Class: Xcodeproj::Project::Object::PBXNativeTarget

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-catalyst-support/xcodeproj/native_target.rb

Instance Method Summary collapse

Instance Method Details

#add_platform_filter_to_build_phases(platform) ⇒ Object

STEP 1 ###### In native target’s build phases, add platform filter to:

  • Resources

  • Compile Sources

  • Frameworks

  • Headers



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/cocoapods-catalyst-support/xcodeproj/native_target.rb', line 76

def add_platform_filter_to_build_phases platform
  loggs "\t\t- Filtering resources"
  resources_build_phase.files.to_a.map do |build_file| build_file.platform_filter = platform.filter end
  
  loggs "\t\t- Filtering compile sources"
  source_build_phase.files.to_a.map do |build_file| build_file.platform_filter = platform.filter end
  
  loggs "\t\t- Filtering frameworks"
  frameworks_build_phase.files.to_a.map do |build_file| build_file.platform_filter = platform.filter end
  
  loggs "\t\t- Filtering headers"
  headers_build_phase.files.to_a.map do |build_file| build_file.platform_filter = platform.filter end
end

#support_files_folderObject



17
18
19
# File 'lib/cocoapods-catalyst-support/xcodeproj/native_target.rb', line 17

def support_files_folder
  build_configurations.filter do |config| not config.base_configuration_reference.nil? end.first.base_configuration_reference.real_path.parent
end

#uninstall(keys, file_name, sdk_root) ⇒ Object



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
# File 'lib/cocoapods-catalyst-support/xcodeproj/native_target.rb', line 22

def uninstall keys, file_name, sdk_root
  configurations = build_configurations.map do |b| b.name end
  keys = keys.to_set.to_a
  loggs "\t\t\tUninstalling for configurations: #{configurations}"
  if support_files_folder.nil?
    loggs "\t\t\tNothing to uninstall"
    return
  end

  script_path = support_files_folder.join file_name
  if !script_path.exist?
    loggs "\t\t\tNothing to uninstall"
    return
  end

  script = File.read(script_path)
  snippets = script.scan(/if \[\[ \"\$CONFIGURATION\" [\S\s]*?(?=fi\n)fi/)
  archs_condition = "[[ \"$SDKROOT\" != *\"#{sdk_root}\"* ]]"
  file_condition_format = 'if [ -d "%s" ]; then'
  changed = false
  
  snippets.each do |snippet|
    new_snippet = snippet.clone
    should_uninstall = configurations.map do |string| snippet.include? string end.reduce(false) do |total, condition| total = total || condition end
    keys.each do |key|
      lines_to_replace = snippet.filter_lines do |line| line.match "\/#{key}" end.to_set.to_a
      unless lines_to_replace.empty?
        changed = true
        lines_to_replace.each do |line|
          if should_uninstall
            new_snippet.gsub! line, "\tif #{archs_condition}; then \n\t#{line}\tfi\n"
          elsif file_name.include? 'resources'
            path = line.scan(/[^(install_resource| |")].*[^*("|\n)]/).first
            file_condition = file_condition_format % path
            new_snippet.gsub! line, "\t#{file_condition} \n\t#{line}\tfi\n"
          end
        end
      end
    end
    script.gsub! snippet, new_snippet
  end

  if changed
    File.open(script_path, "w") { |file| file << script }
  end
  loggs "\t\t\t#{changed ? "Succeded" : "Nothing to uninstall"}"
end

#uninstall_frameworks(frameworks, platform) ⇒ Object

STEP 4 ###### In “Pods-” targets, modify “*frameworks.sh” to not install unsupported frameworks for SDK



7
8
9
# File 'lib/cocoapods-catalyst-support/xcodeproj/native_target.rb', line 7

def uninstall_frameworks frameworks, platform
  uninstall frameworks, "#{name}-frameworks.sh", platform.sdk_root
end

#uninstall_resources(resources, platform) ⇒ Object

STEP 5 ###### In “Pods-” targets, modify “*resources.sh” to not install unsupported resources for SDK



13
14
15
# File 'lib/cocoapods-catalyst-support/xcodeproj/native_target.rb', line 13

def uninstall_resources resources, platform
  uninstall resources, "#{name}-resources.sh", platform.sdk_root
end