#!/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 items that are outdated + restore_all Rebuild all pods declared in the Restore-Podfile + install_sources Install sources of pods to debug into prebuilt items + generate_lldbinit Generate an lldbinit file with setting target.source-map to debug prebuilt items + switch Switch between prebuilt/development/standard pod in the Application-Podfile + clean Remove prebuild items, 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 items 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("-f", "--force", "Rebuild items even when no code change is detected") do |o| OPTIONS[:force_rebuild] = true 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("-f", "--force", "Rebuild items even when no code change is detected") do |o| OPTIONS[:force_rebuild] = 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 items 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 items need to be updated") 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 ] }, "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 prebuild data, dSYM and source folders. Options: " opts.on("-u", "--skip-repo-update", "Skip CocoaPods repo update") do |o| OPTIONS[:update_repos] = false end 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 prebuilt's code. " end, :call => [ PodBuilder::Command::InstallSources ] }, "generate_lldbinit" => { :opts => OptionParser.new do |opts| opts.banner = " Usage: $ pod_builder generate_lldbinit [PATH] Update PodBuilder's custom lldbinit by setting the target.source-map which allows to step into and debug prebuilt prebuilt's code. To allow this to work it is required to specify a path containing the source code that generated the prebuilt item. You can pass a [PATH] which PodBuilder will use to look for dependencies's source code. If omitted it will be implied that the project is organized as a monorepo expecting source code dependencies to live in the project repo. " end, :call => [ PodBuilder::Command::UpdateLldbInit ] }, "switch" => { :opts => OptionParser.new do |opts| opts.banner = " Usage: $ pod_builder switch [OPTIONS] PODNAME[s] Switch integration between prebuilt/development/default pod version. Multiple space separated pods can be passed 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 opts.on("-a", "--all", "Include dependencies") do |o| OPTIONS[:switch_all] = true 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. Options: " opts.on("-u", "--skip-repo-update", "Skip CocoaPods repo update") do |o| OPTIONS[:update_repos] = false end 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 PodBuilder::add_lockfile subcommand[:opts].order! subcommand[:call].each do |k| if (ret = k.call) && 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 command_ret = parse_commandline rescue Exception => e error = e.to_s if error.length < 1000 || !File.directory?(PodBuilder::Configuration.build_path) 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 end PodBuilder::remove_lockfile exit(command_ret) end