lib/xcres/command/install_command.rb
# Integrate the build phase and add the built files to the project
#
# @param [Pathname] output_path
#        the argument OUTPUT_PATH for the build subcommand
#
# @param [PBXGroup] parent_group
#        the group where to integrate
#
# @return [void]
#
Integrate the build phase and add the built files to the project
Integrate the build phase and add the built files to the project
def integrate!(output_path, parent_group)
    build_phase = target.shell_script_build_phases.find do |bp|
      bp.name == BUILD_PHASE_NAME
    end
    build_phase ||= target.new_shell_script_build_phase(BUILD_PHASE_NAME)
    target.build_phases.delete(build_phase)
    index = target.build_phases.index(target.source_build_phase)
    target.build_phases.insert(index, build_phase)
    script_output_path = output_path.relative_path_from(src_root_path)
    documented_argument = documented? ? "--documented" : "--no-documented"
    swift_argument = swift? ? "--swift" : "--no-swift"
    build_phase.shell_script = "xcres --no-ansi build #{documented_argument} #{swift_argument} $PROJECT_FILE_PATH $SRCROOT/#{script_output_path}\n"
    build_phase.show_env_vars_in_log = '0'
    res_group = parent_group.groups.find { |g| g.name == 'Resources' }
    res_group ||= parent_group.new_group('Resources', Pathname('Resources'))
    if swift?
      swift_file = res_group.find_file_by_path('R.swift') || res_group.new_file('R.swift')
      target.source_build_phase.add_file_reference(swift_file, true)
    else
      h_file = res_group.find_file_by_path('R.h') || res_group.new_file('R.h')
      m_file = res_group.find_file_by_path('R.m') || res_group.new_file('R.m')
      target.source_build_phase.add_file_reference(m_file, true)
      prefix_headers.each do |path|
        realpath = src_root_path + path
        next unless File.exist?(realpath)
        File.open(realpath, 'a+') do |f|
          import_snippet = "#import \"#{h_file.path}\"\n"
          unless f.readlines.include?(import_snippet)
            f.write "\n#{import_snippet}"
          end
        end
      end
    end
    project.save()
  end
def integrate! ( output_path , parent_group ) build_phase = target . shell_script_build_phases . find do | bp | bp . name == BUILD_PHASE_NAME end build_phase ||= target . new_shell_script_build_phase ( BUILD_PHASE_NAME ) target . build_phases . delete ( build_phase ) index = target . build_phases . index ( target . source_build_phase ) target . build_phases . insert ( index , build_phase ) script_output_path = output_path . relative_path_from ( src_root_path ) documented_argument = documented? ? "--documented" : "--no-documented" swift_argument = swift? ? "--swift" : "--no-swift" build_phase . shell_script = "xcres --no-ansi build #{documented_argument} #{swift_argument} $PROJECT_FILE_PATH $SRCROOT/#{script_output_path}\n" build_phase . show_env_vars_in_log = '0' res_group = parent_group . groups . find { | g | g . name == 'Resources' } res_group ||= parent_group . new_group ( 'Resources' , Pathname ( 'Resources' ) ) if swift? swift_file = res_group . find_file_by_path ( 'R.swift' ) || res_group . new_file ( 'R.swift' ) target . source_build_phase . add_file_reference ( swift_file , true ) else h_file = res_group . find_file_by_path ( 'R.h' ) || res_group . new_file ( 'R.h' ) m_file = res_group . find_file_by_path ( 'R.m' ) || res_group . new_file ( 'R.m' ) target . source_build_phase . add_file_reference ( m_file , true ) prefix_headers . each do | path | realpath = src_root_path + path next unless File . exist? ( realpath ) File . open ( realpath , 'a+' ) do | f | import_snippet = "#import \"#{h_file.path}\"\n" unless f . readlines . include? ( import_snippet ) f . write "\n#{import_snippet}" end end end end project . save ( ) end
Integrate the build phase and add the built files to the project
Integrate the build phase and add the built files to the project
# Find or create shell script build phase # Remove build phase to re-insert before compile sources # Set shell script # Find or create 'Resources' group in 'Supporting Files' # Find or create references to resources index files # Add .swift file to source build phase, if it doesn't not already exist there # Find or create references to resources index files # Add .m file to source build phase, if it doesn't not already exist there # Add .h file to prefix header
None
void
output_path
parent_group
parent_group the group where to integrate
parent_group the group where to integrate