Class: XCCache::SPM::Package::Target

Inherits:
BaseObject show all
Includes:
Cacheable
Defined in:
lib/xccache/spm/desc/target.rb

Direct Known Subclasses

BinaryTarget, MacroTarget

Constant Summary

Constants inherited from BaseObject

BaseObject::ATTRS

Instance Attribute Summary

Attributes inherited from HashRepresentable

#path, #raw

Instance Method Summary collapse

Methods included from Cacheable

#__cacheable_module_name, #cacheable, included

Methods inherited from BaseObject

#cast_to, #display_name, #fetch, #full_name, #inspect, #name, #pkg_desc_of, #pkg_name, #pkg_slug, #src_dir, #to_s

Methods included from Config::Mixin

#config

Methods inherited from JSONRepresentable

#load, #save

Methods inherited from HashRepresentable

#[], #[]=, #initialize, #load, #merge!, #reload, #save

Constructor Details

This class inherits a constructor from XCCache::HashRepresentable

Instance Method Details

#binary?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/xccache/spm/desc/target.rb', line 127

def binary?
  type == :binary
end

#binary_pathObject



131
132
133
# File 'lib/xccache/spm/desc/target.rb', line 131

def binary_path
  sources_path if binary?
end

#checksumObject



139
140
141
# File 'lib/xccache/spm/desc/target.rb', line 139

def checksum
  @checksum ||= root.git&.sha || sources_path.checksum
end

#direct_dependencies(platform: nil) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/xccache/spm/desc/target.rb', line 103

def direct_dependencies(platform: nil)
  raw["dependencies"].flat_map do |hash|
    dep_types = ["byName", "target", "product"]
    if (dep_type = dep_types.intersection(hash.keys).first).nil?
      raise GeneralError, "Unexpected dependency type. Must be one of #{dep_types}. Hash: #{hash}"
    end
    next [] unless match_platform?(hash[dep_type][-1], platform)
    pkg_name = hash[dep_type][1] if dep_type == "product"
    find_deps(hash[dep_type][0], pkg_name, dep_type)
  end
end

#direct_dependency_targets(platform: nil) ⇒ Object



115
116
117
# File 'lib/xccache/spm/desc/target.rb', line 115

def direct_dependency_targets(platform: nil)
  direct_dependencies(platform: platform).flat_map(&:flatten_as_targets).uniq
end

#downcastObject



24
25
26
27
28
29
30
# File 'lib/xccache/spm/desc/target.rb', line 24

def downcast
  cls = {
    :binary => BinaryTarget,
    :macro => MacroTarget,
  }[type]
  cls.nil? ? self : cast_to(cls)
end

#flatten_as_targetsObject



40
41
42
# File 'lib/xccache/spm/desc/target.rb', line 40

def flatten_as_targets
  [self]
end

#header_paths(options = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/xccache/spm/desc/target.rb', line 55

def header_paths(options = {})
  paths = []
  paths += public_header_paths if options.fetch(:public, true)
  paths += header_search_paths if options.fetch(:search, false)
  paths
    .flat_map { |p| p.glob("**/*.h*") }
    .map(&:realpath)
    .uniq
end

#header_search_pathsObject



69
70
71
72
73
74
75
# File 'lib/xccache/spm/desc/target.rb', line 69

def header_search_paths
  @header_search_paths ||=
    settings
    .filter_map { |h| h.fetch("kind", {})["headerSearchPath"] }
    .flat_map(&:values)
    .map { |p| sources_path / p }
end

#local_binary_pathObject



135
136
137
# File 'lib/xccache/spm/desc/target.rb', line 135

def local_binary_path
  binary_path if binary? && root.local?
end

#macro?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/xccache/spm/desc/target.rb', line 123

def macro?
  type == :macro
end

#match_platform?(_condition, _platform) ⇒ Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/xccache/spm/desc/target.rb', line 119

def match_platform?(_condition, _platform)
  true # FIXME: Handle this
end

#module_nameObject



32
33
34
# File 'lib/xccache/spm/desc/target.rb', line 32

def module_name
  name.c99extidentifier
end

#public_header_pathsObject



77
78
79
80
81
82
83
84
85
# File 'lib/xccache/spm/desc/target.rb', line 77

def public_header_paths
  @public_header_paths ||= begin
    res = []
    implicit_path = sources_path / "include"
    res << implicit_path unless implicit_path.glob("**/*.h*").empty?
    res << (sources_path / raw["publicHeadersPath"]) if raw.key?("publicHeadersPath")
    res
  end
end

#recursive_targets(platform: nil) ⇒ Object



97
98
99
100
101
# File 'lib/xccache/spm/desc/target.rb', line 97

def recursive_targets(platform: nil)
  children = direct_dependency_targets(platform: platform)
  children += children.flat_map { |t| t.macro? ? [t] : t.recursive_targets(platform: platform) }
  children.uniq
end

#resource_bundle_nameObject



36
37
38
# File 'lib/xccache/spm/desc/target.rb', line 36

def resource_bundle_name
  "#{pkg_name}_#{name}.bundle"
end

#resource_pathsObject



87
88
89
90
91
92
93
94
95
# File 'lib/xccache/spm/desc/target.rb', line 87

def resource_paths
  @resource_paths ||= begin
    res = raw.fetch("resources", []).map { |h| sources_path / h["path"] }
    # Refer to the following link for the implicit resources
    # https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package#Add-resource-files
    implicit = sources_path.glob("*.{xcassets,xib,storyboard,xcdatamodeld,lproj}")
    res + implicit
  end
end

#settingsObject



65
66
67
# File 'lib/xccache/spm/desc/target.rb', line 65

def settings
  raw["settings"]
end

#sources_pathObject



44
45
46
47
48
49
# File 'lib/xccache/spm/desc/target.rb', line 44

def sources_path
  @sources_path ||= begin
    path = raw["path"] || "Sources/#{name}"
    root.src_dir / path
  end
end

#typeObject



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

def type
  @type ||= raw["type"].to_sym
end

#use_clang?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/xccache/spm/desc/target.rb', line 51

def use_clang?
  !header_paths.empty?
end

#xccache?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/xccache/spm/desc/target.rb', line 12

def xccache?
  name.end_with?(".xccache")
end

#xccache_idObject



16
17
18
# File 'lib/xccache/spm/desc/target.rb', line 16

def xccache_id
  macro? ? "#{full_name}.macro" : full_name
end