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/add_spm_pkgs.rb,
lib/cocoapods-spm/hooks/pre_integrate/update_settings.rb,
lib/cocoapods-spm/hooks/post_integrate/update_embed_frameworks_script.rb

Defined Under Namespace

Classes: AddSpmPkgs, UpdateEmbedFrameworksScript, UpdateSettings

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Config::Mixin

#macro_pods, #spm_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_analyzer = options[:spm_analyzer]
  @analysis_result = options[:analysis_result]
end

Class Method Details

.run_hooks(phase, context, options) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/cocoapods-spm/hooks/base.rb', line 43

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



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

def config
  Config.instance
end

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



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

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)
  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_targetsObject



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

def pod_targets
  @analysis_result.pod_targets
end

#pods_projectObject



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

def pods_project
  @context.pods_project
end

#runObject



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

def run; end

#sandboxObject



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

def sandbox
  @context.sandbox
end

#user_build_configurationsObject



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

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