Commit 0e2b2dd2 authored by Samuel E. Giddins's avatar Samuel E. Giddins Committed by Samuel Giddins

[Validator] Validate that apps can import the Pod

parent 4c7ce87f
...@@ -164,7 +164,7 @@ module Pod ...@@ -164,7 +164,7 @@ module Pod
validator.validate validator.validate
unless @clean unless @clean
UI.puts "Pods project available at `#{validator.validation_dir}/Pods/Pods.xcodeproj` for inspection." UI.puts "Pods workspace available at `#{validator.validation_dir}/App.xcworkspace` for inspection."
UI.puts UI.puts
end end
if validator.validated? if validator.validated?
......
...@@ -61,7 +61,7 @@ module Pod ...@@ -61,7 +61,7 @@ module Pod
failure_reasons << validator.failure_reason failure_reasons << validator.failure_reason
unless @clean unless @clean
UI.puts "Pods project available at `#{validator.validation_dir}/Pods/Pods.xcodeproj` for inspection." UI.puts "Pods workspace available at `#{validator.validation_dir}/App.xcworkspace` for inspection."
UI.puts UI.puts
end end
end end
......
...@@ -247,12 +247,12 @@ module Pod ...@@ -247,12 +247,12 @@ module Pod
if config.integrate_targets? if config.integrate_targets?
target_inspection = result.target_inspections[target_definition] target_inspection = result.target_inspections[target_definition]
target.user_project = target_inspection.project target.user_project = target_inspection.project
target.client_root = target.user_project_path.dirname target.client_root = target.user_project_path.dirname.realpath
target.user_target_uuids = target_inspection.project_target_uuids target.user_target_uuids = target_inspection.project_target_uuids
target.user_build_configurations = target_inspection.build_configurations target.user_build_configurations = target_inspection.build_configurations
target.archs = target_inspection.archs target.archs = target_inspection.archs
else else
target.client_root = config.installation_root target.client_root = config.installation_root.realpath
target.user_target_uuids = [] target.user_target_uuids = []
target.user_build_configurations = target_definition.build_configurations || { 'Release' => :release, 'Debug' => :debug } target.user_build_configurations = target_definition.build_configurations || { 'Release' => :release, 'Debug' => :debug }
if target_definition.platform && target_definition.platform.name == :osx if target_definition.platform && target_definition.platform.name == :osx
......
...@@ -257,17 +257,24 @@ module Pod ...@@ -257,17 +257,24 @@ module Pod
UI.message "\n\n#{spec} - Analyzing on #{platform} platform.".green.reversed UI.message "\n\n#{spec} - Analyzing on #{platform} platform.".green.reversed
@consumer = spec.consumer(platform) @consumer = spec.consumer(platform)
setup_validation_environment setup_validation_environment
download_pod begin
check_file_patterns create_app_project
install_pod download_pod
validate_vendored_dynamic_frameworks check_file_patterns
build_pod install_pod
tear_down_validation_environment add_app_project_import
validate_vendored_dynamic_frameworks
build_pod
ensure
tear_down_validation_environment
end
validated? validated?
end end
return false if fail_fast && !valid return false if fail_fast && !valid
perform_extensive_subspec_analysis(spec) unless @no_subspecs perform_extensive_subspec_analysis(spec) unless @no_subspecs
rescue => e rescue => e
message = e.to_s
message << "\n" << e.backtrace.join("\n") << "\n" if config.verbose?
error('unknown', "Encountered an unknown error (#{e}) during validation.") error('unknown', "Encountered an unknown error (#{e}) during validation.")
false false
end end
...@@ -339,11 +346,11 @@ module Pod ...@@ -339,11 +346,11 @@ module Pod
validation_dir.rmtree if validation_dir.exist? validation_dir.rmtree if validation_dir.exist?
validation_dir.mkpath validation_dir.mkpath
@original_config = Config.instance.clone @original_config = Config.instance.clone
config.installation_root = validation_dir config.installation_root = validation_dir
config.sandbox_root = validation_dir + 'Pods' config.silent = !config.verbose
config.silent = !config.verbose config.integrate_targets = true
config.integrate_targets = false config.skip_repo_update = true
config.skip_repo_update = true config.deterministic_uuids = false
end end
def tear_down_validation_environment def tear_down_validation_environment
...@@ -361,13 +368,44 @@ module Pod ...@@ -361,13 +368,44 @@ module Pod
@file_accessor = @installer.pod_targets.flat_map(&:file_accessors).find { |fa| fa.spec.name == consumer.spec.name } @file_accessor = @installer.pod_targets.flat_map(&:file_accessors).find { |fa| fa.spec.name == consumer.spec.name }
end end
def create_app_project
app_project = Xcodeproj::Project.new(validation_dir + 'App.xcodeproj')
deployment_target = spec.subspec_by_name(subspec_name).deployment_target(consumer.platform_name)
app_project.new_target(:application, 'App', consumer.platform_name, deployment_target)
app_project.save
app_project.recreate_user_schemes
Xcodeproj::XCScheme.share_scheme(app_project.path, 'App')
end
def add_app_project_import
app_project = Xcodeproj::Project.open(validation_dir + 'App.xcodeproj')
pod_target = @installer.pod_targets.find { |pt| pt.pod_name == spec.root.name }
language = pod_target.uses_swift? ? :swift : :objc
if language == :swift
source_file = validation_dir.+('App/main.swift')
source_file.parent.mkpath
import_statement = use_frameworks ? "import #{pod_target.product_module_name}\n" : ''
source_file.open('w') { |f| f << import_statement }
else
source_file = validation_dir.+('App/main.m')
source_file.parent.mkpath
import_statement = use_frameworks ? "@import #{pod_target.product_module_name};\n" : ''
source_file.open('w') { |f| f << "@import Foundation;\n#{import_statement}int main() {}\n" }
end
source_file_ref = app_project.new_group('App', 'App').new_file(source_file)
app_project.targets.first.add_file_references([source_file_ref])
app_project.save
end
# It creates a podfile in memory and builds a library containing the pod # It creates a podfile in memory and builds a library containing the pod
# for all available platforms with xcodebuild. # for all available platforms with xcodebuild.
# #
def install_pod def install_pod
%i(determine_dependency_product_types verify_no_duplicate_framework_names %i(determine_dependency_product_types verify_no_duplicate_framework_names
verify_no_static_framework_transitive_dependencies verify_no_static_framework_transitive_dependencies
verify_framework_usage generate_pods_project verify_framework_usage generate_pods_project integrate_user_project
perform_post_install_actions).each { |m| @installer.send(m) } perform_post_install_actions).each { |m| @installer.send(m) }
deployment_target = spec.subspec_by_name(subspec_name).deployment_target(consumer.platform_name) deployment_target = spec.subspec_by_name(subspec_name).deployment_target(consumer.platform_name)
...@@ -412,7 +450,7 @@ module Pod ...@@ -412,7 +450,7 @@ module Pod
UI.warn "Skipping compilation with `xcodebuild' because it can't be found.\n".yellow UI.warn "Skipping compilation with `xcodebuild' because it can't be found.\n".yellow
else else
UI.message "\nBuilding with xcodebuild.\n".yellow do UI.message "\nBuilding with xcodebuild.\n".yellow do
output = Dir.chdir(config.sandbox_root) { xcodebuild } output = xcodebuild
UI.puts output UI.puts output
parsed_output = parse_xcodebuild_output(output) parsed_output = parse_xcodebuild_output(output)
parsed_output.each do |message| parsed_output.each do |message|
...@@ -631,18 +669,17 @@ module Pod ...@@ -631,18 +669,17 @@ module Pod
# returns its output (both STDOUT and STDERR). # returns its output (both STDOUT and STDERR).
# #
def xcodebuild def xcodebuild
command = 'xcodebuild clean build -target Pods' command = %W(clean build -workspace App.xcworkspace -scheme App)
case consumer.platform_name case consumer.platform_name
when :ios when :ios
command << ' CODE_SIGN_IDENTITY=- -sdk iphonesimulator' command += %w(CODE_SIGN_IDENTITY=- -sdk iphonesimulator)
when :watchos when :watchos
command << ' CODE_SIGN_IDENTITY=- -sdk watchsimulator' command += %w(CODE_SIGN_IDENTITY=- -sdk watchsimulator)
when :tvos when :tvos
command << ' CODE_SIGN_IDENTITY=- -sdk appletvsimulator' command += %w(CODE_SIGN_IDENTITY=- -sdk appletvsimulator)
end end
output, status = _xcodebuild "#{command} 2>&1" output, status = Dir.chdir(validation_dir) { _xcodebuild(command) }
unless status.success? unless status.success?
message = 'Returned an unsuccessful exit code.' message = 'Returned an unsuccessful exit code.'
...@@ -659,9 +696,8 @@ module Pod ...@@ -659,9 +696,8 @@ module Pod
# resulting status. # resulting status.
# #
def _xcodebuild(command) def _xcodebuild(command)
UI.puts command if config.verbose UI.puts 'xcodebuild ' << command.join(' ') if config.verbose
output = `#{command}` Executable.capture_command('xcodebuild', command, capture: :merge)
[output, $?]
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
......
...@@ -404,11 +404,11 @@ module Pod ...@@ -404,11 +404,11 @@ module Pod
git = Executable.which(:git) git = Executable.which(:git)
Executable.stubs(:which).with('git').returns(git) Executable.stubs(:which).with('git').returns(git)
Executable.expects(:which).with('xcodebuild').times(4).returns('/usr/bin/xcodebuild') Executable.expects(:which).with('xcodebuild').times(4).returns('/usr/bin/xcodebuild')
command = 'xcodebuild clean build -target Pods' command = %w(clean build -workspace App.xcworkspace -scheme App)
validator.expects(:`).with("#{command} 2>&1").once.returns('') Executable.expects(:capture_command).with('xcodebuild', command, capture: :merge).once.returns(['', stub(:success? => true)])
validator.expects(:`).with("#{command} CODE_SIGN_IDENTITY=- -sdk appletvsimulator 2>&1").once.returns('') Executable.expects(:capture_command).with('xcodebuild', command + %w(CODE_SIGN_IDENTITY=- -sdk appletvsimulator), capture: :merge).once.returns(['', stub(:success? => true)])
validator.expects(:`).with("#{command} CODE_SIGN_IDENTITY=- -sdk iphonesimulator 2>&1").once.returns('') Executable.expects(:capture_command).with('xcodebuild', command + %w(CODE_SIGN_IDENTITY=- -sdk iphonesimulator), capture: :merge).once.returns(['', stub(:success? => true)])
validator.expects(:`).with("#{command} CODE_SIGN_IDENTITY=- -sdk watchsimulator 2>&1").once.returns('') Executable.expects(:capture_command).with('xcodebuild', command + %w(CODE_SIGN_IDENTITY=- -sdk watchsimulator), capture: :merge).once.returns(['', stub(:success? => true)])
validator.validate validator.validate
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment