Class: Pod::Installer::Xcode::ProjectGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/installer/xcode/pods_project_generator/project_generator.rb

Overview

Responsible for creating and preparing a Pod::Project instance

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sandbox, path, pod_targets, build_configurations, platforms, object_version, podfile_path = nil, pod_target_subproject: false) ⇒ ProjectGenerator

Initialize a new instance

Parameters:

  • sandbox (Sandbox)

    @see #sandbox

  • path (String)

    @see #path

  • pod_targets (Array<PodTarget>)

    @see #pod_targets

  • build_configurations (Hash{String=>Symbol})

    @see #build_configurations

  • platforms (Array<Platform>)

    @see #platforms

  • object_version (Integer)

    @see #object_version

  • podfile_path (String) (defaults to: nil)

    @see #podfile_path



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cocoapods/installer/xcode/pods_project_generator/project_generator.rb', line 56

def initialize(sandbox, path, pod_targets, build_configurations, platforms,
               object_version, podfile_path = nil, pod_target_subproject: false)
  @sandbox = sandbox
  @path = path
  @pod_targets = pod_targets
  @build_configurations = build_configurations
  @platforms = platforms
  @object_version = object_version
  @podfile_path = podfile_path
  @pod_target_subproject = pod_target_subproject
end

Instance Attribute Details

#build_configurationsHash{String=>Symbol} (readonly)

Returns A hash representing all the user build configurations across all integration targets. Each key corresponds to the name of a configuration and its value to its type (:debug or :release).

Returns:

  • (Hash{String=>Symbol})

    A hash representing all the user build configurations across all integration targets. Each key corresponds to the name of a configuration and its value to its type (:debug or :release).



27
28
29
# File 'lib/cocoapods/installer/xcode/pods_project_generator/project_generator.rb', line 27

def build_configurations
  @build_configurations
end

#object_versionInteger (readonly)

Returns Object version for the Xcode project.

Returns:

  • (Integer)

    Object version for the Xcode project.



35
36
37
# File 'lib/cocoapods/installer/xcode/pods_project_generator/project_generator.rb', line 35

def object_version
  @object_version
end

#pathString (readonly)

Returns path Path of the project.

Returns:

  • (String)

    path Path of the project.



15
16
17
# File 'lib/cocoapods/installer/xcode/pods_project_generator/project_generator.rb', line 15

def path
  @path
end

#platformsArray<Platform> (readonly)

Returns The list of all platforms this project supports.

Returns:

  • (Array<Platform>)

    The list of all platforms this project supports.



31
32
33
# File 'lib/cocoapods/installer/xcode/pods_project_generator/project_generator.rb', line 31

def platforms
  @platforms
end

#pod_target_subprojectBoolean (readonly)

Used by generate_multiple_pod_projects installation option.

Returns:

  • (Boolean)

    Bool indicating if this project is a pod target subproject.



44
45
46
# File 'lib/cocoapods/installer/xcode/pods_project_generator/project_generator.rb', line 44

def pod_target_subproject
  @pod_target_subproject
end

#pod_targetsArray<PodTarget> (readonly)

Returns pod_targets Array of pod targets this project includes.

Returns:

  • (Array<PodTarget>)

    pod_targets Array of pod targets this project includes.



20
21
22
# File 'lib/cocoapods/installer/xcode/pods_project_generator/project_generator.rb', line 20

def pod_targets
  @pod_targets
end

#podfile_pathString (readonly)

Returns Path to the Podfile included in the project.

Returns:

  • (String)

    Path to the Podfile included in the project.



39
40
41
# File 'lib/cocoapods/installer/xcode/pods_project_generator/project_generator.rb', line 39

def podfile_path
  @podfile_path
end

#sandboxSandbox (readonly)

Returns sandbox The Pods sandbox instance.

Returns:

  • (Sandbox)

    sandbox The Pods sandbox instance.



10
11
12
# File 'lib/cocoapods/installer/xcode/pods_project_generator/project_generator.rb', line 10

def sandbox
  @sandbox
end

Instance Method Details

#create_project(path, object_version, pod_target_subproject) ⇒ Object (private)



80
81
82
83
# File 'lib/cocoapods/installer/xcode/pods_project_generator/project_generator.rb', line 80

def create_project(path, object_version, pod_target_subproject)
  object_version ||= Xcodeproj::Constants::DEFAULT_OBJECT_VERSION
  Pod::Project.new(path, false, object_version, :pod_target_subproject => pod_target_subproject)
end

#generate!Project

Returns Generated and prepared project.

Returns:

  • (Project)

    Generated and prepared project.



72
73
74
75
76
# File 'lib/cocoapods/installer/xcode/pods_project_generator/project_generator.rb', line 72

def generate!
  project = create_project(path, object_version, pod_target_subproject)
  prepare(sandbox, project, pod_targets, build_configurations, platforms, podfile_path)
  project
end

#prepare(sandbox, project, pod_targets, build_configurations, platforms, podfile_path) ⇒ Object (private)



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/cocoapods/installer/xcode/pods_project_generator/project_generator.rb', line 85

def prepare(sandbox, project, pod_targets, build_configurations, platforms, podfile_path)
  UI.message "- Creating #{project.project_name} project" do
    build_configurations.each do |name, type|
      project.add_build_configuration(name, type)
    end
    # Reset symroot just in case the user has added a new build configuration other than 'Debug' or 'Release'.
    project.symroot = Pod::Project::LEGACY_BUILD_ROOT
    pod_names = pod_targets.map(&:pod_name).uniq
    pod_names.each do |pod_name|
      local = sandbox.local?(pod_name)
      path = sandbox.pod_dir(pod_name)
      was_absolute = sandbox.local_path_was_absolute?(pod_name)
      project.add_pod_group(pod_name, path, local, was_absolute)
    end
    if podfile_path
      project.add_podfile(podfile_path)
    end
    osx_deployment_target = platforms.select { |p| p.name == :osx }.map(&:deployment_target).min
    ios_deployment_target = platforms.select { |p| p.name == :ios }.map(&:deployment_target).min
    watchos_deployment_target = platforms.select { |p| p.name == :watchos }.map(&:deployment_target).min
    tvos_deployment_target = platforms.select { |p| p.name == :tvos }.map(&:deployment_target).min
    visionos_deployment_target = platforms.select { |p| p.name == :visionos }.map(&:deployment_target).min
    project.build_configurations.each do |build_configuration|
      build_configuration.build_settings['MACOSX_DEPLOYMENT_TARGET'] = osx_deployment_target.to_s if osx_deployment_target
      build_configuration.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = ios_deployment_target.to_s if ios_deployment_target
      build_configuration.build_settings['WATCHOS_DEPLOYMENT_TARGET'] = watchos_deployment_target.to_s if watchos_deployment_target
      build_configuration.build_settings['TVOS_DEPLOYMENT_TARGET'] = tvos_deployment_target.to_s if tvos_deployment_target
      build_configuration.build_settings['XROS_DEPLOYMENT_TARGET'] = visionos_deployment_target.to_s if visionos_deployment_target
      build_configuration.build_settings['STRIP_INSTALLED_PRODUCT'] = 'NO'
      build_configuration.build_settings['CLANG_ENABLE_OBJC_ARC'] = 'YES'
      build_configuration.build_settings['CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED'] = 'YES'
    end
  end
end