8000 Allow app specs to be used to upload to the app store by segiddins · Pull Request #8275 · CocoaPods/CocoaPods · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Allow app specs to be used to upload to the app store #8275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,36 @@ def install!

private

# Adds the target for the library to the Pods project with the
# appropriate build configurations.
#
# @note Overrides the superclass implementation to remove settings that are set in the pod target xcconfig
#
# @return [PBXNativeTarget] the native target that was added.
#
def add_target
super.tap do |native_target|
remove_pod_target_xcconfig_overrides_from_target(target.build_settings, native_target)
end
end

# Removes overrides of the `pod_target_xcconfig` settings from the target's
# build configurations.
#
# @return [Void]
#
# @param [Target::BuildSettings] build_settings
#
# @param [PBXNativeTarget] native_target
#
def remove_pod_target_xcconfig_overrides_from_target(build_settings, native_target)
native_target.build_configurations.each do |configuration|
build_settings.merged_pod_target_xcconfigs.each_key do |setting|
configuration.build_settings.delete(setting)
end
end
end

# @param [Array<Specification>] specs
# the specs to check against whether `.pch` generation should be skipped or not.
#
Expand Down Expand Up @@ -327,6 +357,8 @@ def add_test_targets
configuration.build_settings['CODE_SIGN_IDENTITY'] = '' if target.platform == :osx
end

remove_pod_target_xcconfig_overrides_from_target(target.build_settings_for_spec(test_spec), test_native_target)

# Test native targets also need frameworks and resources to be copied over to their xctest bundle.
create_test_target_embed_frameworks_script(test_spec)
create_test_target_copy_resources_script(test_spec)
Expand Down Expand Up @@ -385,6 +417,7 @@ def add_app_targets
app_native_target = AppHostInstaller.new(sandbox, project, platform, subspec_name, spec_name,
app_target_label, :add_main => false).install!

app_native_target.product_reference.name = app_target_label
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if this could move into AppHostInstaller but meh.

Copy link
Member
@amorde amorde Feb 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like it should be in AppHostInstaller

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just mirroring the way we do it for test specs

target.user_build_configurations.each do |bc_name, type|
app_native_target.add_build_configuration(bc_name, type)
end
Expand Down Expand Up @@ -416,13 +449,33 @@ def add_app_targets
configuration.build_settings['CODE_SIGN_IDENTITY'] = '' if target.platform == :osx
end

remove_pod_target_xcconfig_overrides_from_target(target.build_settings_for_spec(app_spec), app_native_target)

create_app_target_embed_frameworks_script(app_spec)
create_app_target_copy_resources_script(app_spec)
add_resources_to_target(target.file_accessors.find { |fa| fa.spec == app_spec }.resources, app_native_target)

app_native_target
end
end

# Adds the resources to the compile resources phase of the target.
#
# @param [Array<Pathname>] paths the paths to add to the target.
#
# @param [PBXNativeTarget] target the target resources are added to.
#
# @return [Boolean] whether any compile phase references were added.
#
def add_resources_to_target(paths, target)
filter_resource_file_references(paths) do |compile_phase_refs, resource_phase_refs|
# Resource bundles are only meant to have resources, so install everything
# into the resources phase. See note in filter_resource_file_references.
target.add_resources(resource_phase_refs + compile_phase_refs)
!compile_phase_refs.empty?
end
end

# Adds the resources of the Pods to the Pods project.
#
# @note The source files are grouped by Pod and in turn by subspec
Expand All @@ -431,7 +484,7 @@ def add_app_targets
# @param [Array<Sandbox::FileAccessor>] file_accessors
# the file accessors list to generate resource bundles for.
#
# @return [Array<PBXNativeTarget] the resource bundle native targets created.
# @return [Array<PBXNativeTarget>] the resource bundle native targets created.
Copy link
Contributor
@dnkoutso dnkoutso Feb 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was actually wrong. It should be Hash{String => Array<PBXNativeTarget>}]

