Class: Pod::SPM::Hook

Inherits:
Object
  • Object
show all
Includes:
Installer::InstallerMixin, Config::Mixin
Defined in:
lib/cocoapods-spm/hooks/base.rb,
lib/cocoapods-spm/hooks/post_integrate/01.add_spm_pkgs.rb,
lib/cocoapods-spm/hooks/post_integrate/05.update_settings.rb,
lib/cocoapods-spm/hooks/post_integrate/06.update_macro_platforms.rb,
lib/cocoapods-spm/hooks/post_integrate/21.update_copy_resources_script.rb,
lib/cocoapods-spm/hooks/post_integrate/20.update_embed_frameworks_script.rb

Defined Under Namespace

Classes: AddSpmPkgs, UpdateCopyResourcesScript, UpdateEmbedFrameworksScript, UpdateMacroPlatforms, UpdateSettings

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Installer::InstallerMixin

#native_targets, #projects_to_integrate

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 PathMixn

#prepare_dir

Methods included from Config::ProjectConfigMixin

#project_config

Constructor Details

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

Returns a new instance of Hook.



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

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



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

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



31
32
33
# File 'lib/cocoapods-spm/hooks/base.rb', line 31

def aggregate_targets
  @analysis_result.targets
end

#configObject



43
44
45
# File 'lib/cocoapods-spm/hooks/base.rb', line 43

def config
  Config.instance
end

#macro_metadata_for_pod(name) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/cocoapods-spm/hooks/base.rb', line 96

def (name)
  return nil unless spm_config.all_macros.include?(name)

  @macro_metadata_cache ||= {}
  @macro_metadata_cache[name] = MacroMetadata.for_pod(name) unless @macro_metadata_cache.key?(name)
  @macro_metadata_cache[name]
end

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



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

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_name_of_target(name) ⇒ Object



104
105
106
107
# File 'lib/cocoapods-spm/hooks/base.rb', line 104

def pod_name_of_target(name)
  target = @analysis_result.pod_targets.find { |x| x.name == name }
  target.nil? ? name : target.pod_name
end

#pod_target_subprojectsObject



35
36
37
# File 'lib/cocoapods-spm/hooks/base.rb', line 35

def pod_target_subprojects
  @context.pod_target_subprojects
end

#pod_targetsObject



27
28
29
# File 'lib/cocoapods-spm/hooks/base.rb', line 27

def pod_targets
  @analysis_result.pod_targets
end

#podfileObject



47
48
49
# File 'lib/cocoapods-spm/hooks/base.rb', line 47

def podfile
  pod_config.podfile
end

#pods_projectObject



23
24
25
# File 'lib/cocoapods-spm/hooks/base.rb', line 23

def pods_project
  @context.pods_project
end

#runObject



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

def run; end

#sandboxObject



19
20
21
# File 'lib/cocoapods-spm/hooks/base.rb', line 19

def sandbox
  @context.sandbox
end

#user_build_configurationsObject



39
40
41
# File 'lib/cocoapods-spm/hooks/base.rb', line 39

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