Class: Pod::Installer::SandboxDirCleaner

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/installer/sandbox_dir_cleaner.rb

Overview

Cleans up the sandbox directory by removing stale target support files and headers.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sandbox, pod_targets, aggregate_targets) ⇒ SandboxDirCleaner

Initialize a new instance


26
27
28
29
30
# File 'lib/cocoapods/installer/sandbox_dir_cleaner.rb', line 26

def initialize(sandbox, pod_targets, aggregate_targets)
  @sandbox = sandbox
  @pod_targets = pod_targets
  @aggregate_targets = aggregate_targets
end

Instance Attribute Details

#aggregate_targetsArray<AggregateTarget> (readonly)


18
19
20
# File 'lib/cocoapods/installer/sandbox_dir_cleaner.rb', line 18

def aggregate_targets
  @aggregate_targets
end

#pod_targetsArray<PodTarget> (readonly)


13
14
15
# File 'lib/cocoapods/installer/sandbox_dir_cleaner.rb', line 13

def pod_targets
  @pod_targets
end

#sandboxSandbox (readonly)


8
9
10
# File 'lib/cocoapods/installer/sandbox_dir_cleaner.rb', line 8

def sandbox
  @sandbox
end

Instance Method Details

#clean!Object


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
# File 'lib/cocoapods/installer/sandbox_dir_cleaner.rb', line 32

def clean!
  UI.message('Cleaning up sandbox directory') do
    # Clean up Target Support Files Directory
    target_support_dirs_to_install = (pod_targets + aggregate_targets).map(&:support_files_dir)
    target_support_dirs = sandbox_target_support_dirs

    removed_target_support_dirs = target_support_dirs - target_support_dirs_to_install
    removed_target_support_dirs.each { |dir| remove_dir(dir) }

    # Clean up Sandbox Headers Directory
    sandbox_private_headers_to_install = pod_targets.flat_map do |pod_target|
      if pod_target.header_mappings_by_file_accessor.empty?
        []
      else
        [pod_target.build_headers.root.join(pod_target.headers_sandbox)]
      end
    end
    sandbox_public_headers_to_install = pod_targets.flat_map do |pod_target|
      if pod_target.public_header_mappings_by_file_accessor.empty?
        []
      else
        [
          sandbox.public_headers.root.join(pod_target.headers_sandbox),
          pod_target.module_map_path.dirname,
        ].uniq
      end
    end

    removed_sandbox_public_headers = sandbox_public_headers - sandbox_public_headers_to_install
    removed_sandbox_public_headers.each { |path| remove_dir(path) }

    removed_sandbox_private_headers = sandbox_private_headers(pod_targets) - sandbox_private_headers_to_install
    removed_sandbox_private_headers.each { |path| remove_dir(path) }

    project_dir_names_to_install = pod_targets.map do |pod_target|
      sandbox.pod_target_project_path(pod_target.project_name)
    end
    project_dir_names = sandbox_project_dir_names - [sandbox.project_path]

    removed_project_dir_names = project_dir_names - project_dir_names_to_install
    removed_project_dir_names.each { |dir| remove_dir(dir) }
  end
end