rakelib/support.rb
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 24 Oct 2016 09:48:37 +0100
changeset 60 57c963e85a00
parent 29 cd2e05aff563
child 88 112075e99cef
permissions -rw-r--r--
Cleanup: Renamed `vcs.rb` & `Rake::StX::VCS` to `scm.rb` and `Rake::StX::SCM` to make naming a little more consistent within Smalltalk/X (which uses SCM). Also SCM seems to be commonly used abbrev.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
     1
require 'net/http'
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
     2
require 'net/https'
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
     3
require 'json'
6
abb35e8d97a7 Add `bin` directory to PATH so build scripts may use scripts located there
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2
diff changeset
     4
require 'rakelib/extensions.rb'
abb35e8d97a7 Add `bin` directory to PATH so build scripts may use scripts located there
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2
diff changeset
     5
require 'rakelib/rbspec.rb'
60
57c963e85a00 Cleanup: Renamed `vcs.rb` & `Rake::StX::VCS` to `scm.rb` and `Rake::StX::SCM`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
     6
require 'rakelib/scm.rb'
6
abb35e8d97a7 Add `bin` directory to PATH so build scripts may use scripts located there
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2
diff changeset
     7
2
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
     8
# Following hack is required to allow passing variable
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
     9
# values in `make` style, i.e., to allow for
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
    10
#
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
    11
#  rake PROJECT=stx:jv-branch compile
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
    12
#
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
    13
ARGV.each do | arg |
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
    14
  name_and_value = /^([A-Za-z_]+)\w*=(.*)/.match(arg)
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
    15
  if name_and_value
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
    16
     self.class.const_set(name_and_value[1], name_and_value[2])  
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
    17
  end
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
    18
end
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
    19
23
7dad21b22558 Added support to build under MSYS2 environment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    20
# Update PATH for build so build scripts may access  scripts and programs 
7dad21b22558 Added support to build under MSYS2 environment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    21
# in `bin` directory. This is required especially on Windows as Windows do 
7dad21b22558 Added support to build under MSYS2 environment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    22
# not ship with some basic tools (e.g. zip) by default. As a courtesy to the
7dad21b22558 Added support to build under MSYS2 environment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    23
# user, provide our own. 
7dad21b22558 Added support to build under MSYS2 environment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    24
# NOTE that this MUST be the first entry in the PATH to be able to override
7dad21b22558 Added support to build under MSYS2 environment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    25
# MINGW/MSYS make.exe with Borland's ancient make.exe (sigh, St/X still deals
7dad21b22558 Added support to build under MSYS2 environment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    26
# with dinosaurs)
7dad21b22558 Added support to build under MSYS2 environment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    27
ENV['PATH'] = "#{File.expand_path('bin')};#{File::PATH_SEPARATOR}#{ENV['PATH']}"
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    28
10
cb3e0e3ca28f Fixed repository specifications to allow anonymous checkout.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    29
# Return true if running under Jenkins, false otherwise
cb3e0e3ca28f Fixed repository specifications to allow anonymous checkout.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    30
def jenkins?
cb3e0e3ca28f Fixed repository specifications to allow anonymous checkout.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    31
  return (ENV.has_key? 'WORKSPACE'   and 
cb3e0e3ca28f Fixed repository specifications to allow anonymous checkout.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    32
          ENV.has_key? 'JOB_NAME'    and 
11
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    33
          ENV.has_key? 'BUILD_ID')
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    34
end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    35
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    36
# Returns true if and only if this is machine of one of the core developers
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    37
# (currently only JV). 
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    38
# Indeed this is a feeble check and can be easily bypassed by chaning the
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    39
# code or by setting a proper environment variable. But this should not hurt 
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    40
# much as in that case, unauthorized person wouldn't be able to connect to 
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    41
# stc and librun repository so the build will fail. 
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    42
def core_developer?
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    43
  # JV's box: jv@..., vranyj1@...
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    44
  if (ENV['USER'] == 'jv') or (ENV['USER'] == 'vranyj1')
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    45
    return true
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    46
  end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    47
  if (ENV['USERNAME'] == 'jv') or (ENV['USERNAME'] == 'vranyj1')
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    48
    return true
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    49
  end 
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    50
  return false
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    51
end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    52
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    53
# A super simple API for Jenkins used to download pre-built stc and librun.
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    54
module Jenkins
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    55
  # Return an a Jenkins build with pre-built stc and librun. 
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    56
  # Used to download pre-build stc and librun
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    57
  def self.smalltalkx_jv_branch_build()
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    58
    plat = nil
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    59
    if win32? then        
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    60
        plat = 'Windows'
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    61
    elsif linux?        
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    62
      plat = 'Linux'
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    63
    else        
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    64
      error_unsupported_platform()
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    65
    end
