Class: Pod::Installer::Analyzer::TargetInspector

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/installer/analyzer/target_inspector.rb

Constant Summary collapse

PLATFORM_INFO_URL =
'https://guides.cocoapods.org/syntax/podfile.html#platform'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_definition, installation_root) ⇒ TargetInspector

Initialize a new instance

Parameters:

  • target_definition (TargetDefinition)

    @see #target_definition

  • installation_root (Pathname)

    @see #installation_root


26
27
28
29
# File 'lib/cocoapods/installer/analyzer/target_inspector.rb', line 26

def initialize(target_definition, installation_root)
  @target_definition = target_definition
  @installation_root = installation_root
end

Instance Attribute Details

#installation_rootPathname (readonly)

Returns the root of the CocoaPods installation where the Podfile is located

Returns:

  • (Pathname)

    the root of the CocoaPods installation where the Podfile is located


16
17
18
# File 'lib/cocoapods/installer/analyzer/target_inspector.rb', line 16

def installation_root
  @installation_root
end

#target_definitionTargetDefinition (readonly)

Returns the target definition to inspect

Returns:

  • (TargetDefinition)

    the target definition to inspect


11
12
13
# File 'lib/cocoapods/installer/analyzer/target_inspector.rb', line 11

def target_definition
  @target_definition
end

Instance Method Details

#compute_project_pathPathname

Returns the path of the user project that the #target_definition should integrate.

Returns:

  • (Pathname)

    the path of the user project.

Raises:

  • If the project is implicit and there are multiple projects.

  • If the path doesn't exits.


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/cocoapods/installer/analyzer/target_inspector.rb', line 62

def compute_project_path
  if target_definition.user_project_path
    path = installation_root + target_definition.user_project_path
    path = "#{path}.xcodeproj" unless File.extname(path) == '.xcodeproj'
    path = Pathname.new(path)
    unless path.exist?
      raise Informative, 'Unable to find the Xcode project ' \
      "`#{path}` for the target `#{target_definition.label}`."
    end
  else
    xcodeprojs = installation_root.children.select { |e| e.fnmatch('*.xcodeproj') }
    if xcodeprojs.size == 1
      path = xcodeprojs.first
    else
      raise Informative, 'Could not automatically select an Xcode project. ' \
        "Specify one in your Podfile like so:\n\n" \
        "    project 'path/to/Project.xcodeproj'\n"
    end
  end
  path
end

#compute_results(user_project) ⇒ TargetInspectionResult

Inspect the #target_definition

Returns:

Raises:

  • If no `user_project` is set


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cocoapods/installer/analyzer/target_inspector.rb', line 37

def compute_results(user_project)
  raise ArgumentError, 'Cannot compute results without a user project set' unless user_project

  targets = compute_targets(user_project)
  project_target_uuids = targets.map(&:uuid)
  build_configurations = compute_build_configurations(targets)
  platform = compute_platform(targets)
  archs = compute_archs(targets)
  swift_version = compute_swift_version_from_targets(targets)

  result = TargetInspectionResult.new(target_definition, user_project, project_target_uuids,
                                      build_configurations, platform, archs)
  result.target_definition.swift_version = swift_version
  result
end