Class: Pod::SPM::Hook

Inherits:
Object
  • Object
show all
Includes:
Config::Mixin
Defined in:
lib/cocoapods-spm/hooks/base.rb,
lib/cocoapods-spm/hooks/post_integrate/1.add_spm_pkgs.rb,
lib/cocoapods-spm/hooks/post_integrate/5.update_settings.rb,
lib/cocoapods-spm/hooks/post_integrate/7.update_copy_resources_script.rb,
lib/cocoapods-spm/hooks/post_integrate/6.update_embed_frameworks_script.rb

Defined Under Namespace

Classes: AddSpmPkgs, UpdateCopyResourcesScript, UpdateEmbedFrameworksScript, UpdateSettings

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Config::SPMConfigMixin

#local_macro_pod?, #local_macro_pod_dir, #macro_pods, #spm_config

Methods included from Config::PodConfigMixin

#pod_config

Methods included from Config::ProjectConfigMixin

#project_config

Constructor Details

#initialize(context, options = {}) ⇒ Hook

Returns a new instance of Hook.



10
11
12
13
14
15
# File 'lib/cocoapods-spm/hooks/base.rb', line 10

def initialize(context, options = {})
  @context = context
  @options = options
  @spm_resolver = options[:spm_resolver]
  @analysis_result = options[:analysis_result]
end

Class Method Details

.run_hooks(phase, context, options) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/cocoapods-spm/hooks/base.rb', line 55

def self.run_hooks(phase, context, options)
  Dir["#{__dir__}/#{phase}/*.rb"].sort.each do |f|
    require f
    id = File.basename(f, ".*").split(".").last
    cls_name = "Pod::SPM::Hook::#{id.camelize}"
    UI.message "- Running hook: #{cls_name}" do
      cls_name.constantize.new(context, options).run
    end
  end
end

Instance Method Details

#aggregate_targetsObject



29
30
31
# File 'lib/cocoapods-spm/hooks/base.rb', line 29

def aggregate_targets
  @analysis_result.targets
end

#configObject



45
46
47
# File 'lib/cocoapods-spm/hooks/base.rb', line 45

def config
  Config.instance
end

#perform_settings_update(update_targets: nil, update_pod_targets: nil, update_aggregate_targets: nil) ⇒ Object



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
# File 'lib/cocoapods-spm/hooks/base.rb', line 66

def perform_settings_update(
  update_targets: nil,
  update_pod_targets: nil,
  update_aggregate_targets: nil
)
  proc = lambda do |update, target, setting, config|
    return if update.nil?

    hash = update.call(target, setting, config)
    setting.xcconfig.merge!(hash)
    setting.generate.merge!(hash)
    Installer::Xcode::PodsProjectGenerator::TargetInstallerHelper.update_changed_file(
      setting, target.xcconfig_path(config)
    )
  end

  pod_targets.each do |target|
    target.build_settings.each do |config, setting|
      proc.call(update_targets, target, setting, config)
      proc.call(update_pod_targets, target, setting, config)
    end
  end

  aggregate_targets.each do |target|
    target.user_build_configurations.each_key do |config|
      setting = target.build_settings(config)
      proc.call(update_targets, target, setting, config)
      proc.call(update_aggregate_targets, target, setting, config)
    end
  end
end

#pod_target_subprojectsObject



33
34
35
# File 'lib/cocoapods-spm/hooks/base.rb', line 33

def pod_target_subprojects
  @context.pod_target_subprojects
end

#pod_targetsObject



25
26
27
# File 'lib/cocoapods-spm/hooks/base.rb', line 25

def pod_targets
  @analysis_result.pod_targets
end

#podfileObject



49
50
51
# File 'lib/cocoapods-spm/hooks/base.rb', line 49

def podfile
  pod_config.podfile
end

#pods_projectObject



21
22
23
# File 'lib/cocoapods-spm/hooks/base.rb', line 21

def pods_project
  @context.pods_project
end

#projects_to_integrateObject



37
38
39
# File 'lib/cocoapods-spm/hooks/base.rb', line 37

def projects_to_integrate
  [pods_project] + pod_target_subprojects
end

#runObject



53
# File 'lib/cocoapods-spm/hooks/base.rb', line 53

def run; end

#sandboxObject



17
18
19
# File 'lib/cocoapods-spm/hooks/base.rb', line 17

def sandbox
  @context.sandbox
end

#user_build_configurationsObject



41
42
43
# File 'lib/cocoapods-spm/hooks/base.rb', line 41

def user_build_configurations
  @user_build_configurations ||= (pod_targets + aggregate_targets)[0].user_build_configurations
end