#
def add_resources_bundle_targets(file_accessors)
file_accessors.each_with_object({}) do |file_accessor, hash|
Expand All @@ -443,13 +496,7 @@ def add_resources_bundle_targets(file_accessors)
bundle_product.name = bundle_file_name
end

contains_compile_phase_refs = false
filter_resource_file_references(paths) do |compile_phase_refs, resource_phase_refs|
# Resource bundles are only meant to have resources, so install everything
# into the resources phase. See note in filter_resource_file_references.
resource_bundle_target.add_resources(compile_phase_refs + resource_phase_refs)
contains_compile_phase_refs = !compile_phase_refs.empty?
end
contains_compile_phase_refs = add_resources_to_target(paths, resource_bundle_target)

target.user_build_configurations.each do |bc_name, type|
resource_bundle_target.add_build_configuration(bc_name, type)
Expand All @@ -473,7 +520,7 @@ def add_resources_bundle_targets(file_accessors)

# Set the `SWIFT_VERSION` build setting for resource bundles that could have resources that get
# compiled such as an `xcdatamodeld` file which has 'Swift' as its code generation language.
if contains_compile_phase_refs && target.uses_swift?
if contains_compile_phase_refs && file_accessors.any? { |fa| target.uses_swift_for_spec?(fa.spec) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this be any target and not the spec of the file_accessor we are looping in? Isnt that where the resource bundle is under?

Alternatively I was under the impression from our offline chat that we would always set this without caring whether Swift is needed or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this be any target and not the spec of the file_accessor we are looping in? Isnt that where the resource bundle is under?

I changed it to do just that

Alternatively I was under the impression from our offline chat that we would always set this without caring whether Swift is needed or not.

Decided not to change that here, on the off chance it would accidentally break something

configuration.build_settings['SWIFT_VERSION'] = target.swift_version
end

Expand All @@ -489,6 +536,8 @@ def add_resources_bundle_targets(file_accessors)
end
end

remove_pod_target_xcconfig_overrides_from_target(target.build_settings_for_spec(file_accessor.spec), resource_bundle_target)

resource_bundle_target
end
end
Expand Down Expand Up @@ -528,19 +577,18 @@ def create_test_xcconfig_files(test_native_targets, test_resource_bundle_targets
spec_consumer = test_spec.consumer(target.platform)
test_type = spec_consumer.test_type
path = target.xcconfig_path("#{test_type.capitalize}-#{target.subspec_label(test_spec)}")
test_spec_build_settings = target.test_spec_build_settings[test_spec.name]
test_spec_build_settings = target.build_settings_for_spec(test_spec)
update_changed_file(test_spec_build_settings, path)
test_xcconfig_file_ref = add_file_to_support_group(path)

test_native_target = test_native_target_from_spec(spec_consumer.spec, test_native_targets)
test_native_target.build_configurations.each do |test_native_target_bc|
test_target_swift_debug_hack(test_spec, test_native_target_bc)
test_native_target_bc.base_configuration_reference = test_xcconfig_file_ref
end

# also apply the private config to resource bundle test targets related to this test spec.
scoped_test_resource_bundle_targets = test_resource_bundle_targets[test_spec.name]
apply_xcconfig_file_ref_to_targets(scoped_test_resource_bundle_targets, test_xcconfig_file_ref)
apply_xcconfig_file_ref_to_targets([test_native_target] + scoped_test_resource_bundle_targets, test_xcconfig_file_ref)
end
end

Expand Down Expand Up @@ -602,7 +650,7 @@ def create_app_xcconfig_files(app_native_targets, app_resource_bundle_targets)
target.app_specs.each do |app_spec|
spec_consumer = app_spec.consumer(target.platform)
path = target.xcconfig_path(target.subspec_label(app_spec))
update_changed_file(Target::BuildSettings::PodTargetSettings.new(target, app_spec), path)
update_changed_file(target.build_settings_for_spec(app_spec), path)
app_xcconfig_file_ref = add_file_to_support_group(path)

app_native_target = app_native_target_from_spec(spec_consumer.spec, app_native_targets)
Expand Down
24 changes: 22 additions & 2 deletions lib/cocoapods/target/build_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ class BuildSettings
GCC_PREPROCESSOR_DEFINITIONS
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS
HEADER_SEARCH_PATHS
INCLUDED_SOURCE_FILE_NAMES
INFOPLIST_PREPROCESSOR_DEFINITIONS
LD_RUNPATH_SEARCH_PATHS
LIBRARY_SEARCH_PATHS
LOCALIZED_STRING_MACRO_NAMES
OTHER_CFLAGS
OTHER_CPLUSPLUSFLAGS
OTHER_LDFLAGS
Expand All @@ -31,6 +33,8 @@ class BuildSettings
SECTORDER_FLAGS
SWIFT_ACTIVE_COMPILATION_CONDITIONS
SWIFT_INCLUDE_PATHS
SYSTEM_FRAMEWORK_SEARCH_PATHS
SYSTEM_HEADER_SEARCH_PATHS
USER_HEADER_SEARCH_PATHS
WARNING_CFLAGS
WARNING_LDFLAGS
Expand Down Expand Up @@ -425,6 +429,22 @@ def merged_xcconfigs(xcconfig_values_by_consumer_by_key, attribute)
end
end

# Merges the spec-defined xcconfig into the derived xcconfig,
# overriding any singular settings and merging plural settings.
#
# @param [Hash<String,String>] spec_xcconfig_hash the merged xcconfig defined in the spec.
#
# @param [Xcodeproj::Config] xcconfig the config to merge into.
#
# @return [Xcodeproj::Config] the merged config.
#
def merge_spec_xcconfig_into_xcconfig(spec_xcconfig_hash, xcconfig)
plural_configs, singlular_configs = spec_xcconfig_hash.partition { |k, _v| PLURAL_SETTINGS.include?(k) }.map { |a| Hash[a] }
xcconfig.attributes.merge!(singlular_configs)
xcconfig.merge!(plural_configs)
xcconfig
end

# Filters out pod targets whose `specs` are a subset of
# another target's.
#
Expand Down Expand Up @@ -503,7 +523,7 @@ def initialize(target, non_library_spec = nil)
# @return [Xcodeproj::Xconfig]
define_build_settings_method :xcconfig, :memoized => true do
xcconfig = super()
xcconfig.merge(merged_pod_target_xcconfigs)
merge_spec_xcconfig_into_xcconfig(merged_pod_target_xcconfigs, xcconfig)
end

#-------------------------------------------------------------------------#
Expand Down Expand Up @@ -911,7 +931,7 @@ def initialize(target, configuration_name)
# @return [Xcodeproj::Config] xcconfig
define_build_settings_method :xcconfig, :memoized => true do
xcconfig = super()
xcconfig.merge(merged_user_target_xcconfigs)
merge_spec_xcconfig_into_xcconfig(merged_user_target_xcconfigs, xcconfig)
end

#-------------------------------------------------------------------------#
Expand Down
13 changes: 13 additions & 0 deletions lib/cocoapods/target/pod_target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ def resource_paths
@resource_paths ||= begin
file_accessors.each_with_object({}) do |file_accessor, hash|
resource_paths = file_accessor.resources.map { |res| "${PODS_ROOT}/#{res.relative_path_from(sandbox.project_path.dirname)}" }
resource_paths = [] if file_accessor.spec.app_specification?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why wouldn't we want the resource paths of app specifications?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because they now get added directly to the app target, rather than being integrated via the copy resources script

prefix = Pod::Target::BuildSettings::CONFIGURATION_BUILD_DIR_VARIABLE
prefix = configuration_build_dir unless file_accessor.spec.test_specification?
resource_bundle_paths = file_accessor.resource_bundles.keys.map { |name| "#{prefix}/#{name.shellescape}.bundle" }
Expand Down Expand Up @@ -719,6 +720,18 @@ def header_search_paths(include_dependent_targets_for_test_spec: nil, include_de
header_search_paths.uniq
end

# @param [Specification] spec
#
# @return [BuildSettings::PodTargetSettings] The build settings for the given spec
#
def build_settings_for_spec(spec)
case spec.spec_type
when :test then test_spec_build_settings[spec.name]
when :app then app_spec_build_settings[spec.name]
else build_settings
end || raise(ArgumentError, "No build settings for #{spec}")
end

protected

# Returns whether the pod target should use modular headers.
Expand Down
Empty file.
Empty file.
56 changes: 53 additions & 3 deletions spec/fixtures/watermelon-lib/WatermelonLib.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Pod::Spec.new do |s|
s.source = { :git => 'http://watermelon-corp.local/coconut-lib.git', :tag => 'v1.0' }
s.license = {
:type => 'MIT',
:text => 'Permission is hereby granted ...'
:text => 'Permission is hereby granted ...',
}

s.ios.deployment_target = '9.0'
s.osx.deployment_target = '10.11'

s.source_files = 'Classes/*.{h,m}'
s.source_files = 'Classes/*.{h,m}'

s.test_spec do |test_spec|
test_spec.source_files = 'Tests/*.{h,m,swift}'
Expand All @@ -27,4 +27,54 @@ Pod::Spec.new do |s|
test_spec.source_files = 'SnapshotTests/*.{h,m}'
test_spec.dependency 'iOSSnapshotTestCase/Core'
end

s.app_spec do |app_spec|
app_spec.source_files = 'App/*.swift'
app_spec.resources = 'App/*.txt'
app_spec.resource_bundle = { 'WatermelonLibExampleAppResources' => ['Tests/Resources/**/*'] }

app_spec.pod_target_xcconfig = {
'PRODUCT_NAME' => 'ExampleApp',
'PRODUCT_SHORT_NAME' => 'ExampleApp',

'INFOPLIST_FILE' => '${PODS_TARGET_SRCROOT}/App/App-Info.plist',

'PRODUCT_BUNDLE_IDENTIFIER_Debug' => 'org.cocoapods.example.development',
'PRODUCT_BUNDLE_IDENTIFIER_Release' => 'org.cocoapods.example',
'PRODUCT_BUNDLE_IDENTIFIER' => '$(PRODUCT_BUNDLE_IDENTIFIER_$(CONFIGURATION))',

'TARGETED_DEVICE_FAMILY' => '1', # iPhone-only
'IPHONEOS_DEPLOYMENT_TARGET' => s.deployment_target(:ios),
'SKIP_INSTALL' => 'NO',
'ENABLE_BITCODE' => 'NO',
'PRODUCT_MODULE_NAME' => 'ExampleAppSpec',

'ASSETCATALOG_COMPILER_APPICON_NAME_Debug' => 'AppIcon-Debug',
'ASSETCATALOG_COMPILER_APPICON_NAME_Release' => 'AppIcon',
'ASSETCATALOG_COMPILER_APPICON_NAME' => '$(ASSETCATALOG_COMPILER_APPICON_NAME_$(CONFIGURATION))',

'COPY_PHASE_STRIP_Debug' => 'NO',
'COPY_PHASE_STRIP_Release' => 'YES',
'COPY_PHASE_STRIP' => '$(COPY_PHASE_STRIP_$(CONFIGURATION))',

'STRIP_INSTALLED_PRODUCT_Debug' => 'NO',
'STRIP_INSTALLED_PRODUCT_Release' => 'YES',
'STRIP_INSTALLED_PRODUCT' => '$(STRIP_INSTALLED_PRODUCT_$(CONFIGURATION))',

'ENABLE_TESTABILITY_Debug' => 'YES',
'ENABLE_TESTABILITY_Release' => 'NO',
'ENABLE_TESTABILITY' => '$(ENABLE_TESTABILITY_$(CONFIGURATION))',

'SWIFT_OPTIMIZATION_LEVEL_Debug' => '-Onone',
'SWIFT_OPTIMIZATION_LEVEL_Release' => '-Owholemodule',
'SWIFT_OPTIMIZATION_LEVEL' => '$(SWIFT_OPTIMIZATION_LEVEL_$(CONFIGURATION))',

'CODE_SIGN_IDENTITY' => '$(ORG_PODS_CODE_SIGN_IDENTITY)',
'CODE_SIGN_IDENTITY[sdk=iphoneos*]' => '$(ORG_PODS_CODE_SIGN_IDENTITY)',
'PROVISIONING_PROFILE_SPECIFIER' => '$(ORG_PODS_PROVISIONING_PROFILE_SPECIFIER)',
'DEVELOPMENT_TEAM' => '$(ORG_PODS_DEVELOPMENT_TEAM)',
}

app_spec.script_phase = { :name => 'Run Script', :script => 'set -eux; "${PODS_TARGET_SRCROOT}/Scripts/script.rb"', :shell_path => '/bin/sh' }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,16 @@ class Xcode
'AppHost-WatermelonLib-iOS-Unit-Tests',
'AppHost-WatermelonLib-macOS-Unit-Tests',
'WatermelonLib-iOS',
'WatermelonLib-iOS-App',
'WatermelonLib-iOS-Unit-SnapshotTests',
'WatermelonLib-iOS-Unit-Tests',
'WatermelonLib-iOS-WatermelonLibExampleAppResources',
'WatermelonLib-iOS-WatermelonLibTestResources',
'WatermelonLib-macOS',
'WatermelonLib-macOS-App',
'WatermelonLib-macOS-Unit-SnapshotTests',
'WatermelonLib-macOS-Unit-Tests',
'WatermelonLib-macOS-WatermelonLibExampleAppResources',
'WatermelonLib-macOS-WatermelonLibTestResources',
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ class PodsProjectGenerator
describe '#file_accessors' do
it 'returns the file accessors' do
pod_target_1 = PodTarget.new(config.sandbox, false, {}, [], Platform.ios,
[stub('Spec', :test_specification? => false, :library_specification? => true, :app_specification? => false, :spec_type => :library)],
[stub('Spec', :test_specification? => false, :library_specification? => true, :non_library_specification? => false, :app_specification? => false, :spec_type => :library)],
[fixture_target_definition],
[fixture_file_accessor('banana-lib/BananaLib.podspec')])
pod_target_2 = PodTarget.new(config.sandbox, false, {}, [], Platform.ios,
[stub('Spec', :test_specification? => false, :library_specification? => true, :app_specification? => false, :spec_type => :library)],
[stub('Spec', :test_specification? => false, :library_specification? => true, :non_library_specification? => false, :app_specification? => false, :spec_type => :library)],
[fixture_target_definition],
[fixture_file_accessor('banana-lib/BananaLib.podspec')])
installer = FileReferencesInstaller.new(config.sandbox, [pod_target_1, pod_target_2], @project)
Expand All @@ -217,7 +217,9 @@ class PodsProjectGenerator
end

it 'handles pods without file accessors' do
pod_target_1 = PodTarget.new(config.sandbox, false, {}, [], Platform.ios, [stub('Spec', :test_specification? => false, :library_specification? => true, :app_specification? => false, :spec_type => :library)], [fixture_target_definition], [])
pod_target_1 = PodTarget.new(config.sandbox, false, {}, [], Platform.ios,
[stub('Spec', :test_specification? => false, :library_specification? => true, :non_library_specification? => false, :app_specification? => false, :spec_type => :library)],
[fixture_target_definition], [])
installer = FileReferencesInstaller.new(config.sandbox, [pod_target_1], @project)
installer.send(:file_accessors).should == []
end
Expand Down
Loading
0