Class: XCCache::SPM::Buildable

Inherits:
Object
  • Object
show all
Defined in:
lib/xccache/spm/build.rb

Direct Known Subclasses

FrameworkSlice, Macro, XCFramework

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Buildable

Returns a new instance of Buildable.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/xccache/spm/build.rb', line 7

def initialize(options = {})
  @name = options[:name]
  @module_name = @name.c99extidentifier
  @pkg_dir = Pathname(options[:pkg_dir] || ".").expand_path
  @pkg_desc = options[:pkg_desc]
  @sdks = options[:sdks] || []
  @sdk = options[:sdk] || @sdks&.first
  @config = options[:config] || "debug"
  @path = options[:path]
  @tmpdir = options[:tmpdir]
  @library_evolution = options[:library_evolution]
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/xccache/spm/build.rb', line 4

def config
  @config
end

#library_evolutionObject (readonly) Also known as: library_evolution?

Returns the value of attribute library_evolution.



4
5
6
# File 'lib/xccache/spm/build.rb', line 4

def library_evolution
  @library_evolution
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



4
5
6
# File 'lib/xccache/spm/build.rb', line 4

def module_name
  @module_name
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/xccache/spm/build.rb', line 4

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/xccache/spm/build.rb', line 4

def path
  @path
end

#pkg_descObject (readonly)

Returns the value of attribute pkg_desc.



4
5
6
# File 'lib/xccache/spm/build.rb', line 4

def pkg_desc
  @pkg_desc
end

#pkg_dirObject (readonly)

Returns the value of attribute pkg_dir.



4
5
6
# File 'lib/xccache/spm/build.rb', line 4

def pkg_dir
  @pkg_dir
end

#sdkObject (readonly)

Returns the value of attribute sdk.



4
5
6
# File 'lib/xccache/spm/build.rb', line 4

def sdk
  @sdk
end

#sdksObject (readonly)

Returns the value of attribute sdks.



4
5
6
# File 'lib/xccache/spm/build.rb', line 4

def sdks
  @sdks
end

#tmpdirObject (readonly)

Returns the value of attribute tmpdir.



4
5
6
# File 'lib/xccache/spm/build.rb', line 4

def tmpdir
  @tmpdir
end

Instance Method Details

#build(options = {}) ⇒ Object

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/xccache/spm/build.rb', line 20

def build(options = {})
  raise NotImplementedError
end

#pkg_targetObject



48
49
50
# File 'lib/xccache/spm/build.rb', line 48

def pkg_target
  @pkg_target ||= pkg_desc.get_target(name)
end

#swift_build(target: nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/xccache/spm/build.rb', line 24

def swift_build(target: nil)
  cmd = ["swift", "build"] + swift_build_args
  cmd << "--package-path" << pkg_dir
  cmd << "--target" << (target || name)
  cmd << "--sdk" << sdk.sdk_path
  sdk.swiftc_args.each { |arg| cmd << "-Xswiftc" << arg }
  if library_evolution?
    # Workaround for swiftinterface emission
    # https://github.com/swiftlang/swift/issues/64669#issuecomment-1535335601
    cmd << "-Xswiftc" << "-enable-library-evolution"
    cmd << "-Xswiftc" << "-alias-module-names-in-module-interface"
    cmd << "-Xswiftc" << "-emit-module-interface"
    cmd << "-Xswiftc" << "-no-verify-emitted-module-interface"
  end
  Sh.run(cmd)
end

#swift_build_argsObject



41
42
43
44
45
46
# File 'lib/xccache/spm/build.rb', line 41

def swift_build_args
  [
    "--configuration", config,
    "--triple", sdk.triple,
  ]
end