#!/usr/bin/env ruby require 'pod_builder/version' show_version = ARGV.include?("version") && ARGV.count == 1 if show_version puts PodBuilder::VERSION exit(0) end if ENV['DEBUGGING'] puts "Running in debug, injecting $LOAD_PATH" libdir = File.expand_path("#{File.dirname(__FILE__)}/../lib") $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir) end require 'optparse' require 'pod_builder/core' require 'pod_builder/command' OPTIONS = {} def parse_commandline() subcommands = { "none" => { :opts => OptionParser.new do |opts| opts.banner = " Usage: $ pod_builder COMMAND [OPTIONS] Prebuild CocoaPods pods Command: + init Initialize prebuild folders + deintegrate Deintegrate prebuild folders + build Build a specific pod declared in the PodBuilder-Podfile + build_all Build all pods declared in the PodBuilder-Podfile + update Rebuild frameworks that are outdated + restore_all Rebuild all pods declared in the Restore-Podfile + install_sources Install sources of pods to debug into prebuilt frameworks + update_lldbinit Generate an lldbinit file with setting target.source-map to debug prebuilt frameworks + clear_lldbinit Clear an lldbinit file from PodBuilder's customizations + switch Switch between prebuilt/development/standard pod in the Application-Podfile + clean Remove prebuild frameworks, dSYMs and source files added by `install_sources` command that are no longer in the PodBuilder-Podfile + sync_podfile Update your Application-Podfile with all pods declared in the PodBuilder-Podfile + info Print json-formatted informations about prebuilt frameworks Options: " opts.on("-v", "--version", "Show the version of the tool") do |o| OPTIONS[:version] = o end end, :call => [ PodBuilder::Command::None ] }, "build" => { :opts => OptionParser.new do |opts| opts.banner = " Usage: $ pod_builder build [OPTIONS] Prebuild the specified CocoaPods pods. Options: " opts.on("-u", "--skip-repo-update", "Skip CocoaPods repo update") do |o| OPTIONS[:update_repos] = false end opts.on("-w", "--allow-warnings", "Allow warnings") do |o| OPTIONS[:allow_warnings] = o end opts.on("-a", "--auto-resolve-deps", "Resolve pod dependencies automatically") do |o| OPTIONS[:auto_resolve_dependencies] = o end opts.on("-d", "--debug", "Don't clean build folder") do |o| OPTIONS[:debug] = o end end, :call => [ PodBuilder::Command::Build ] }, "build_all" => { :opts => OptionParser.new do |opts| opts.banner = " Usage: $ pod_builder build_all [OPTIONS] Prebuild all pods specified in the PodBuilder-Podfile. Options: " opts.on("-u", "--skip-repo-update", "Skip CocoaPods repo update") do |o| OPTIONS[:update_repos] = false end opts.on("-w", "--allow-warnings", "Allow warnings") do |o| OPTIONS[:allow_warnings] = o end opts.on("-d", "--debug", "Don't clean build folder") do |o| OPTIONS[:debug] = o end end, :call => [ PodBuilder::Command::BuildAll ] }, "update" => { :opts => OptionParser.new do |opts| opts.banner = " Usage: $ pod_builder update [OPTIONS] Rebuild frameworks that are outdated Options: " opts.on("-u", "--skip-repo-update", "Skip CocoaPods repo update") do |o| OPTIONS[:update_repos] = false end opts.on("-w", "--allow-warnings", "Allow warnings") do |o| OPTIONS[:allow_warnings] = o end opts.on("-r", "--dry", "Determine which frameworks need update") do |o| OPTIONS[:dry_run] = o end opts.on("-d", "--debug", "Don't clean build folder") do |o| OPTIONS[:debug] = o end end, :call => [ PodBuilder::Command::Update ] }, "restore_all" => { :opts => OptionParser.new do |opts| opts.banner = " Usage: $ pod_builder restore_all [OPTIONS] Rebuilds all pods to the version specified in the Restore-Podfile. Options: " opts.on("-u", "--skip-repo-update", "Skip CocoaPods repo update") do |o| OPTIONS[:update_repos] = false end opts.on("-d", "--debug", "Don't clean build folder") do |o| OPTIONS[:debug] = o end end, :call => [ PodBuilder::Command::RestoreAll ] }, "init" => { :opts => OptionParser.new do |opts| opts.banner = " Usage: $ pod_builder init [OPTIONS] Initializes PodBuilder. Options: " opts.on("-d", "--destination path", "Prebuilt destination path (default: #{PodBuilder::Configuration.base_path})") do |o| OPTIONS[:prebuild_path] = o end end, :call => [ PodBuilder::Command::Init ] }, "generate_podspec" => { :opts => OptionParser.new do |opts| end, :call => [ PodBuilder::Command::GeneratePodspec ] }, "update_lfs" => { :opts => OptionParser.new do |opts| end, :call => [ PodBuilder::Command::GenerateLFS ] }, "deintegrate" => { :opts => OptionParser.new do |opts| opts.banner = " Usage: $ pod_builder deintegrate Remove PodBuilder from your project. Options: " end, :call => [ PodBuilder::Command::Deintegrate ] }, "clean" => { :opts => OptionParser.new do |opts| opts.banner = " Usage: $ pod_builder clean Remove unused framework, dSYM and source folders. Options: " end, :call => [ PodBuilder::Command::Clean ] }, "install_sources" => { :opts => OptionParser.new do |opts| opts.banner = " Usage: $ pod_builder install_sources Install source of prebuilt pods to be able to step into and debug framework's code. " end, :call => [ PodBuilder::Command::InstallSources ] }, "update_lldbinit" => { :opts => OptionParser.new do |opts| opts.banner = " Usage: $ pod_builder update_lldbinit Update LLDBINIT_PATH setting target.source-map in order to be able to step into and debug prebuilt framework's code. Specify the PATH of the folder containing the source code of prebuilt frameworks. PATH can be relative to PodBuilder's Framework folder. " end, :call => [ PodBuilder::Command::UpdateLldbInit ] }, "clear_lldbinit" => { :opts => OptionParser.new do |opts| opts.banner = " Usage: $ pod_builder clear_lldbinit Clear LLDBINIT_PATH setting target.source-map PodBuilder's customizations " end, :call => [ PodBuilder::Command::ClearLldbInit ] }, "switch" => { :opts => OptionParser.new do |opts| opts.banner = " Usage: $ pod_builder switch PODNAME [OPTIONS] Switch integration between prebuilt/development/default pod version. Options: " opts.on("-p", "--prebuilt", "Use prebuilt") do |o| OPTIONS[:switch_mode] = "prebuilt" end opts.on("-d", "--development", "Development pod") do |o| OPTIONS[:switch_mode] = "development" end opts.on("-s", "--default", "Default version specified in PodBuilder-Podfile") do |o| OPTIONS[:switch_mode] = "default" end end, :call => [ PodBuilder::Command::Switch ] }, "sync_podfile" => { :opts => OptionParser.new do |opts| opts.banner = " Usage: $ pod_builder sync_podfile Rewrite the Application-Podfile based on the PodBuilder-Podfile. You may want to run this command when you add a new pod to the PodBuilder-Podfile and you want to integrate it in the project without rebuilding it. " end, :call => [ PodBuilder::Command::SyncPodfile ] }, "info" => { :opts => OptionParser.new do |opts| opts.banner = " Usage: $ pod_builder info Output dependencies and prebuilt informations " end, :call => [ PodBuilder::Command::Info ] } } argv = ARGV.dup if subcommand = subcommands[argv.first] ARGV.shift else subcommand = subcommands["none"] end ret = -1 show_help = argv.include?("--help") || argv.include?("-h") || argv.count == 0 if show_help puts subcommand[:opts].help else PodBuilder::Configuration.load subcommand[:opts].order! subcommand[:call].each do |k| if (ret = k.call(OPTIONS)) && ret == -1 puts subcommand[:opts].help end end end return ret end command_ret = -1 begin unless ENV['USER'] != "root" raise "\n\nFor safety do not run this as root\n".red end PodBuilder::add_lock_file valid_lock_file = true command_ret = parse_commandline rescue Exception => e error = e.to_s if error.length < 1000 puts "#{error.red}\n" puts e.backtrace.join("\n\t").red puts "\n\nCommand failed!".red else error_log = File.join(PodBuilder::Configuration.build_path, "pod_builder.err") puts "\n\nCommand failed, check #{error_log}!".red File.write(error_log, error) end ensure if command_ret == 0 PodBuilder::clean_basepath if !OPTIONS.has_key?(:debug) PodBuilder::safe_rm_rf(PodBuilder::Configuration.build_path) end end if valid_lock_file PodBuilder::remove_lock_file end exit(command_ret) end