29
cd2e05aff563 Switch URL of prebuilt stc and librun archives to 'production' job 'stx_jv'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 23
diff changeset
    66
    return Jenkins::Build.new(%Q{https://swing.fit.cvut.cz/jenkins/job/stx_jv/ARCH=#{ARCH},PLATFORM=#{plat}N/lastSuccessfulBuild})
11
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    67
  end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    68
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    69
  class Artifact
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    70
    attr_reader :name
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    71
    attr_reader :uri
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    72
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    73
    def initialize(name, uri)
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    74
      @name = name
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    75
      @uri = uri
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    76
    end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    77
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    78
    def download_to(destination)       
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    79
      if not File.exist? destination
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    80
        if not File.directory? File.dirname(destination)
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    81
          raise Exception.new("Invalid destination for download: #{destination}")
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    82
        end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    83
      else
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    84
        if not File.directory? destination
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    85
          raise Exception.new("Invalid destination for download: #{destination}")
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    86
        else
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    87
          destination = File.join(destination, @name)
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    88
        end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    89
      end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    90
      Jenkins::get(@uri) do | response |
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    91
        File.open(destination, "wb") do | file |
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    92
          response.read_body do | part |
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    93
            file.write part
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    94
          end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    95
        end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    96
      end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    97
    end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    98
  end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    99
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   100
  class Build
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   101
    attr_reader :data
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   102
    attr_reader :uri
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   103
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   104
    def initialize(uri)
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   105
      @uri = uri
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   106
      @data = JSON.parse(Jenkins::get(URI(uri.to_s + '/api/json')))
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   107
    end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   108
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   109
    # Return a list of artifacts (as instances of `Jenkins::Artifact`) 
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   110
    # associated with this build. 
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   111
    def artifacts()
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   112
      if not @artifacts then
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   113
        @artifacts = @data["artifacts"].collect do | each | 
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   114
          Artifact.new(each['fileName'], URI(@uri.to_s + '/artifact/' + each['relativePath']))
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   115
        end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   116
      end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   117
      return @artifacts      
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   118
    end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   119
  end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   120
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   121
  # A private method to GET data over HTTP(S)  
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   122
  def self.get(uri, &block) 
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   123
    # http parameters       
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   124
    http_host = Net::HTTP.new(uri.host, uri.port)
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   125
    http_host.use_ssl = (uri.scheme == 'https') # simple true enough
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   126
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   127
    if false # host verification not used (yet)
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   128
      http_host.verify_mode = OpenSSL::SSL::VERIFY_PEER
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   129
      http_host.cert_store = OpenSSL::X509::Store.new
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   130
      http_host.cert_store.set_default_paths
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   131
      http_host.cert_store.add_file('cacert.pem') # file downloaded from curl.haxx.se/ca/cacert.pem
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   132
    else
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   133
      http_host.verify_mode = OpenSSL::SSL::VERIFY_NONE
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   134
    end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   135
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   136
    # actual download
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   137
    body = nil
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   138
    http_host.start do | http |        
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   139
      http.request_get(uri) do | response |
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   140
        if block then
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   141
          yield response
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   142
        else
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   143
          body = response.body
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   144
        end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   145
      end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   146
    end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   147
    return body
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   148
  end
10
cb3e0e3ca28f Fixed repository specifications to allow anonymous checkout.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
   149
end