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.



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

def initialize(options = {})
  @name = options[:name]
  @module_name = @name.c99extidentifier
  @pkg_dir = Pathname(options[:pkg_dir] || ".").expand_path
  @pkg_desc = options[:pkg_desc]
  @ctx_desc = options[:ctx_desc] # Context desc, could be an umbrella or a standalone pkg
  @sdks = options[:sdks] || []
  @sdk = options[:sdk] || @sdks&.first
  @config = options[:config] || "debug"
  @path = options[:path]
  @tmpdir = options[:tmpdir]
  @library_evolution = options[:library_evolution]
  @sdks.each { |sdk| sdk.version = @ctx_desc.platforms[sdk.platform] } if @ctx_desc
  @live_log = options[:live_log]
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

#live_logObject (readonly)

Returns the value of attribute live_log.



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

def live_log
  @live_log
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)


24
25
26
# File 'lib/xccache/spm/build.rb', line 24

def build(options = {})
  raise NotImplementedError
end

#pkg_targetObject



56
57
58
# File 'lib/xccache/spm/build.rb', line 56

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

#sh(cmd) ⇒ Object



45
46
47
# File 'lib/xccache/spm/build.rb', line 45

def sh(cmd)
  Sh.run(cmd, live_log: live_log)
end

#swift_build(target: nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/xccache/spm/build.rb', line 28

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(cmd)
end

#swift_build_argsObject



49
50
51
52
53
54
# File 'lib/xccache/spm/build.rb', line 49

def swift_build_args
  [
    "--configuration", config,
    "--triple", sdk.triple(with_version: true),
  ]
end