Class: Pod::Installer::UserProjectIntegrator::TargetIntegrator

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/taobao/environment/deintegrate_pods_for_framework_1.0.rb,
lib/cocoapods/taobao/environment/deintegrate_pods_for_framework_0.39.rb,
lib/cocoapods/taobao/environment/integrate_copy_framework_resouces_script.rb,
lib/cocoapods/taobao/environment/integrate_copy_framework_resouces_script_1.1.rb

Instance Method Summary collapse

Instance Method Details

#add_copy_resources_script_phaseObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cocoapods/taobao/environment/integrate_copy_framework_resouces_script.rb', line 38

def add_copy_resources_script_phase
	old_add_copy_resources_script_phase
  phase_name = 'Copy Framework Resources'
  targets = PodVersion("~>1.0") ? native_targets : native_targets_to_integrate
  targets = targets.select { |t| EMBED_FRAMEWORK_TARGET_TYPES.include?(t.symbol_type) }
  targets.each do |native_target|
      phase = create_or_update_build_phase(native_target, phase_name)
      script_path = target.copy_framework_resources_script_relative_path
      phase.shell_script = %(bash -l -c "ruby \\"#{script_path}\\"")
  end
end

#create_or_update_build_phase(target, phase_name, phase_class = Xcodeproj::Project::Object::PBXShellScriptBuildPhase) ⇒ Object



40
41
42
43
44
45
# File 'lib/cocoapods/taobao/environment/deintegrate_pods_for_framework_1.0.rb', line 40

def create_or_update_build_phase(target, phase_name, phase_class = Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
  if !EMBED_FRAMEWORK_TARGET_TYPES.include?(target.symbol_type) and phase_name == COPY_PODS_RESOURCES_PHASE_NAME
    return target.project.new(phase_class)
  end
  old_create_or_update_build_phase(target, phase_name, phase_class)
end

#integrate!Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/cocoapods/taobao/environment/deintegrate_pods_for_framework_1.0.rb', line 7

def integrate!
  old_integrate!
  framework_targets = native_targets.select do |target|
    !EMBED_FRAMEWORK_TARGET_TYPES.include?(target.symbol_type)
  end
  framework_targets.each do |native_target|
    remove_pods_library_from_target(native_target)
    remove_copy_resources_script_phase_from_target(native_target)
  end
end

#native_targets_to_integrateObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cocoapods/taobao/environment/deintegrate_pods_for_framework_0.39.rb', line 41

def native_targets_to_integrate
  unless @native_targets_to_integrate
    old_native_targets_to_integrate
    unless @native_targets_to_integrate.nil?
      targets = native_targets.select do |native_target|
        native_target.shell_script_build_phases.find { |bp| bp.name == "Copy Framework Resources" }.nil?
      end
      @native_targets_to_integrate += targets if targets.present?
      @native_targets_to_integrate.uniq!
      @native_targets_to_integrate = @native_targets_to_integrate.select do |target|
        EMBED_FRAMEWORK_TARGET_TYPES.include?(target.symbol_type)
      end
    end
  end
  @native_targets_to_integrate
end

#old_add_copy_resources_script_phaseObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cocoapods/taobao/environment/integrate_copy_framework_resouces_script.rb', line 37

def add_copy_resources_script_phase
	old_add_copy_resources_script_phase
  phase_name = 'Copy Framework Resources'
  targets = PodVersion("~>1.0") ? native_targets : native_targets_to_integrate
  targets = targets.select { |t| EMBED_FRAMEWORK_TARGET_TYPES.include?(t.symbol_type) }
  targets.each do |native_target|
      phase = create_or_update_build_phase(native_target, phase_name)
      script_path = target.copy_framework_resources_script_relative_path
      phase.shell_script = %(bash -l -c "ruby \\"#{script_path}\\"")
  end
end

#old_create_or_update_build_phaseObject



39
# File 'lib/cocoapods/taobao/environment/deintegrate_pods_for_framework_1.0.rb', line 39

alias_method :old_create_or_update_build_phase, :create_or_update_build_phase

#old_integrate!Object



6
# File 'lib/cocoapods/taobao/environment/deintegrate_pods_for_framework_1.0.rb', line 6

alias_method :old_integrate!, :integrate!

#old_native_targets_to_integrateObject



40
# File 'lib/cocoapods/taobao/environment/deintegrate_pods_for_framework_0.39.rb', line 40

alias_method :old_native_targets_to_integrate, :native_targets_to_integrate

#old_update_to_cocoapods_0_39Object



6
# File 'lib/cocoapods/taobao/environment/deintegrate_pods_for_framework_0.39.rb', line 6

alias_method :old_update_to_cocoapods_0_39, :update_to_cocoapods_0_39

#remove_copy_resources_script_phase_from_target(native_target) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/cocoapods/taobao/environment/deintegrate_pods_for_framework_1.0.rb', line 31

def remove_copy_resources_script_phase_from_target(native_target)
  phase_name = BUILD_PHASE_PREFIX + COPY_PODS_RESOURCES_PHASE_NAME
  resource_build_phase = native_target.shell_script_build_phases.find { |bp| bp.name == phase_name }
  return false unless resource_build_phase.present?
  native_target.build_phases.delete(resource_build_phase)
  true
end

#remove_pods_library_from_target(native_target) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cocoapods/taobao/environment/deintegrate_pods_for_framework_1.0.rb', line 18

def remove_pods_library_from_target(native_target)
  frameworks = user_project.frameworks_group
  build_phase = native_target.frameworks_build_phase
  new_product_ref = frameworks.files.find { |f| f.path == target.product_name }
  if new_product_ref.present?
    UI.message("Removing Pod product reference #{target.product_name} from project.")
    build_phase.remove_file_reference(new_product_ref)
    frameworks.remove_reference(new_product_ref)
    return true
  end
  false
end

#update_to_cocoapods_0_39Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/cocoapods/taobao/environment/deintegrate_pods_for_framework_0.39.rb', line 7

def update_to_cocoapods_0_39
  requires_update = old_update_to_cocoapods_0_39
  framework_targets = native_targets.select do |target|
    !EMBED_FRAMEWORK_TARGET_TYPES.include?(target.symbol_type)
  end
  framework_targets.each do |native_target|
    requires_update = remove_pods_library_from_target(native_target) || requires_update
    requires_update = remove_copy_resources_script_phase_from_target(native_target) || requires_update
  end
  requires_update
end