Class: Pod::Installer::PodSourceInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-binary-cache/pod-binary/integration/source_installer.rb

Instance Method Summary collapse

Instance Method Details

#install_for_prebuild!(standard_sanbox) ⇒ Object



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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/cocoapods-binary-cache/pod-binary/integration/source_installer.rb', line 13

def install_for_prebuild!(standard_sanbox)
  return if !Podfile::DSL.dev_pods_enabled && standard_sanbox.local?(name)

  # make a symlink to target folder
  prebuild_sandbox = Pod::PrebuildSandbox.from_standard_sandbox(standard_sanbox)
  # if spec used in multiple platforms, it may return multiple paths
  target_names = prebuild_sandbox.existed_target_names_for_pod_name(self.name)

  def walk(path, &action)
    return unless path.exist?
    path.children.each do |child|
      result = action.call(child, &action)
      if child.directory?
        walk(child, &action) if result
      end
    end
  end

  def make_link(source, target)
    source = Pathname.new(source)
    target = Pathname.new(target)
    target.parent.mkpath unless target.parent.exist?
    relative_source = source.relative_path_from(target.parent)
    FileUtils.ln_sf(relative_source, target)
  end

  def mirror_with_symlink(source, basefolder, target_folder)
    target = target_folder + source.relative_path_from(basefolder)
    make_link(source, target)
  end

  target_names.each do |name|

    # symbol link copy all substructure
    real_file_folder = prebuild_sandbox.framework_folder_path_for_target_name(name)

    # If have only one platform, just place int the root folder of this pod.
    # If have multiple paths, we use a sperated folder to store different
    # platform frameworks. e.g. AFNetworking/AFNetworking-iOS/AFNetworking.framework

    target_folder = standard_sanbox.pod_dir(self.name)
    if target_names.count > 1
      target_folder += real_file_folder.basename
    end

    if !standard_sanbox.local?(name)
      target_folder.rmtree if target_folder.exist?
      target_folder.mkpath
    else
      system "find #{target_folder} -type l -delete" # Only clean up symlink, keep source code for local pod
    end

    walk(real_file_folder) do |child|
      source = child
      # only make symlink to file and `.framework` folder
      if child.directory? and [".framework", ".dSYM"].include? child.extname
        if child.extname == ".framework"
          mirror_with_symlink(source, real_file_folder, target_folder)
        else
          # Ignore dsym here to avoid cocoapods from adding install_dsym to buildphase-script
          # That can cause duplicated output files error in Xcode 11 (warning in Xcode 10)
          # We need more setup to support local debuging with prebuilt dSYM
        end
        next false  # return false means don't go deeper
      elsif child.file?
        mirror_with_symlink(source, real_file_folder, target_folder)
        next true
      else
        next true
      end
    end

    # symbol link copy resource for static framework
     = PodPrebuild::Metadata.in_dir(real_file_folder)
    next unless .static_framework?

    .resources.each do |path|
      target_file_path = path.sub("${PODS_ROOT}", sandbox.root.to_path)
                             .sub("${PODS_CONFIGURATION_BUILD_DIR}", sandbox.root.to_path)
      real_file_path = real_file_folder + .framework_name + File.basename(path)
      case File.extname(path)
      when ".xib"
        # https://github.com/grab/cocoapods-binary-cache/issues/7
        # When ".xib" files are compiled in a framework, it becomes ".nib" files
        # --> We need to correct the path extension
        real_file_path = real_file_path.sub_ext(".nib")
        target_file_path = target_file_path.sub(".xib", ".nib")
      when ".bundle"
        next if .resource_bundles.include?(File.basename(path))

        real_file_path = real_file_folder + File.basename(path) unless real_file_path.exist?
      end
      make_link(real_file_path, target_file_path)
    end
  end
end


31
32
33
34
35
36
37
# File 'lib/cocoapods-binary-cache/pod-binary/integration/source_installer.rb', line 31

def make_link(source, target)
  source = Pathname.new(source)
  target = Pathname.new(target)
  target.parent.mkpath unless target.parent.exist?
  relative_source = source.relative_path_from(target.parent)
  FileUtils.ln_sf(relative_source, target)
end


39
40
41
42
# File 'lib/cocoapods-binary-cache/pod-binary/integration/source_installer.rb', line 39

def mirror_with_symlink(source, basefolder, target_folder)
  target = target_folder + source.relative_path_from(basefolder)
  make_link(source, target)
end

#walk(path, &action) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/cocoapods-binary-cache/pod-binary/integration/source_installer.rb', line 21

def walk(path, &action)
  return unless path.exist?
  path.children.each do |child|
    result = action.call(child, &action)
    if child.directory?
      walk(child, &action) if result
    end
  end
end