From 3468be59827406f7babb06258d709b484d4839c7 Mon Sep 17 00:00:00 2001 From: Rafael Lecina Date: Tue, 7 Jul 2020 08:32:51 +0200 Subject: [PATCH 1/3] Add support for .swift file extension on xcode_common.lua Add support for setting swiftversion --- modules/xcode/xcode_common.lua | 22 +++++++++++++++++----- src/_premake_init.lua | 11 +++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/modules/xcode/xcode_common.lua b/modules/xcode/xcode_common.lua index 481afb32a4..518831a817 100644 --- a/modules/xcode/xcode_common.lua +++ b/modules/xcode/xcode_common.lua @@ -41,6 +41,7 @@ [".icns"] = "Resources", [".s"] = "Sources", [".S"] = "Sources", + [".swift"] = "Sources", } if node.isResource then return "Resources" @@ -140,7 +141,7 @@ [".bmp"] = "image.bmp", [".wav"] = "audio.wav", [".xcassets"] = "folder.assetcatalog", - + [".swift"] = "sourcecode.swift", } return types[path.getextension(node.path)] or "text" end @@ -218,9 +219,9 @@ value(level, name) elseif type(value) ~= 'table' then _p(level, '%s = %s;', stringifySetting(name), stringifySetting(value)) - --elseif #value == 1 then - --_p(level, '%s = %s;', stringifySetting(name), stringifySetting(value[1])) - elseif #value >= 1 then + elseif #value == 1 then + _p(level, '%s = %s;', stringifySetting(name), stringifySetting(value[1])) + elseif #value > 1 then _p(level, '%s = (', stringifySetting(name)) for _, item in ipairs(value) do _p(level + 1, '%s,', stringifySetting(item)) @@ -1292,7 +1293,16 @@ end end - + function xcode.XCBuildConfiguration_SwiftLanguageVersion(settings, cfg) + -- if no swiftversion is provided, don't set swift version + -- Projects with swift files but without swift version will refuse + -- to build on Xcode but setting a default SWIFT_VERSION may have + -- unexpected interactions with other systems like cocoapods + if cfg.swiftversion then + settings['SWIFT_VERSION'] = cfg.swiftversion + end + end + function xcode.XCBuildConfiguration_Project(tr, cfg) local settings = {} @@ -1460,6 +1470,8 @@ settings['WARNING_CFLAGS'] = '-Weverything' end + xcode.XCBuildConfiguration_SwiftLanguageVersion(settings, cfg) + overrideSettings(settings, cfg.xcodebuildsettings) _p(2,'%s /* %s */ = {', cfg.xcode.projectid, cfg.buildcfg) diff --git a/src/_premake_init.lua b/src/_premake_init.lua index 37496e60b9..e8221a677f 100644 --- a/src/_premake_init.lua +++ b/src/_premake_init.lua @@ -782,6 +782,17 @@ } } + api.register { + name = "swiftversion", + scope = "config", + kind = "string", + allowed = { + "4.0", + "4.2", + "5.0", + } + } + api.register { name = "libdirs", scope = "config", From 5dfb248a535cc308cc5667091394ee0e9607edb3 Mon Sep 17 00:00:00 2001 From: Rafael Lecina Date: Thu, 30 Jul 2020 22:41:33 +0200 Subject: [PATCH 2/3] Revert change to use single value settings specific format for xcode --- modules/xcode/xcode_common.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/xcode/xcode_common.lua b/modules/xcode/xcode_common.lua index 518831a817..4c65c16e4f 100644 --- a/modules/xcode/xcode_common.lua +++ b/modules/xcode/xcode_common.lua @@ -219,9 +219,9 @@ value(level, name) elseif type(value) ~= 'table' then _p(level, '%s = %s;', stringifySetting(name), stringifySetting(value)) - elseif #value == 1 then - _p(level, '%s = %s;', stringifySetting(name), stringifySetting(value[1])) - elseif #value > 1 then + --elseif #value == 1 then + --_p(level, '%s = %s;', stringifySetting(name), stringifySetting(value[1])) + elseif #value >= 1 then _p(level, '%s = (', stringifySetting(name)) for _, item in ipairs(value) do _p(level + 1, '%s,', stringifySetting(item)) From 8a37c0507521569c1bfa86a36bc288a025a65b33 Mon Sep 17 00:00:00 2001 From: Rafael Lecina Date: Thu, 6 Aug 2020 01:07:08 +0200 Subject: [PATCH 3/3] Add swift tests --- modules/xcode/tests/test_xcode_project.lua | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/modules/xcode/tests/test_xcode_project.lua b/modules/xcode/tests/test_xcode_project.lua index a1358f6cf2..97a1ed856c 100644 --- a/modules/xcode/tests/test_xcode_project.lua +++ b/modules/xcode/tests/test_xcode_project.lua @@ -61,6 +61,17 @@ ]] end + function suite.PBXBuildFile_ListsSwiftSources() + files { "source.swift", "Info.plist" } + prepare() + xcode.PBXBuildFile(tr) + test.capture [[ +/* Begin PBXBuildFile section */ + 4616E7383FD8A3AA79D7A578 /* source.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B2BDAE0539CBF12983B9120 /* source.swift */; }; +/* End PBXBuildFile section */ + ]] + end + function suite.PBXBuildFile_ListsResourceFilesOnlyOnceWithGroupID() files { "English.lproj/MainMenu.xib", "French.lproj/MainMenu.xib" } prepare() @@ -3563,6 +3574,83 @@ ]] end + function suite.XCBuildConfigurationProject_OnSwift4_0() + workspace("MyWorkspace") + swiftversion("4.0") + prepare() + xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) + test.capture [[ + A14350AC4595EE5E57CE36EC /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(NATIVE_ARCH_ACTUAL)"; + CONFIGURATION_BUILD_DIR = "$(SYMROOT)"; + CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + OBJROOT = obj/Debug; + ONLY_ACTIVE_ARCH = NO; + SWIFT_VERSION = 4.0; + SYMROOT = bin/Debug; + }; + name = Debug; + }; + ]] + end + + function suite.XCBuildConfigurationProject_OnSwift4_2() + workspace("MyWorkspace") + swiftversion("4.2") + prepare() + xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) + test.capture [[ + A14350AC4595EE5E57CE36EC /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(NATIVE_ARCH_ACTUAL)"; + CONFIGURATION_BUILD_DIR = "$(SYMROOT)"; + CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + OBJROOT = obj/Debug; + ONLY_ACTIVE_ARCH = NO; + SWIFT_VERSION = 4.2; + SYMROOT = bin/Debug; + }; + name = Debug; + }; + ]] + end + + function suite.XCBuildConfigurationProject_OnSwift5_0() + workspace("MyWorkspace") + swiftversion("5.0") + prepare() + xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) + test.capture [[ + A14350AC4595EE5E57CE36EC /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(NATIVE_ARCH_ACTUAL)"; + CONFIGURATION_BUILD_DIR = "$(SYMROOT)"; + CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + OBJROOT = obj/Debug; + ONLY_ACTIVE_ARCH = NO; + SWIFT_VERSION = 5.0; + SYMROOT = bin/Debug; + }; + name = Debug; + }; + ]] + end --------------------------------------------------------------------------- -- XCBuildConfigurationList tests