fgmeta/hudson_mac_package_release.rb

157 lines
4.4 KiB
Ruby
Raw Normal View History

#!/usr/bin/ruby
require 'ERB'
require 'fileutils' #I know, no underscore is not ruby-like
include FileUtils
$osgLibs = ['osgFX', 'osgParticle', 'osg', 'osgGA', 'osgText', 'osgUtil', 'osgSim', 'osgViewer', 'osgDB']
$osgPlugins = ['ac', 'osg', 'freetype', 'imageio', 'rgb', 'txf', 'mdl', '3ds']
def runOsgVersion(option)
env = "export DYLD_LIBRARY_PATH=#{Dir.pwd}/dist/lib"
bin = Dir.pwd + "/dist/bin/osgversion"
return `#{env}; #{bin} --#{option}`.chomp
end
osgVersion = runOsgVersion('version-number')
$osgSoVersion=runOsgVersion('so-number')
$openThreadsSoVersion=runOsgVersion('openthreads-soversion-number')
$codeSignIdentity = ENV['FG_CODESIGN_IDENTITY']
puts "Code signing identity is #{$codeSignIdentity}"
puts "osgVersion=#{osgVersion}, so-number=#{$osgSoVersion}"
def fix_install_names(object)
#puts "fixing install names for #{object}"
2015-02-24 19:41:58 +08:00
$osgLibs.each do |l|
oldName = "lib#{l}.#{$osgSoVersion}.dylib"
newName = "@executable_path/../Frameworks/#{oldName}"
`install_name_tool -change #{oldName} #{newName} #{object}`
end
2015-02-24 19:41:58 +08:00
oldName = "libOpenThreads.#{$openThreadsSoVersion}.dylib"
newName= "@executable_path/../Frameworks/#{oldName}"
`install_name_tool -change #{oldName} #{newName} #{object}`
end
$prefixDir=Dir.pwd + "/dist"
dmgDir=Dir.pwd + "/image"
srcDir=Dir.pwd + "/flightgear"
puts "Erasing previous image dir"
`rm -rf #{dmgDir}`
2015-02-24 19:41:58 +08:00
bundle=dmgDir + "/FlightGear.app"
# run macdeployt before we rename the bundle, otherwise it
# can't find the bundle executable
puts "Running macdeployqt on the bundle to copy Qt libraries"
`macdeployqt #{$prefixDir}/fgfs.app`
puts "Moving & renaming app bundle"
`mkdir -p #{dmgDir}`
`mv #{$prefixDir}/fgfs.app #{bundle}`
bundle=dmgDir + "/FlightGear.app"
contents=bundle + "/Contents"
macosDir=contents + "/MacOS"
$frameworksDir=contents +"/Frameworks"
resourcesDir=contents+"/Resources"
2015-02-24 19:43:51 +08:00
osgPluginsDir=contents+"/PlugIns/osgPlugins"
# for writing copyright year to Info.plist
t = Time.new
fgCurrentYear = t.year
fgVersion = File.read("#{srcDir}/version").strip
volName="\"FlightGear #{fgVersion}\""
2015-02-24 19:47:15 +08:00
dmgPath = Dir.pwd + "/output/FlightGear-#{fgVersion}-nightly.dmg"
dmgFullPath = Dir.pwd + "/output/FlightGear-#{fgVersion}-nightly-full.dmg"
puts "Creating directory structure"
`mkdir -p #{macosDir}`
`mkdir -p #{$frameworksDir}`
`mkdir -p #{resourcesDir}`
`mkdir -p #{osgPluginsDir}`
2015-02-24 19:41:58 +08:00
# fix install names on the primary executable
fix_install_names("#{macosDir}/fgfs")
puts "Copying auxilliary binaries"
bins = ['fgjs', 'fgcom']
bins.each do |b|
if !File.exist?("#{$prefixDir}/bin/#{b}")
next
end
2015-02-24 19:41:58 +08:00
outPath = "#{macosDir}/#{b}"
`cp #{$prefixDir}/bin/#{b} #{outPath}`
fix_install_names(outPath)
end
puts "copying libraries"
$osgLibs.each do |l|
libFile = "lib#{l}.#{$osgSoVersion}.dylib"
`cp #{$prefixDir}/lib/#{libFile} #{$frameworksDir}`
fix_install_names("#{$frameworksDir}/#{libFile}")
end
# and not forgetting OpenThreads
libFile = "libOpenThreads.#{$openThreadsSoVersion}.dylib"
`cp #{$prefixDir}/lib/#{libFile} #{$frameworksDir}`
$osgPlugins.each do |p|
2015-02-24 19:43:51 +08:00
pluginFile = "osgdb_#{p}.dylib"
`cp #{$prefixDir}/lib/osgPlugins/#{pluginFile} #{osgPluginsDir}`
fix_install_names("#{osgPluginsDir}/#{pluginFile}")
end
2012-08-08 23:27:04 +08:00
if File.exist?("#{$prefixDir}/bin/fgcom-data")
puts "Copying FGCom data files"
`ditto #{$prefixDir}/bin/fgcom-data #{resourcesDir}/fgcom-data`
end
# Info.plist
template = File.read("Info.plist.in")
output = ERB.new(template).result(binding)
File.open("#{contents}/Info.plist", 'w') { |f|
f.write(output)
}
`cp #{srcDir}/package/mac/FlightGear.icns #{resourcesDir}/FlightGear.icns`
`cp #{srcDir}/COPYING #{dmgDir}`
# move documentation to a public place
2013-02-01 22:45:30 +08:00
`mv fgdata/Docs/FGShortRef.pdf "#{dmgDir}/Quick Reference.pdf"`
`mv fgdata/Docs/getstart.pdf "#{dmgDir}/Getting Started.pdf"`
# create the 'lite' DMG without the base files
2015-02-24 19:43:51 +08:00
# code sign the entire bundle once complete - v2 code-signing
puts "Signing #{bundle}"
`codesign --deep -s "#{$codeSignIdentity}" #{bundle}`
puts "Creating DMG"
createArgs = "-format UDBZ -imagekey bzip2-level=9 -quiet -volname #{volName}"
`rm #{dmgPath}`
`hdiutil create -srcfolder #{dmgDir} #{createArgs} #{dmgPath}`
puts "Creatign full image with data"
puts "Copying base package files into the image"
`rsync -a fgdata/ #{resourcesDir}/data`
# re-sign the entire bundle
puts "Re-signing full #{bundle}"
`codesign --force --deep -s "#{$codeSignIdentity}" #{bundle}`
`rm #{dmgFullPath}`
`hdiutil create -srcfolder #{dmgDir} #{createArgs} #{dmgFullPath}`