Class: XCCache::SPM::Macro
- Defined in:
- lib/xccache/spm/macro.rb
Instance Attribute Summary collapse
-
#macosx_sdk ⇒ Object
readonly
Returns the value of attribute macosx_sdk.
Attributes inherited from Buildable
#config, #library_evolution, #module_name, #name, #path, #pkg_desc, #pkg_dir, #sdk, #sdks, #tmpdir
Instance Method Summary collapse
- #build(_options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Macro
constructor
A new instance of Macro.
- #products_dir ⇒ Object
Methods inherited from Buildable
#pkg_target, #swift_build, #swift_build_args
Constructor Details
Instance Attribute Details
#macosx_sdk ⇒ Object (readonly)
Returns the value of attribute macosx_sdk.
6 7 8 |
# File 'lib/xccache/spm/macro.rb', line 6 def macosx_sdk @macosx_sdk end |
Instance Method Details
#build(_options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/xccache/spm/macro.rb', line 14 def build( = {}) # NOTE: Building macro binary is tricky... # -------------------------------------------------------------------------------- # Consider this manifest config: .target(Macro) -> .macro(MacroImpl) # where `.target(Macro)` contains the interfaces # and `.target(MacroImpl)` contains the implementation # -------------------------------------------------------------------------------- # Building `.macro(MacroImpl)` does not produce the tool binary (MacroImpl-tool)... Only `.o` files. # Yet, linking those files are exhaustive due to many dependencies in swift-syntax # Luckily, building `.target(Macro)` does produce the tool binary. # -> WORKAROUND: Find the associated regular target and build it, then collect the tool binary # --------------------------------------------------------------------------------- associated_target = pkg_desc.targets.find { |t| t.direct_dependency_targets.include?(pkg_target) } UI.( "#{name.yellow.dark} is a macro target. " \ "Will build the associated target #{associated_target.name.dark} to get the tool binary." ) swift_build(target: associated_target.name) binary_path = products_dir / "#{module_name}-tool" raise GeneralError, "Tool binary not exist at: #{binary_path}" unless binary_path.exist? binary_path.copy(to: path) FileUtils.chmod("+x", path) UI.info("-> Macro binary: #{path.to_s.dark}") end |
#products_dir ⇒ Object
39 40 41 |
# File 'lib/xccache/spm/macro.rb', line 39 def products_dir @products_dir ||= pkg_dir / ".build" / macosx_sdk.triple / config end |