bin/nixenvironment in nixenvironment-0.0.23 vs bin/nixenvironment in nixenvironment-0.0.24

- old
+ new

@@ -62,54 +62,32 @@ command :build do |c| c.syntax = 'nixenvironment build [options]' c.description = 'Build project for selected configuration and make signed/resigned ipa' c.option '--config NAME', String, 'Select configuration' c.option '--ipa TYPE', String, 'Select sign (ipa, resigned_ipa_for_device, resigned_ipa_for_adhoc_distribution or resigned_ipa_for_appstore)' - c.option '--ci_build VALUE', String, 'Define NIXENV_CI_BUILD environment variable (yes, true, 1 or on to enable)' + c.option '--ci_build', 'Define NIXENV_CI_BUILD environment variable' c.option '--unity TARGET PLATFORM', String, 'Select target platform to build (ios or android)' c.action do |args, options| - options.default :config => 'Debug', :ipa => 'ipa', :ci_build => 'yes' + options.default :config => 'Debug', :ipa => 'ipa' - root_working_directory = nil - need_chdir_to_root_working_directory = false - - unity = options.unity - if unity and unity.length > 0 - case unity - when 'ios' - ios_project_path = File.join(Dir.pwd, 'Builds/iOS') - - unity_success = system("unity -executeMethod NIXBuilder.MakeiOSBuild -batchmode -quit -customArgs:path='#{ios_project_path}'") - abort('Build unity error!') unless unity_success - - root_working_directory = Dir.pwd - need_chdir_to_root_working_directory = true - - Dir.chdir(ios_project_path) - - $project_to_build = 'Unity-iPhone.xcodeproj' - $project_target_to_build = 'Unity-iPhone' - $infoplist_path = 'Info.plist' - when 'android' - #TODO: implement me! - else - abort("Error: Unknown unity target platform '#{unity}'!") - end + if options.unity and options.unity.length > 0 + need_to_build_ios, root_working_dir, need_chdir_to_root_working_dir = unity_build(options.unity) + return unless need_to_build_ios end begin read_config(options) enable_ci_build(options.ci_build) build_settings = setup(options.config) prebuild(build_settings, options.config) build(build_settings, options.config, options.ipa) restore_info_plist rescue - raise # re-rise exception but chdir to root_working_directory in ensure block first if needed + raise # re-rise exception but chdir to root_working_dir in ensure block first if needed ensure - if need_chdir_to_root_working_directory and root_working_directory - Dir.chdir(root_working_directory) + if need_chdir_to_root_working_dir and root_working_dir + Dir.chdir(root_working_dir) end end end end @@ -174,12 +152,13 @@ end command :clean_working_copy do |c| c.syntax = 'nixenvironment clean_working_copy' c.description = 'Make working copy clean' + c.option '--all', 'Remove ignored files too' c.action do |args, options| - clean_working_copy + clean_working_copy(options.all) end end def update(ninbas) root_working_directory = Dir.pwd @@ -273,11 +252,11 @@ p("#{key} |NOT specified| directly. Used from Config: #{@config[key]}") end end def enable_ci_build(ci_build) - if ci_build == 'yes' or ci_build == 'true' or ci_build == '1' or ci_build == 'on' + if ci_build ENV['NIXENV_CI_BUILD'] = '1' p('CI_BUILD enabled.') else ENV['NIXENV_CI_BUILD'] = nil p('CI_BUILD disabled.') @@ -476,10 +455,59 @@ restore_info_plist abort("#{make} error!") end end +def unity_build(unity) + root_working_dir = nil + need_chdir_to_root_working_dir = false + need_to_build_ios = false + + save_revision = File.join(BUILD_SCRIPTS_PATH, 'SaveRevision.sh') + system("#{save_revision}") + + abort unless working_copy_is_clean? + + unity_build_scripts_dir = File.join(BUILD_SCRIPTS_PATH, 'UnityBuildAutomationScripts') + unity_editor_dir = File.join(Dir.pwd, 'Assets/Editor') + + if File.directory?(unity_editor_dir) + FileUtils.cp_r(unity_build_scripts_dir, unity_editor_dir) + else + abort("Copy UnityBuildAutomationScripts error! #{unity_editor_dir} doesn't exist!") + end + + case unity + when 'ios' + need_to_build_ios = true + + ios_project_path = File.join(Dir.pwd, 'Builds/iOS') + + p('Generating IOS project from UNITY project ...') + unity_success = system("unity -executeMethod NIXBuilder.MakeiOSBuild -batchmode -quit -customArgs:path='#{ios_project_path}'") + abort('Build unity error!') unless unity_success + p('IOS project was generated.') + + root_working_dir = Dir.pwd + need_chdir_to_root_working_dir = true + + clean_working_copy(false) + + Dir.chdir(ios_project_path) + + $project_to_build = 'Unity-iPhone.xcodeproj' + $project_target_to_build = 'Unity-iPhone' + $infoplist_path = 'Info.plist' + when 'android' + #TODO: implement me! + else + abort("Error: Unknown unity target platform '#{unity}'!") + end + + return need_to_build_ios, root_working_dir, need_chdir_to_root_working_dir +end + def backup_info_plist p('Backuping Info.plist ...') @info_plist_backup_name = @config['INFOPLIST_PATH'] + '.backup' FileUtils.cp(@config['INFOPLIST_PATH'], @info_plist_backup_name) @@ -590,10 +618,11 @@ ENV['SCM_PASSWORD']=%x[ $(shell echo $$(xpath ../subversion.credentials \(//password\)[1]/text\(\) 2>/dev/null && echo) | openssl base64 -d) ] tag end -def clean_working_copy +def clean_working_copy(all) + clean_all = all ? 'all' : nil clean_working_copy = File.join(BUILD_SCRIPTS_PATH, 'CleanWorkingCopy.sh') - clean_success = system("#{clean_working_copy}") + clean_success = system("#{clean_working_copy} #{clean_all}") abort('Clean working copy error!') unless clean_success end