#!/usr/bin/env ruby if ENV['RUBYLIB'] 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/version' 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 prebuild frameworks + 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 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. Options: " end, :call => [ PodBuilder::Command::InstallSources ] }, "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 ] } } subcommands["none"][:opts].order! subcommand = subcommands[ARGV.shift] ret = -1 if subcommand if ARGV.include?("--help") || ARGV.include?("-h") 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 else if !subcommands["none"][:call].first&.call(OPTIONS) puts subcommands["none"][:opts].help 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 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 = "/tmp/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 exit(command_ret) end