Class: Pod::SPM::MacroPrebuilder

Inherits:
Object
  • Object
show all
Includes:
Config::Mixin, Executables
Defined in:
lib/cocoapods-spm/macro/prebuilder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Config::SPMConfigMixin

#macro_pods, #spm_config

Methods included from Config::PodConfigMixin

#pod_config

Methods included from Config::ProjectConfigMixin

#project_config

Constructor Details

#initialize(options = {}) ⇒ MacroPrebuilder

Returns a new instance of MacroPrebuilder.



11
12
13
# File 'lib/cocoapods-spm/macro/prebuilder.rb', line 11

def initialize(options = {})
  @name = options[:name]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/cocoapods-spm/macro/prebuilder.rb', line 9

def name
  @name
end

Instance Method Details

#generate_metadataObject



36
37
38
39
40
41
42
43
# File 'lib/cocoapods-spm/macro/prebuilder.rb', line 36

def 
  raise "Package.swift not exist in #{macro_downloaded_dir}" \
    unless (macro_downloaded_dir / "Package.swift").exist?

  raw = Dir.chdir(macro_downloaded_dir) { `swift package dump-package` }
  .write(raw)
   = .from_s(raw)
end

#macro_dirObject



24
25
26
# File 'lib/cocoapods-spm/macro/prebuilder.rb', line 24

def macro_dir
  @macro_dir ||= spm_config.macro_root_dir / name
end

#macro_downloaded_dirObject



20
21
22
# File 'lib/cocoapods-spm/macro/prebuilder.rb', line 20

def macro_downloaded_dir
  spm_config.macro_downloaded_root_dir / name
end

#macro_prebuilt_dirObject



28
29
30
# File 'lib/cocoapods-spm/macro/prebuilder.rb', line 28

def macro_prebuilt_dir
  macro_dir / ".prebuilt"
end

#metadata_pathObject



32
33
34
# File 'lib/cocoapods-spm/macro/prebuilder.rb', line 32

def 
  macro_dir / "metadata.json"
end

#prebuild_macro_implObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cocoapods-spm/macro/prebuilder.rb', line 45

def prebuild_macro_impl
  return if spm_config.dont_prebuild_macros?

  config = spm_config.macro_config
  impl_module_name = .macro_impl_name
  return if spm_config.dont_prebuild_macros_if_exist? && (macro_prebuilt_dir / config / impl_module_name).exist?

  UI.section "Building macro implementation: #{impl_module_name} (#{config})...".green do
    Dir.chdir(macro_downloaded_dir) do
      swift! ["build", "-c", config, "--product", impl_module_name]
    end
  end

  (macro_prebuilt_dir / config).mkpath
  FileUtils.copy_entry(
    macro_downloaded_dir / ".build" / config / impl_module_name,
    macro_prebuilt_dir / config / impl_module_name
  )
end

#runObject



15
16
17
18
# File 'lib/cocoapods-spm/macro/prebuilder.rb', line 15

def run
  
  prebuild_macro_impl
end