Class: Pod::Swift::PackageDescription::Target

Inherits:
Pod::Swift::PackageDescriptionBaseObject show all
Defined in:
lib/cocoapods-spm/swift/package/target.rb

Instance Attribute Summary

Attributes inherited from Pod::Swift::PackageDescriptionBaseObject

#parent, #raw

Instance Method Summary collapse

Methods inherited from Pod::Swift::PackageDescriptionBaseObject

#[], #dup_with_attrs, from_file, from_s, #initialize, #inspect, #name, #pkg_name, #root

Constructor Details

This class inherits a constructor from Pod::Swift::PackageDescriptionBaseObject

Instance Method Details

#binary?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/cocoapods-spm/swift/package/target.rb', line 17

def binary?
  return @binary unless @binary.nil?

  @binary = type == "binary"
end

#binary_basenameObject



81
82
83
84
85
86
87
88
# File 'lib/cocoapods-spm/swift/package/target.rb', line 81

def binary_basename
  return nil unless binary?

  @binary_basename ||= begin
    paths = (root.artifacts_dir / name).glob("*.xcframework/*/*.{a,framework}")
    paths[0].basename.to_s unless paths.empty?
  end
end

#built_framework_pathObject



77
78
79
# File 'lib/cocoapods-spm/swift/package/target.rb', line 77

def built_framework_path
  "${BUILT_PRODUCTS_DIR}/PackageFrameworks/#{framework_name}.framework"
end

#clang_modulemap_argObject



35
36
37
38
39
# File 'lib/cocoapods-spm/swift/package/target.rb', line 35

def clang_modulemap_arg
  return nil if public_headers_path.nil?

  "-fmodule-map-file=\"${GENERATED_MODULEMAP_DIR}/#{name}.modulemap\""
end

#dynamic?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/cocoapods-spm/swift/package/target.rb', line 23

def dynamic?
  @dynamic
end

#framework_nameObject



27
28
29
# File 'lib/cocoapods-spm/swift/package/target.rb', line 27

def framework_name
  @product_name || name
end

#linker_flagsObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cocoapods-spm/swift/package/target.rb', line 45

def linker_flags
  return ["-framework \"#{framework_name}\""] if dynamic?
  return ["-l\"#{name}.o\""] unless binary?

  case binary_basename
  when /(\S+)\.framework/ then ["-framework \"#{$1}\""]
  when /lib(\S+)\.a/ then ["-library \"#{$1}\""]
  when /(\S+\.a)/ then ["\"${PODS_CONFIGURATION_BUILD_DIR}/#{$1}\""]
  else []
  end
end

#macro?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/cocoapods-spm/swift/package/target.rb', line 13

def macro?
  type == "macro"
end

#public_headers_pathObject



31
32
33
# File 'lib/cocoapods-spm/swift/package/target.rb', line 31

def public_headers_path
  raw["publicHeadersPath"]
end

#resolve_dependencies(pkg_desc_cache) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/cocoapods-spm/swift/package/target.rb', line 57

def resolve_dependencies(pkg_desc_cache)
  raw.fetch("dependencies", []).flat_map do |hash|
    type = ["byName", "target", "product"].find { |k| hash.key?(k) }
    if type.nil?
      raise Informative, "Unexpected dependency type. Must be either `byName`, `target`, or `product`."
    end

    name = hash[type][0]
    pkg_name = hash.key?("product") ? hash["product"][1] : self.pkg_name
    pkg_desc = pkg_desc_cache[pkg_name]
    find_by_target = -> { pkg_desc.targets.select { |t| t.name == name } }
    find_by_product = -> { pkg_desc.targets_of_product(name) }
    next find_by_target.call if hash.key?("target")
    next find_by_product.call if hash.key?("product")

    # byName, could be either a target or a product
    next find_by_target.call || find_by_product.call
  end
end

#resourcesObject



41
42
43
# File 'lib/cocoapods-spm/swift/package/target.rb', line 41

def resources
  raw.fetch("resources", []).flat_map { |h| Resources.new(h, parent: self) }
end

#typeObject



9
10
11
# File 'lib/cocoapods-spm/swift/package/target.rb', line 9

def type
  raw["type"]
end

#use_default_xcode_linking?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/cocoapods-spm/swift/package/target.rb', line 90

def use_default_xcode_linking?
  root.use_default_xcode_linking?
end