class Pod::Command::Fmwk::Build

Public Class Methods

new(argv) click to toggle source
Calls superclass method
# File lib/pod/command/fmwk/build.rb, line 48
def initialize(argv)
  @workspace           = argv.flag?('workspace')
  # @allow_warnings  = argv.flag?('allow-warnings')
  # @clean           = argv.flag?('clean', true)
  # @fail_fast       = argv.flag?('fail-fast', false)
  # @subspecs        = argv.flag?('subspecs', true)
  # @only_subspec    = argv.option('subspec')
  # @use_frameworks  = !argv.flag?('use-libraries')
  # @source_urls     = argv.option('sources', 'https://github.com/CocoaPods/Specs.git').split(',')
  # @private         = argv.flag?('private', false)
  # @swift_version   = argv.option('swift-version', nil)
  # @skip_import_validation = argv.flag?('skip-import-validation', false)
  # @skip_tests = argv.flag?('skip-tests', false)
  @framework_names = argv.arguments!
  super
end
options() click to toggle source
Calls superclass method
# File lib/pod/command/fmwk/build.rb, line 28
def self.options
  [
    ['--workspace', '构建 workspace,若不指定,默认为构建 project'],
    # ['--allow-warnings', 'Lint validates even if warnings are present'],
    # ['--subspec=NAME', 'Lint validates only the given subspec'],
    # ['--no-subspecs', 'Lint skips validation of subspecs'],
    # ['--no-clean', 'Lint leaves the build directory intact for inspection'],
    # ['--fail-fast', 'Lint stops on the first failing platform or subspec'],
    # ['--use-libraries', 'Lint uses static libraries to install the spec'],
    # ['--sources=https://github.com/artsy/Specs,master', 'The sources from which to pull dependent pods ' \
    #   '(defaults to https://github.com/CocoaPods/Specs.git). ' \
    #   'Multiple sources must be comma-delimited.'],
    # ['--private', 'Lint skips checks that apply only to public specs'],
    # ['--swift-version=VERSION', 'The SWIFT_VERSION that should be used to lint the spec. ' \
    #   'This takes precedence over a .swift-version file.'],
    # ['--skip-import-validation', 'Lint skips validating that the pod can be imported'],
    # ['--skip-tests', 'Lint skips building and running tests during validation'],
  ].concat(super)
end

Public Instance Methods

run() click to toggle source
# File lib/pod/command/fmwk/build.rb, line 69
def run
  framework_names.each do |podspec|
    `rm -rf #{build_path}` unless !Dir.exist?(build_path)

    puts "打真机包..."
    puts

    output = xcodebuild(podspec)
    puts output
    puts 

    puts "打模拟器包..."
    puts
    output = xcodebuild(podspec, :iphonesimulator)
    puts output
    puts
    puts "生成合成包..."
    puts
    `lipo #{derived_data_path}/#{podspec}/Build/Products/Release-iphoneos/#{podspec}.framework/#{podspec} #{derived_data_path}/#{podspec}/Build/Products/Release-iphonesimulator/#{podspec}.framework/#{podspec} -create -output #{build_path}/#{podspec}`
    `cp -r #{derived_data_path}/#{podspec}/Build/Products/Release-iphoneos/#{podspec}.framework #{build_path}/`
    `cp -f #{build_path}/#{podspec} #{build_path}/#{podspec}.framework/`
    `rm #{build_path}/#{podspec}`
    puts "成功输出 framework 于 #{build_path}/#{podspec}.framework/"
    puts
  end
end
validate!() click to toggle source
Calls superclass method
# File lib/pod/command/fmwk/build.rb, line 65
def validate!
  super
end

Private Instance Methods

_xcodebuild(command) click to toggle source
# File lib/pod/command/fmwk/build.rb, line 150
def _xcodebuild(command)
  UI.puts 'xcodebuild ' << command.join(' ') if config.verbose
  # Executable.capture_command('xcodebuild', command, :capture => :merge)
  require 'open3'
  Open3.pipeline('xcodebuild ' << command.join(' '), 'xcpretty')
end
build_path() click to toggle source
# File lib/pod/command/fmwk/build.rb, line 122
def build_path
  path = Dir.pwd + '/build'
  `mkdir -p #{path}` unless Dir.exist?(path)
  path
end
derived_data_path() click to toggle source
# File lib/pod/command/fmwk/build.rb, line 116
def derived_data_path
  path = Dir.home + '/Documents/Temp/DerivedData'
  `mkdir -p #{path}` unless Dir.exist?(path)
  path
end
framework_names() click to toggle source

@return [Pathname] The path of the podspec found in the current

working directory.

@raise If no podspec is found. @raise If multiple podspecs are found.

# File lib/pod/command/fmwk/build.rb, line 108
def framework_names
  if !@framework_names.empty?
    Array(@framework_names)
  else
    raise Informative, 'Please type in a framework name!'
  end
end
xcodebuild(target, type = :iphoneos, clean = true) click to toggle source
# File lib/pod/command/fmwk/build.rb, line 128
def xcodebuild(target, type = :iphoneos, clean = true)
  if clean
    command = %W(clean build)
  else
    command = []
  end

  if @workspace
    command += %W(-workspace #{target}.xcworkspace)
  else
    command += %W(-project #{target}.xcodeproj)
  end
  command += %W(-scheme #{target} -configuration Release -derivedDataPath #{derived_data_path}/#{target})
  case type
  when :iphoneos then command += %W(-sdk iphoneos)
  when :iphonesimulator then command += %W(-sdk iphonesimulator)
  end
  # command += %W(| xcpretty)
  output, status = _xcodebuild(command)
  output
end