Module: FIR::Build

Defined in:
lib/fir/util/build.rb

Instance Method Summary collapse

Instance Method Details

#build_apk(*args, options) ⇒ Object



72
73
# File 'lib/fir/util/build.rb', line 72

def build_apk *args, options
end

#build_ipa(*args, options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fir/util/build.rb', line 6

def build_ipa *args, options
  # initialize build options
  if args.first.blank? || !File.exist?(args.first)
    build_dir = Dir.pwd
  else
    build_dir = File.absolute_path(args.shift.to_s) # pop the first param
  end

  build_cmd       = "xcodebuild build -sdk iphoneos"
  build_tmp_dir   = Dir.mktmpdir
  custom_settings = parse_custom_settings(args) # convert ['a=1', 'b=2'] => { 'a' => '1', 'b' => '2' }
  configuration   = options[:configuration]
  target_name     = options[:target]
  scheme_name     = options[:scheme]
  output_path     = options[:output].blank? ? "#{build_dir}/build_ipa" : File.absolute_path(options[:output].to_s)

  # check build environment and make build cmd
  check_osx
  if options.workspace?
    workspace = check_and_find_workspace(build_dir)
    check_scheme(scheme_name)
    build_cmd += " -workspace '#{workspace}' -scheme '#{scheme_name}'"
  else
    project = check_and_find_project(build_dir)
    build_cmd += " -project '#{project}'"
  end

  build_cmd += " -configuration '#{configuration}'" unless configuration.blank?
  build_cmd += " -target '#{target_name}'" unless target_name.blank?

  # convert { "a" => "1", "b" => "2" } => "a='1' b='2'"
  setting_str =  custom_settings.collect { |k, v| "#{k}='#{v}'" }.join(' ')
  setting_str += " TARGET_BUILD_DIR='#{build_tmp_dir}'" unless custom_settings['TARGET_BUILD_DIR']
  setting_str += " CONFIGURATION_BUILD_DIR='#{build_tmp_dir}'" unless custom_settings['CONFIGURATION_BUILD_DIR']
  setting_str += " DWARF_DSYM_FOLDER_PATH='#{output_path}'" unless custom_settings['DWARF_DSYM_FOLDER_PATH']

  build_cmd += " #{setting_str} 2>&1"
  puts build_cmd if $DEBUG

  logger.info "Building......"
  logger_info_dividing_line

  logger.info `#{build_cmd}`

  FileUtils.mkdir_p(output_path) unless File.exist?(output_path)
  Dir.chdir(build_tmp_dir) do
    apps = Dir["*.app"]
    if apps.length == 0
      logger.error "Builded has no output app, Can not be packaged"
      exit 1
    end

    apps.each do |app|
      ipa_path = File.join(output_path, "#{File.basename(app, '.app')}.ipa")
      zip_app2ipa(File.join(build_tmp_dir, app), ipa_path)
    end
  end

  logger.info "Build Success"

  if options.publish?
    ipa_path = Dir["#{output_path}/*.ipa"].first
    publish(ipa_path, short: options[:short], changelog: options[:changelog], token: options[:token])
  end
end