Top Level Namespace

Includes:
FileTest

Defined Under Namespace

Classes: Transform, Update

Instance Method Summary collapse

Instance Method Details

#add_files(stage, what_dlls, nuspec, folder = 'lib') ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/build.rb', line 28

def add_files stage, what_dlls, nuspec, folder='lib'
  [['net35', 'net-3.5'], ['net40', 'net-4.0'], ['net45', 'net-4.5']].each{|fw|
    takeFrom = File.join(stage, fw[1], what_dlls)
    Dir.glob(takeFrom).each do |f|
      nuspec.file(f.gsub("/", "\\"), "#{folder}\\#{fw[0]}")
    end
  }
end

#check_devkitObject

devkit version check



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/install.rb', line 95

def check_devkit
	# check if devkit exists
	puts 'Checking devkit version...'
	rubyPath = `where.exe ruby.exe`
	rubyPath['bin\ruby.exe'] = 'devkit'
	rubyPath = rubyPath.sub("\n", '')	#doublequotes required for Line break, gotcha
	if (!File.directory?(rubyPath))
		puts 'devkit not found'
		# if not download, install and setup devkit
		puts 'Downloading devkit...'

		sourcePath = 'cdn.rubyinstaller.org'
		versionedExeFile = $selected_version[:devkit]
		filePath = "/archives/devkits/#{versionedExeFile}?direct"
		return false if !download_file(sourcePath, filePath, versionedExeFile)
		
		puts 'Devkit installation in progress...'
		cmd = "#{versionedExeFile} -y -o\"#{rubyPath}\""	#no space after -o, gotcha
		puts cmd
		return false if !install_file(cmd, versionedExeFile)

		puts 'Setting up devkit...'
		Dir.chdir "#{rubyPath}"
		cmd = 'ruby dk.rb init'
		cmdoutput = `#{cmd}`
		puts cmdoutput
		if !cmdoutput.to_s.include?('Initialization complete!')
			puts 'Error: could not initialize devkit.'
			return false
		end

	    cmd = 'ruby dk.rb review'
	    cmdoutput = `#{cmd}`
		puts cmdoutput
		if !cmdoutput.to_s.include?('DevKit functionality will be injected')
			puts 'Error: devkit review failed'
			return false
		end

	    cmd = 'ruby dk.rb install'
	    cmdoutput = `#{cmd}`
		puts cmdoutput
	    puts 'Restart console since environment variables are now updated'

		return false
	end

	puts 'devkit ok'
	return true
end

#check_doxygenObject

doxygen check



147
148
149
150
# File 'lib/install.rb', line 147

def check_doxygen
	# download doxygen
	return true
end

#check_gemsObject

check and install required gems



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/install.rb', line 153

def check_gems
	puts 'Checking required gems...'
	$selected_version[:gems].each {|key, value|
		if !gem_exists(key, "=#{value}")
			begin
				puts "Installing missing gem: #{key}"
				cmd = "gem install #{key} -v #{value}"
				cmdoutput = `#{cmd}`
				puts cmdoutput
			rescue
				puts 'gem install failed'
				puts $!
				return false	# don't continue if even one gem install fails
			end
		end
	}
	# all gems installed
	return true
end

#check_package_version_dependency(package_uri, package, version = 'IsLatestVersion') ⇒ Object

checks nuget dependency



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/build.rb', line 147

def check_package_version_dependency(package_uri, package, version='IsLatestVersion')
  # retrieve package version info
  response = Net::HTTP.get_response(URI.parse(package_uri.sub('pkg', package))) # get_response takes a URI object
  package_info = response.body
  xml = Nokogiri::XML(package_info)
  xml.xpath("//m:properties/d:#{version}").each { |e|
    if e.text.to_s == 'true'
      version = e.parent.xpath('d:Version').text
    end
  }

  # grab all packages.config files
  config_files = Dir.glob('**/packages.config')

  # for each file match version. Return false is check fails
  config_files.each{ |file|
    doc = Nokogiri::XML(File.read(file))
    node = doc.at_xpath("//*[@id=\"#{package}\"]")
    if (!node.nil?)
      config_version = node.attr('version')
      puts "Package: #{package} Latest Version: #{version} File: #{file} File package version: #{config_version}"
      return false unless config_version.to_s == version
    end
  }

  return true
end

#check_rubyObject

Ruby version check



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/install.rb', line 76

