mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-04-24 04:46:05 +08:00
better build system output
This commit is contained in:
@@ -3,6 +3,8 @@ require 'motion/project/config'
|
||||
require 'motion/project/builder'
|
||||
require 'motion/project/vendor'
|
||||
|
||||
Rake.verbose(false) unless Rake.verbose == true
|
||||
|
||||
desc "Build the project, then run the simulator"
|
||||
task :default => :simulator
|
||||
|
||||
@@ -51,6 +53,7 @@ task :simulator => ['build:simulator'] do
|
||||
# Launch the simulator.
|
||||
sim = File.join(App.config.bindir, 'sim')
|
||||
debug = (ENV['debug'] || '0') == '1' ? 1 : 0
|
||||
App.info 'Simulate', app
|
||||
sh "#{sim} #{debug} #{family_int} #{sdk_version} \"#{app}\""
|
||||
end
|
||||
|
||||
@@ -59,6 +62,7 @@ task :archive => ['build:ios'] do
|
||||
app_bundle = App.config.app_bundle('iPhoneOS')
|
||||
archive = App.config.archive
|
||||
if !File.exist?(archive) or File.mtime(app_bundle) > File.mtime(archive)
|
||||
App.info 'Create', archive
|
||||
tmp = "/tmp/ipa_root"
|
||||
sh "/bin/rm -rf #{tmp}"
|
||||
sh "/bin/mkdir -p #{tmp}/Payload"
|
||||
@@ -80,6 +84,7 @@ end
|
||||
|
||||
desc "Deploy on the device"
|
||||
task :deploy => :archive do
|
||||
App.info 'Deploy', App.config.archive
|
||||
deploy = File.join(App.config.bindir, 'deploy')
|
||||
flags = Rake.application.options.trace ? '-d' : ''
|
||||
sh "#{deploy} #{flags} \"#{App.config.archive}\""
|
||||
@@ -87,6 +92,7 @@ end
|
||||
|
||||
desc "Clear build objects"
|
||||
task :clean do
|
||||
App.info 'Delete', App.config.build_dir
|
||||
rm_rf(App.config.build_dir)
|
||||
end
|
||||
|
||||
|
||||
@@ -21,6 +21,16 @@ module Motion; module Project
|
||||
def codesign(platform)
|
||||
builder.codesign(config, platform)
|
||||
end
|
||||
|
||||
def warn(msg)
|
||||
$stderr.puts "WARNING!".rjust(10) + ' ' + msg
|
||||
end
|
||||
|
||||
def info(what, msg)
|
||||
unless Rake.verbose
|
||||
$stderr.puts what.rjust(10) + ' ' + msg
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end; end
|
||||
|
||||
@@ -4,7 +4,6 @@ module Motion; module Project;
|
||||
|
||||
def build(config, platform)
|
||||
datadir = config.datadir
|
||||
libstatic = File.join(datadir, 'libmacruby-static.a')
|
||||
archs = Dir.glob(File.join(datadir, platform, '*.bc')).map do |path|
|
||||
path.scan(/kernel-(.+).bc$/)[0][0]
|
||||
end
|
||||
@@ -57,6 +56,7 @@ module Motion; module Project;
|
||||
init_func = should_rebuild ? "MREP_#{`/usr/bin/uuidgen`.strip.gsub('-', '')}" : `/usr/bin/nm #{obj}`.scan(/T\s+_(MREP_.*)/)[0][0]
|
||||
|
||||
if should_rebuild
|
||||
App.info 'Compile', path
|
||||
FileUtils.mkdir_p(File.dirname(obj))
|
||||
arch_objs = []
|
||||
archs.each do |arch|
|
||||
@@ -193,26 +193,42 @@ EOS
|
||||
|
||||
# Prepare bundle.
|
||||
bundle_path = config.app_bundle(platform)
|
||||
FileUtils.mkdir_p(bundle_path)
|
||||
unless File.exist?(bundle_path)
|
||||
App.info 'Create', bundle_path
|
||||
FileUtils.mkdir_p(bundle_path)
|
||||
end
|
||||
|
||||
# Link executable.
|
||||
main_exec = File.join(bundle_path, config.name)
|
||||
objs_list = objs.map { |path, _| path }.unshift(main_o).map { |x| "\"#{x}\"" }.join(' ')
|
||||
frameworks = config.frameworks.map { |x| "-framework #{x}" }.join(' ')
|
||||
framework_stubs_objs = []
|
||||
config.frameworks.each do |framework|
|
||||
stubs_obj = File.join(datadir, platform, "#{framework}_stubs.o")
|
||||
framework_stubs_objs << "\"#{stubs_obj}\"" if File.exist?(stubs_obj)
|
||||
if !File.exist?(main_exec) \
|
||||
or File.mtime(config.project_file) > File.mtime(main_exec) \
|
||||
or objs.any? { |path, _| File.mtime(path) > File.mtime(main_exec) } \
|
||||
or File.mtime(File.join(datadir, platform, 'libmacruby-static.a')) > File.mtime(main_exec)
|
||||
App.info 'Link', main_exec
|
||||
objs_list = objs.map { |path, _| path }.unshift(main_o).map { |x| "\"#{x}\"" }.join(' ')
|
||||
frameworks = config.frameworks.map { |x| "-framework #{x}" }.join(' ')
|
||||
framework_stubs_objs = []
|
||||
config.frameworks.each do |framework|
|
||||
stubs_obj = File.join(datadir, platform, "#{framework}_stubs.o")
|
||||
framework_stubs_objs << "\"#{stubs_obj}\"" if File.exist?(stubs_obj)
|
||||
end
|
||||
sh "#{cxx} -o \"#{main_exec}\" #{objs_list} #{arch_flags} #{framework_stubs_objs.join(' ')} -isysroot \"#{sdk}\" -miphoneos-version-min=#{config.sdk_version} -L#{File.join(datadir, platform)} -lmacruby-static -lobjc -licucore #{frameworks} #{config.libs.join(' ')} #{vendor_libs.map { |x| '-force_load ' + x }.join(' ')}"
|
||||
end
|
||||
sh "#{cxx} -o \"#{main_exec}\" #{objs_list} #{arch_flags} #{framework_stubs_objs.join(' ')} -isysroot \"#{sdk}\" -miphoneos-version-min=#{config.sdk_version} -L#{File.join(datadir, platform)} -lmacruby-static -lobjc -licucore #{frameworks} #{config.libs.join(' ')} #{vendor_libs.map { |x| '-force_load ' + x }.join(' ')}"
|
||||
|
||||
# Create bundle/Info.plist.
|
||||
bundle_info_plist = File.join(bundle_path, 'Info.plist')
|
||||
File.open(bundle_info_plist, 'w') { |io| io.write(config.info_plist_data) }
|
||||
sh "/usr/bin/plutil -convert binary1 \"#{bundle_info_plist}\""
|
||||
if !File.exist?(bundle_info_plist) or File.mtime(config.project_file) > File.mtime(bundle_info_plist)
|
||||
App.info 'Create', bundle_info_plist
|
||||
File.open(bundle_info_plist, 'w') { |io| io.write(config.info_plist_data) }
|
||||
sh "/usr/bin/plutil -convert binary1 \"#{bundle_info_plist}\""
|
||||
end
|
||||
|
||||
# Create bundle/PkgInfo.
|
||||
File.open(File.join(bundle_path, 'PkgInfo'), 'w') { |io| io.write(config.pkginfo_data) }
|
||||
bundle_pkginfo = File.join(bundle_path, 'PkgInfo')
|
||||
if !File.exist?(bundle_pkginfo) or File.mtime(config.project_file) > File.mtime(bundle_pkginfo)
|
||||
App.info 'Create', bundle_pkginfo
|
||||
File.open(bundle_pkginfo, 'w') { |io| io.write(config.pkginfo_data) }
|
||||
end
|
||||
|
||||
# Copy resources, handle subdirectories.
|
||||
reserved_app_bundle_files = [
|
||||
@@ -234,6 +250,7 @@ EOS
|
||||
dest_path = File.join(bundle_path, res)
|
||||
if !File.exist?(dest_path) or File.mtime(res_path) > File.mtime(dest_path)
|
||||
FileUtils.mkdir_p(File.dirname(dest_path))
|
||||
App.info 'Copy', res_path
|
||||
FileUtils.cp(res_path, File.dirname(dest_path))
|
||||
end
|
||||
end
|
||||
@@ -257,8 +274,10 @@ EOS
|
||||
|
||||
# Create bundle/ResourceRules.plist.
|
||||
resource_rules_plist = File.join(bundle_path, 'ResourceRules.plist')
|
||||
File.open(resource_rules_plist, 'w') do |io|
|
||||
io.write(<<-PLIST)
|
||||
unless File.exist?(resource_rules_plist)
|
||||
App.info 'Create', resource_rules_plist
|
||||
File.open(resource_rules_plist, 'w') do |io|
|
||||
io.write(<<-PLIST)
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
@@ -285,20 +304,25 @@ EOS
|
||||
</dict>
|
||||
</plist>
|
||||
PLIST
|
||||
end
|
||||
end
|
||||
|
||||
# Copy the provisioning profile.
|
||||
File.open(File.join(bundle_path, "embedded.mobileprovision"), 'w') do |io|
|
||||
io.write(File.read(config.provisioning_profile))
|
||||
bundle_provision = File.join(bundle_path, "embedded.mobileprovision")
|
||||
if !File.exist?(bundle_provision) or File.mtime(config.provisioning_profile) > File.mtime(bundle_provision)
|
||||
App.info 'Create', bundle_provision
|
||||
FileUtils.cp config.provisioning_profile, bundle_provision
|
||||
end
|
||||
|
||||
# Create the entitlements file.
|
||||
entitlements = File.join(config.build_dir, platform, "Entitlements.plist")
|
||||
File.open(entitlements, 'w') { |io| io.write(config.entitlements_data) }
|
||||
|
||||
# Do the codesigning.
|
||||
codesign_allocate = File.join(config.platform_dir(platform), 'Developer/usr/bin/codesign_allocate')
|
||||
sh "CODESIGN_ALLOCATE=\"#{codesign_allocate}\" /usr/bin/codesign -f -s \"#{config.codesign_certificate}\" --resource-rules=\"#{resource_rules_plist}\" --entitlements #{entitlements} \"#{bundle_path}\""
|
||||
# Codesign.
|
||||
codesign_cmd = "CODESIGN_ALLOCATE=\"#{File.join(config.platform_dir(platform), 'Developer/usr/bin/codesign_allocate')}\" /usr/bin/codesign"
|
||||
if File.mtime(config.project_file) > File.mtime(bundle_path) \
|
||||
or !system("#{codesign_cmd} --verify \"#{bundle_path}\" >& /dev/null")
|
||||
App.info 'Codesign', bundle_path
|
||||
entitlements = File.join(config.build_dir, platform, "Entitlements.plist")
|
||||
File.open(entitlements, 'w') { |io| io.write(config.entitlements_data) }
|
||||
sh "#{codesign_cmd} -f -s \"#{config.codesign_certificate}\" --resource-rules=\"#{resource_rules_plist}\" --entitlements #{entitlements} \"#{bundle_path}\""
|
||||
end
|
||||
end
|
||||
end
|
||||
end; end
|
||||
|
||||
@@ -86,7 +86,7 @@ module Motion; module Project
|
||||
require 'digest/sha1'
|
||||
hash = Digest::SHA1.hexdigest(File.expand_path(project_dir))
|
||||
tmp = File.join(ENV['TMPDIR'], hash)
|
||||
$stderr.puts "Cannot create build_dir `#{@build_dir}'. Check the permissions. Using temporary build directory instead: `#{tmp}'"
|
||||
App.warn "Cannot create build_dir `#{@build_dir}'. Check the permissions. Using a temporary build directory instead: `#{tmp}'"
|
||||
@build_dir = tmp
|
||||
tried = true
|
||||
retry
|
||||
@@ -254,7 +254,7 @@ module Motion; module Project
|
||||
$stderr.puts "Can't find an iPhone Developer certificate in the keychain"
|
||||
exit 1
|
||||
elsif certs.size > 1
|
||||
$stderr.puts "Found #{certs.size} iPhone Developer certificates, will use the first one: `#{certs[0]}'"
|
||||
App.warn "Found #{certs.size} iPhone Developer certificates in the keychain. Set the `codesign_certificate' project setting. Will use the first certificate: `#{certs[0]}'"
|
||||
end
|
||||
certs[0][1..-2] # trim trailing `"` characters
|
||||
end
|
||||
@@ -267,7 +267,7 @@ module Motion; module Project
|
||||
$stderr.puts "Can't find a provisioning profile"
|
||||
exit 1
|
||||
elsif paths.size > 1
|
||||
$stderr.puts "Found #{paths.size} provisioning profiles, will use the first one: `#{paths[0]}'"
|
||||
App.warn "Found #{paths.size} provisioning profiles. Set the `provisioning_profile' project setting. Will use the first one: `#{paths[0]}'"
|
||||
end
|
||||
paths[0]
|
||||
end
|
||||
@@ -281,7 +281,7 @@ module Motion; module Project
|
||||
$stderr.puts "Can't find an application seed ID in the provisioning profile"
|
||||
exit 1
|
||||
elsif seed_ids.size > 1
|
||||
$stderr.puts "Found #{seed_ids.size} seed IDs in the provisioning profile, will use the last one: `#{seed_ids.last}'"
|
||||
App.warn "Found #{seed_ids.size} seed IDs in the provisioning profile. Set the `seed_id' project setting. Will use the last one: `#{seed_ids.last}'"
|
||||
end
|
||||
seed_ids.last
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user