From d32ca304efd438c1d532c19995616deb0ad49487 Mon Sep 17 00:00:00 2001 From: Igor Makarov Date: Thu, 24 Feb 2022 15:50:18 +0200 Subject: [PATCH] Fix launch scheme params (#224) * update CakeMania demo to Swift 4.2 * add separate `.gitignore` for CakeMania example * bump `xcodeproj` minimum version to 1.7.0 * add launch target if launchable * make the framework example complete * disable annoying lint * fix tests + add test --- .gitignore | 4 ++- .rubocop.yml | 4 +-- example/app/CakeMania/.gitignore | 24 +++++++++++++ example/app/CakeMania/Cakefile | 2 +- example/app/CakeMania/Gemfile | 5 +++ example/app/CakeMania/Src/AppDelegate.swift | 2 +- example/framework/.gitignore | 24 +++++++++++++ example/framework/Cakefile | 2 +- example/framework/Gemfile | 5 +++ example/framework/Info/CakeFamework.plist | 38 ++++++++++++++++++++ example/framework/Info/CakeFameworkTst.plist | 22 ++++++++++++ example/framework/Src/FrameworkSource.swift | 0 example/framework/Tst/Main.swift | 36 +++++++++++++++++++ lib/xcake/generator/scheme_generator.rb | 2 +- spec/generator/scheme_generator_spec.rb | 19 +++++++--- xcake.gemspec | 2 +- 16 files changed, 177 insertions(+), 14 deletions(-) create mode 100644 example/app/CakeMania/.gitignore create mode 100644 example/app/CakeMania/Gemfile create mode 100644 example/framework/.gitignore create mode 100644 example/framework/Gemfile create mode 100644 example/framework/Info/CakeFamework.plist create mode 100644 example/framework/Info/CakeFameworkTst.plist create mode 100644 example/framework/Src/FrameworkSource.swift create mode 100644 example/framework/Tst/Main.swift diff --git a/.gitignore b/.gitignore index a1eb8c25..a5db346c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ -Gemfile*.lock +/Gemfile*.lock +/gemfiles/Gemfile*.lock + *.gem *.rbc /.config diff --git a/.rubocop.yml b/.rubocop.yml index a35d1fc8..af06b084 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -22,9 +22,7 @@ Metrics/ModuleLength: - 'spec/**/*' Metrics/AbcSize: - Max: 30 - Exclude: - - 'lib/xcake/ui.rb' + Enabled: false Metrics/LineLength: Max: 130 diff --git a/example/app/CakeMania/.gitignore b/example/app/CakeMania/.gitignore new file mode 100644 index 00000000..1ab3cfe5 --- /dev/null +++ b/example/app/CakeMania/.gitignore @@ -0,0 +1,24 @@ +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +*.xcscmblueprint +.DS_Store + +Gemfile.lock + +*.xcodeproj \ No newline at end of file diff --git a/example/app/CakeMania/Cakefile b/example/app/CakeMania/Cakefile index 91a2efa5..c16452e0 100644 --- a/example/app/CakeMania/Cakefile +++ b/example/app/CakeMania/Cakefile @@ -8,7 +8,7 @@ # just helper variables to use these values in a consistent way across whole file iOSdeploymentTarget = "8.0" -currentSwiftVersion = "3.0.1" # to set "Use Legacy Swift ..." to "No" +currentSwiftVersion = "4.2" companyIdentifier = "com.CakeMania" developmentTeamId = "XYZXYZ" # for automatic debug signing in Xcode 8 testSuffix = "Tst" diff --git a/example/app/CakeMania/Gemfile b/example/app/CakeMania/Gemfile new file mode 100644 index 00000000..b0fba7f0 --- /dev/null +++ b/example/app/CakeMania/Gemfile @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gemspec path: `git rev-parse --show-toplevel`.chomp diff --git a/example/app/CakeMania/Src/AppDelegate.swift b/example/app/CakeMania/Src/AppDelegate.swift index 09d91022..abb01026 100644 --- a/example/app/CakeMania/Src/AppDelegate.swift +++ b/example/app/CakeMania/Src/AppDelegate.swift @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } diff --git a/example/framework/.gitignore b/example/framework/.gitignore new file mode 100644 index 00000000..1ab3cfe5 --- /dev/null +++ b/example/framework/.gitignore @@ -0,0 +1,24 @@ +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +*.xcscmblueprint +.DS_Store + +Gemfile.lock + +*.xcodeproj \ No newline at end of file diff --git a/example/framework/Cakefile b/example/framework/Cakefile index 1057b754..bc36e5ce 100644 --- a/example/framework/Cakefile +++ b/example/framework/Cakefile @@ -2,7 +2,7 @@ # http://www.rubydoc.info/github/jcampbell05/xcake/master/file/docs/Cakefile.md iOSdeploymentTarget = "8.0" -currentSwiftVersion = "3.0.1" # to set "Use Legacy Swift ..." to "No" +currentSwiftVersion = "4.2" companyIdentifier = "com.CakeMania" developmentTeamId = "XYZXYZ" # for automatic debug signing in Xcode 8 testSuffix = "Tst" diff --git a/example/framework/Gemfile b/example/framework/Gemfile new file mode 100644 index 00000000..b0fba7f0 --- /dev/null +++ b/example/framework/Gemfile @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gemspec path: `git rev-parse --show-toplevel`.chomp diff --git a/example/framework/Info/CakeFamework.plist b/example/framework/Info/CakeFamework.plist new file mode 100644 index 00000000..38e98af2 --- /dev/null +++ b/example/framework/Info/CakeFamework.plist @@ -0,0 +1,38 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/example/framework/Info/CakeFameworkTst.plist b/example/framework/Info/CakeFameworkTst.plist new file mode 100644 index 00000000..6c6c23c4 --- /dev/null +++ b/example/framework/Info/CakeFameworkTst.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/example/framework/Src/FrameworkSource.swift b/example/framework/Src/FrameworkSource.swift new file mode 100644 index 00000000..e69de29b diff --git a/example/framework/Tst/Main.swift b/example/framework/Tst/Main.swift new file mode 100644 index 00000000..740d30aa --- /dev/null +++ b/example/framework/Tst/Main.swift @@ -0,0 +1,36 @@ +// +// CakeManiaTests.swift +// CakeManiaTests +// +// Created by Maxim Khatskevich on 11/25/16. +// Copyright © 2016 CakeMania Inc. All rights reserved. +// + +import XCTest +@testable import CakeFamework + +class CakeManiaTests: XCTestCase { + + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testExample() { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testPerformanceExample() { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/lib/xcake/generator/scheme_generator.rb b/lib/xcake/generator/scheme_generator.rb index c1944fda..9e8d1e94 100644 --- a/lib/xcake/generator/scheme_generator.rb +++ b/lib/xcake/generator/scheme_generator.rb @@ -19,7 +19,7 @@ def visit_target(target) native_scheme = @context.native_object_for(scheme) native_scheme.name = scheme.name - native_scheme.configure_with_targets(native_target, nil) + native_scheme.configure_with_targets(native_target, nil, launch_target: native_target.launchable_target_type?) native_project = @context.native_object_for(@project) native_unit_test_target = native_project.find_unit_test_target_for_target(target) diff --git a/spec/generator/scheme_generator_spec.rb b/spec/generator/scheme_generator_spec.rb index fa041a99..c96d2632 100644 --- a/spec/generator/scheme_generator_spec.rb +++ b/spec/generator/scheme_generator_spec.rb @@ -25,6 +25,7 @@ module Xcake allow(@native_project).to receive(:find_unit_test_target_for_target).and_return(@native_unit_test_target) allow(@native_project).to receive(:find_ui_test_target_for_target).and_return(@native_ui_test_target) + allow(@native_target).to receive(:launchable_target_type?).and_return(false) allow(@context).to receive(:native_object_for).with(@target).and_return(@native_target) allow(@context).to receive(:native_object_for).with(@project).and_return(@native_project) allow(@context).to receive(:native_object_for).with(@scheme).and_return(@native_scheme) @@ -51,12 +52,20 @@ module Xcake end context 'when configuring native scheme' do - it 'should configure with build target' do - allow(@native_project).to receive(:find_unit_test_target_for_target).and_return(nil) - allow(@native_project).to receive(:find_ui_test_target_for_target).and_return(nil) + context 'should configure with build target' do + it 'should configure as launch target if launchable' do + allow(@native_target).to receive(:launchable_target_type?).and_return(true) - expect(@native_scheme).to receive(:configure_with_targets).with(@native_target, nil) - @generator.visit_target(@target) + expect(@native_scheme).to receive(:configure_with_targets).with(@native_target, nil, launch_target: true) + @generator.visit_target(@target) + end + + it 'should not configure as launch target if not launchable' do + allow(@native_target).to receive(:launchable_target_type?).and_return(false) + + expect(@native_scheme).to receive(:configure_with_targets).with(@native_target, nil, launch_target: false) + @generator.visit_target(@target) + end end it 'should configure with test action' do diff --git a/xcake.gemspec b/xcake.gemspec index 64ca4e0b..cfd26a34 100644 --- a/xcake.gemspec +++ b/xcake.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength spec.add_runtime_dependency 'cork' spec.add_runtime_dependency 'deep_merge' spec.add_runtime_dependency 'hooks', '~> 0.4.1' - spec.add_runtime_dependency 'xcodeproj', '< 2.0.0', '>= 1.3.0' + spec.add_runtime_dependency 'xcodeproj', '< 2.0.0', '>= 1.7.0' spec.add_development_dependency 'bundler', '>= 1.10' spec.add_development_dependency 'os', '~> 1.0'