def check_ruby
	puts 'Checking ruby version...'
	# check if expected ruby version exists. If not download and install ruby
	rubyVersion = "#{RUBY_VERSION}"
	localVersion = "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
	expectedVersion1 = '1.9.3-p551'
	expectedVersion2 = '2.0.0-p481'
	if (!rubyVersion.nil? && (localVersion != expectedVersion1 && localVersion != expectedVersion2))
		puts "Uninstall incompatible version of ruby: #{localVersion} and install version: #{expectedVersion1} or #{expectedVersion2}. Then Restart rake. Goto http://rubyinstaller.org/downloads/"
		return false
	end

	$selected_version = $version_map[localVersion]
	puts 'Ruby ok'

	return true
end

#clean_build(msb, solution) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/build.rb', line 94

def clean_build(msb, solution)
  msb.properties :Configuration => 'Release',
    :Platform => 'Any CPU',
    :VisualStudioVersion => '12.0'
  msb.use :net4
  msb.solution = solution
end

#cleantask(props) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/build.rb', line 61

def cleantask(props)

  if props.has_key?(:output) && File.directory?(props[:output])
    FileUtils.rm_rf props[:output]
    waitfor { !exists?(props[:output]) }
  end

  if props.has_key?(:artifacts) && File.directory?(props[:artifacts])
    FileUtils.rm_rf props[:artifacts]
    waitfor { !exists?(props[:artifacts]) }
  end

  if props.has_key?(:output)
    Dir.mkdir props[:output]
  end
  if props.has_key?(:artifacts)
    Dir.mkdir props[:artifacts]
  end
end

#commit_dataObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/build.rb', line 37

def commit_data
  begin
    commit = `git rev-parse --short HEAD`.chomp()[0,6]
    git_date = `git log -1 --date=iso --pretty=format:%ad`
    commit_date = DateTime.parse( git_date ).strftime("%Y-%m-%d %H%M%S")
  rescue Exception => e
    puts e.inspect
    commit = (ENV['BUILD_VCS_NUMBER'] || "000000")[0,6]
    commit_date = Time.new.strftime("%Y-%m-%d %H%M%S")
  end
  [commit, commit_date]
end

#copy_output_files(fromDir, filePattern, outDir) ⇒ Object



3
4
5
6
7
8
# File 'lib/build.rb', line 3

def copy_output_files(fromDir, filePattern, outDir)
    FileUtils.mkdir_p outDir unless exists?(outDir)
    Dir.glob(File.join(fromDir, filePattern)){|file|
        copy(file, outDir) if File.file?(file)
    }
end

#copy_runtime_artifacts(package) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/build.rb', line 175

def copy_runtime_artifacts(package)

  # grab all packages.config files
  config_files = Dir.glob('**/packages.config')
  config_version = ''

  # find package version
  config_files.each{ |file|
    doc = Nokogiri::XML(File.read(file))
    node = doc.at_xpath("//*[@id=\"#{package}\"]")
    if (!node.nil?)
      config_version = node.attr('version').to_s
      break
    end
  }
  puts config_version
  
  # copy artifacts
  source = "#{ENV['RuntimePath']}/#{config_version}"
  dest = File.join(File.expand_path('.'), 'RuntimeService')
  puts source
  puts dest
  copy_output_files source, "*.*", dest
end

#download_file(sourcePath, filePath, localFileLocation) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/install.rb', line 3

def download_file(sourcePath, filePath, localFileLocation)
	Net::HTTP.start(sourcePath) do |http|
	    resp = http.get(filePath)
		f = open(localFileLocation, 'wb')
		begin
			requestPath = "http://#{sourcePath}#{filePath}"
			puts "Downloading #{requestPath}..."
		    http.request_get(requestPath) do |resp|
		        resp.read_body do |segment|
		            f.write(segment)
		        end
		    end
	    rescue
	    	puts $!
	    	return false
		ensure
		    f.close()
		end
	end
	return true
end

#gem_exists(name, version) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/install.rb', line 41

def gem_exists(name, version)
	begin
	  gem name, version
	rescue Gem::LoadError
	  puts "failed to load gem #{name} -v #{version}"
	  Gem.clear_paths
	  return false
	end
	return true
end

#get_commit_hash_and_dateObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/build.rb', line 16

def get_commit_hash_and_date
    begin
        commit = `git log -1 --pretty=format:%H`
        git_date = `git log -1 --date=iso --pretty=format:%ad`
        commit_date = DateTime.parse( git_date ).strftime("%Y-%m-%d %H%M%S")
    rescue
        commit = "git unavailable"
    end

    [commit, commit_date]
end

#install_file(cmd, versionedExeFile) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/install.rb', line 25

def install_file(cmd, versionedExeFile)
	begin
		installerOutput = `#{cmd}`
		puts installerOutput
	rescue
		puts $!
		return false
	ensure
		puts 'Cleaning up...'
		cmd = "#{versionedExeFile}"
		installerOutput = `del #{cmd}`
		puts installerOutput		
	end
	return true
end

#project_outputs(props) ⇒ Object



10
11
12
13
14
# File 'lib/build.rb', line 10

def project_outputs(props)
    props[:projects].map{ |p| "src/#{p}/bin/#{BUILD_CONFIG}/#{p}.dll" }.
        concat( props[:projects].map{ |p| "src/#{p}/bin/#{BUILD_CONFIG}/#{p}.exe" } ).
        find_all{ |path| exists?(path) }
end

#restore_nuget(nuget_exe) ⇒ Object



81
82
83
84
# File 'lib/build.rb', line 81

def restore_nuget(nuget_exe)
    sh 'powershell', '-Command', "& { Invoke-RestMethod https://www.nuget.org/nuget.exe -OutFile '#{nuget_exe}' }"
    sh nuget_exe, 'restore', "src/#{PRODUCT}.sln"
end

#restore_project_pkgs(proj) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/build.rb', line 86

def restore_project_pkgs(proj)
  msbuild :nuget_restore do |msb|
    msb.use :net4
    msb.targets :RestorePackages
    msb.solution = proj
  end
end

#set_framework_version(asm) ⇒ Object



124
125
126
# File 'lib/build.rb', line 124

def set_framework_version(asm)
  set_version asm, $versionMap[:formal_version], $versionMap[:formal_version], $versionMap[:build_version], 'Framework'
end

#set_solution_version(asm) ⇒ Object



128
129
130
# File 'lib/build.rb', line 128

def set_solution_version(asm)
  set_version asm, $versionMap[:platform_version], $versionMap[:platform_version], $versionMap[:platform_build_version], 'Solution'
end

#set_version(asm, version, file_version, assembly_version, output_file) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/build.rb', line 132

def set_version(asm, version, file_version, assembly_version, output_file)
  # Assembly file config
  asm.product_name = PRODUCT
  asm.description = PRODUCT_DESCRIPTION
  asm.version = version
  asm.file_version = file_version
  asm.custom_attributes :AssemblyInformationalVersion => assembly_version,
  :ComVisibleAttribute => false,
  :CLSCompliantAttribute => true
  asm.copyright = COPYRIGHT
  asm.output_file = "src/#{output_file}Version.cs"
  asm.namespaces 'System', 'System.Reflection', 'System.Runtime.InteropServices'
end

#versioningObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/build.rb', line 102

def versioning
  ver = SemVer.find
  revision = (ENV['BUILD_NUMBER'] || ver.patch).to_i
  var = SemVer.new(ver.major, ver.minor, revision, ver.special)

  commitData = commit_data()

  # extensible number w/ git hash
  ENV['BUILD_VERSION'] = $versionMap[:build_version] = ver.format('%M.%m.%p%s') + ".#{commitData[0]}"
  
  # nuget (not full semver 2.0.0-rc.1 support) see http://nuget.codeplex.com/workitem/1796
  ENV['NUGET_VERSION'] = $versionMap[:nuget_version] = ver.format('%M.%m.%p%s')

  ENV['PLATFORM_VERSION'] = $versionMap[:platform_version] = Time.new.strftime('%y.%-m.%-d') + ".#{(ENV['BUILD_NUMBER'] || '0')}"

  ENV['PLATFORM_BUILD_VERSION'] = $versionMap[:platform_build_version] = Time.new.strftime('%y.%-m.%-d') + ".#{commitData[0]}"
  
  # purely M.m.p format
  ENV['FORMAL_VERSION'] = $versionMap[:formal_version] = "#{ SemVer.new(ver.major, ver.minor, revision).format '%M.%m.%p'}"
  puts "##teamcity[buildNumber '#{$versionMap[:platform_version]}']" # tell teamcity our decision
end

#waitfor(&block) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/build.rb', line 50

def waitfor(&block)
    checks = 0

    until block.call || checks >10
        sleep 0.5
        checks += 1
    end

    raise 'Waitfor timeout expired. Make sure that you aren\'t running something from the build output folders, or that you have browsed to it through Explorer.' if checks > 10
end