Skip to content

Commit fe6f10f

Browse files
authored
Merge pull request #488 from swiftlang/owenv/bundling-continued
Include xcspec resources in the CMake build
2 parents 36e8b25 + fce47fd commit fe6f10f

File tree

9 files changed

+170
-177
lines changed

9 files changed

+170
-177
lines changed

Sources/CMakeLists.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,48 @@ See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
]]
1010

11+
include(CMakeParseArguments)
12+
function(SwiftBuild_Bundle)
13+
set(Options)
14+
set(OneValueArguments MODULE)
15+
set(MultiValueArguments FILES)
16+
cmake_parse_arguments(PARSE_ARGV 0 BundleXCSpecs
17+
"${Options}" "${OneValueArguments}" "${MultiValueArguments}")
18+
19+
list(TRANSFORM BundleXCSpecs_FILES PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/")
20+
add_custom_command(TARGET ${BundleXCSpecs_MODULE} POST_BUILD
21+
COMMAND
22+
${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/share/pm/SwiftBuild_${BundleXCSpecs_MODULE}.resources"
23+
COMMAND
24+
${CMAKE_COMMAND} -E copy_if_different ${BundleXCSpecs_FILES} "${CMAKE_BINARY_DIR}/share/pm/SwiftBuild_${BundleXCSpecs_MODULE}.resources/")
25+
26+
file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/share/pm/SwiftBuild_${BundleXCSpecs_MODULE}.resources" _SWIFT_BUILD_RESOURCE_BUNDLE_BUILD_PATH)
27+
file(CONFIGURE
28+
OUTPUT "${CMAKE_BINARY_DIR}/resource_accessors/SwiftBuild_${BundleXCSpecs_MODULE}_resource_bundle_accessor.swift"
29+
CONTENT [[
30+
import Foundation
31+
extension Foundation.Bundle {
32+
static let module: Bundle = {
33+
let mainPath = Bundle.main.bundleURL.appendingPathComponent("SwiftBuild_@BundleXCSpecs_MODULE@.resources").path
34+
let buildPath = #"@_SWIFT_BUILD_RESOURCE_BUNDLE_BUILD_PATH@"#
35+
let preferredBundle = Bundle(path: mainPath)
36+
guard let bundle = preferredBundle ?? Bundle(path: buildPath) else {
37+
Swift.fatalError("could not load resource bundle: from \(mainPath) or \(buildPath)")
38+
}
39+
return bundle
40+
}()
41+
}
42+
]]
43+
ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF)
44+
45+
target_sources("${BundleXCSpecs_MODULE}" PRIVATE
46+
"${CMAKE_BINARY_DIR}/resource_accessors/SwiftBuild_${BundleXCSpecs_MODULE}_resource_bundle_accessor.swift")
47+
48+
install(DIRECTORY
49+
"${CMAKE_BINARY_DIR}/share/pm/SwiftBuild_${BundleXCSpecs_MODULE}.resources/"
50+
DESTINATION share/pm/SwiftBuild_${BundleXCSpecs_MODULE}.resources/)
51+
endfunction()
52+
1153
add_subdirectory(SWBCSupport)
1254
add_subdirectory(SWBCLibc)
1355
add_subdirectory(SWBLibc)

Sources/SWBAndroidPlatform/CMakeLists.txt

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,15 @@ See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
]]
1010

11-
file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}"
12-
_SWBAndroidPlatform_NATIVE_CMAKE_CURRENT_BINARY_DIR)
13-
file(CONFIGURE
14-
OUTPUT resource_bundle_accessor.swift
15-
CONTENT [[
16-
import Foundation
17-
extension Foundation.Bundle {
18-
static let module: Bundle = {
19-
let mainPath = Bundle.main.bundleURL.appendingPathComponent("SwiftBuild_SWBAndroidPlatform.resources").path
20-
let buildPath = #"@_SWBAndroidPlatform_NATIVE_CMAKE_CURRENT_BINARY_DIR@\SwiftBuild_SWBAndroidPlatform.resources"#
21-
let preferredBundle = Bundle(path: mainPath)
22-
guard let bundle = preferredBundle ?? Bundle(path: buildPath) else {
23-
Swift.fatalError("could not load resource bundle: from \(mainPath) or \(buildPath)")
24-
}
25-
return bundle
26-
}()
27-
}
28-
]]
29-
ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF)
30-
3111
add_library(SWBAndroidPlatform
3212
AndroidSDK.swift
3313
Plugin.swift)
14+
SwiftBuild_Bundle(MODULE SWBAndroidPlatform FILES
15+
Specs/Android.xcspec)
3416
target_link_libraries(SWBAndroidPlatform PUBLIC
3517
SWBCore
3618
SWBMacro
3719
SWBUtil)
38-
target_sources(SWBAndroidPlatform PRIVATE
39-
"${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift")
4020

4121
set_target_properties(SWBAndroidPlatform PROPERTIES
4222
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

Sources/SWBApplePlatform/CMakeLists.txt

Lines changed: 71 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,6 @@ See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
]]
1010

11-
file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}"
12-
_SWBApplePlatform_NATIVE_CMAKE_CURRENT_BINARY_DIR)
13-
file(CONFIGURE
14-
OUTPUT resource_bundle_accessor.swift
15-
CONTENT [[
16-
import Foundation
17-
extension Foundation.Bundle {
18-
static let module: Bundle = {
19-
let mainPath = Bundle.main.bundleURL.appendingPathComponent("SwiftBuild_SWBApplePlatform.resources").path
20-
let buildPath = #"@_SWBApplePlatform_NATIVE_CMAKE_CURRENT_BINARY_DIR@\SwiftBuild_SWBApplePlatform.resources"#
21-
let preferredBundle = Bundle(path: mainPath)
22-
guard let bundle = preferredBundle ?? Bundle(path: buildPath) else {
23-
Swift.fatalError("could not load resource bundle: from \(mainPath) or \(buildPath)")
24-
}
25-
return bundle
26-
}()
27-
}
28-
]]
29-
ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF)
30-
3111
add_library(SWBApplePlatform
3212
AppIntentsMetadataCompiler.swift
3313
AppIntentsMetadataTaskProducer.swift
@@ -65,6 +45,77 @@ add_library(SWBApplePlatform
6545
StringCatalogCompilerOutputParser.swift
6646
StubBinaryTaskProducer.swift
6747
XCStringsInputFileGroupingStrategy.swift)
48+
SwiftBuild_Bundle(MODULE SWBApplePlatform FILES
49+
Specs/AppIntentsMetadata.xcspec
50+
Specs/AppIntentsNLTraining.xcspec
51+
Specs/AppShortcutStringsMetadata.xcspec
52+
Specs/AssetCatalogCompiler.xcspec
53+
Specs/CompileSkybox.xcspec
54+
Specs/CopyPNGFile.xcspec
55+
Specs/CopyTiffFile.xcspec
56+
"Specs/Core Data.xcspec"
57+
Specs/CoreML.xcspec
58+
"Specs/Darwin Package Types.xcspec"
59+
"Specs/Darwin Product Types.xcspec"
60+
Specs/DriverKit.xcspec
61+
Specs/DTrace.xcspec
62+
Specs/Embedded-Device.xcspec
63+
Specs/Embedded-Shared.xcspec
64+
Specs/Embedded-Simulator.xcspec
65+
Specs/EmbeddedBinaryValidationUtility.xcspec
66+
Specs/GenerateAppPlaygroundAssetCatalog.xcspec
67+
Specs/GenerateTextureAtlas.xcspec
68+
Specs/IBCompiler.xcspec
69+
Specs/IBPostprocessor.xcspec
70+
Specs/IBStoryboardCompiler.xcspec
71+
Specs/IBStoryboardLinker.xcspec
72+
Specs/IBStoryboardPostprocessor.xcspec
73+
Specs/Iconutil.xcspec
74+
Specs/Iig.xcspec
75+
Specs/InfoPlistUtility.xcspec
76+
Specs/InstrumentsPackage.xcspec
77+
Specs/Intents.xcspec
78+
"Specs/Interface Builder File Types.xcspec"
79+
"Specs/iOS Device.xcspec"
80+
"Specs/iOS Shared.xcspec"
81+
"Specs/iOS Simulator.xcspec"
82+
Specs/KernelExtension.xcspec
83+
Specs/Lipo.xcspec
84+
Specs/LSRegisterURL.xcspec
85+
"Specs/MacOSX Architectures.xcspec"
86+
"Specs/MacOSX Core Build System.xcspec"
87+
"Specs/MacOSX Native Build System.xcspec"
88+
"Specs/MacOSX Package Types.xcspec"
89+
"Specs/MacOSX Product Types.xcspec"
90+
Specs/MetalCompiler.xcspec
91+
Specs/MetalFileTypes.xcspec
92+
Specs/MetalLinker.xcspec
93+
Specs/MetalPackageTypes.xcspec
94+
Specs/MetalProductTypes.xcspec
95+
Specs/MiG.xcspec
96+
Specs/OpenCL.xcspec
97+
Specs/OSACompile.xcspec
98+
Specs/RCFileTypes.xcspec
99+
Specs/RealityAssets.xcspec
100+
Specs/ReferenceObject.xcspec
101+
Specs/ResMerger.xcspec
102+
Specs/Rez.xcspec
103+
"Specs/SceneKit FileTypes.xcspec"
104+
"Specs/SceneKit Tools.xcspec"
105+
Specs/SpriteKitFileTypes.xcspec
106+
Specs/TiffUtil.xcspec
107+
"Specs/tvOS Device.xcspec"
108+
"Specs/tvOS Shared.xcspec"
109+
"Specs/tvOS Simulator.xcspec"
110+
Specs/WatchKit1ProductTypes.xcspec
111+
"Specs/watchOS Device.xcspec"
112+
"Specs/watchOS Shared.xcspec"
113+
"Specs/watchOS Simulator.xcspec"
114+
Specs/XCAppExtensionPoints.xcspec
115+
Specs/XCStrings.xcspec
116+
"Specs/xrOS Device.xcspec"
117+
"Specs/xrOS Shared.xcspec"
118+
"Specs/xrOS Simulator.xcspec")
68119
set_target_properties(SWBApplePlatform PROPERTIES
69120
Swift_LANGUAGE_VERSION 6)
70121
target_link_libraries(SWBApplePlatform PUBLIC
@@ -73,8 +124,6 @@ target_link_libraries(SWBApplePlatform PUBLIC
73124
SWBUtil
74125
SWBProtocol
75126
SWBTaskConstruction)
76-
target_sources(SWBApplePlatform PRIVATE
77-
"${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift")
78127

79128
set_target_properties(SWBApplePlatform PROPERTIES
80129
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

Sources/SWBCore/CMakeLists.txt

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,6 @@ See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
]]
1010

11-
file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}"
12-
_SWBCore_NATIVE_CMAKE_CURRENT_BINARY_DIR)
13-
file(CONFIGURE
14-
OUTPUT resource_bundle_accessor.swift
15-
CONTENT [[
16-
import Foundation
17-
extension Foundation.Bundle {
18-
static let module: Bundle = {
19-
let mainPath = Bundle.main.bundleURL.appendingPathComponent("SwiftBuild_SWBCore.resources").path
20-
let buildPath = #"@_SWBCore_NATIVE_CMAKE_CURRENT_BINARY_DIR@\SwiftBuild_SWBCore.resources"#
21-
let preferredBundle = Bundle(path: mainPath)
22-
guard let bundle = preferredBundle ?? Bundle(path: buildPath) else {
23-
Swift.fatalError("could not load resource bundle: from \(mainPath) or \(buildPath)")
24-
}
25-
return bundle
26-
}()
27-
}
28-
]]
29-
ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF)
30-
3111
add_library(SWBCore
3212
ActivityReporting.swift
3313
Apple/DeviceFamily.swift
@@ -195,6 +175,10 @@ add_library(SWBCore
195175
WorkspaceContext.swift
196176
WorkspaceSettingsCache.swift
197177
XCFramework.swift)
178+
SwiftBuild_Bundle(MODULE SWBCore FILES
179+
Specs/CoreBuildSystem.xcspec
180+
Specs/ExternalBuildSystem.xcspec
181+
Specs/NativeBuildSystem.xcspec)
198182
set_target_properties(SWBCore PROPERTIES
199183
Swift_LANGUAGE_VERSION 5)
200184
target_link_libraries(SWBCore PUBLIC
@@ -205,8 +189,6 @@ target_link_libraries(SWBCore PUBLIC
205189
SWBCAS
206190
SWBLLBuild
207191
SwiftDriver)
208-
target_sources(SWBCore PRIVATE
209-
"${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift")
210192

211193
set_target_properties(SWBCore PROPERTIES
212194
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

Sources/SWBGenericUnixPlatform/CMakeLists.txt

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,16 @@ See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
]]
1010

11-
file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}"
12-
_SWBGenericUnixPlatform_NATIVE_CMAKE_CURRENT_BINARY_DIR)
13-
file(CONFIGURE
14-
OUTPUT resource_bundle_accessor.swift
15-
CONTENT [[
16-
import Foundation
17-
extension Foundation.Bundle {
18-
static let module: Bundle = {
19-
let mainPath = Bundle.main.bundleURL.appendingPathComponent("SwiftBuild_SWBGenericUnixPlatform.resources").path
20-
let buildPath = #"@_SWBGenericUnixPlatform_NATIVE_CMAKE_CURRENT_BINARY_DIR@\SwiftBuild_SWBGenericUnixPlatform.resources"#
21-
let preferredBundle = Bundle(path: mainPath)
22-
guard let bundle = preferredBundle ?? Bundle(path: buildPath) else {
23-
Swift.fatalError("could not load resource bundle: from \(mainPath) or \(buildPath)")
24-
}
25-
return bundle
26-
}()
27-
}
28-
]]
29-
ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF)
30-
3111
add_library(SWBGenericUnixPlatform
3212
Plugin.swift)
13+
SwiftBuild_Bundle(MODULE SWBGenericUnixPlatform FILES
14+
Specs/Unix.xcspec
15+
Specs/UnixCompile.xcspec
16+
Specs/UnixLd.xcspec
17+
Specs/UnixLibtool.xcspec)
3318
target_link_libraries(SWBGenericUnixPlatform PUBLIC
3419
SWBCore
3520
SWBUtil)
36-
target_sources(SWBGenericUnixPlatform PRIVATE
37-
"${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift")
3821

3922
set_target_properties(SWBGenericUnixPlatform PROPERTIES
4023
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

Sources/SWBQNXPlatform/CMakeLists.txt

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,18 @@ See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
]]
1010

11-
file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}"
12-
_SWBQNXPlatform_NATIVE_CMAKE_CURRENT_BINARY_DIR)
13-
file(CONFIGURE
14-
OUTPUT resource_bundle_accessor.swift
15-
CONTENT [[
16-
import Foundation
17-
extension Foundation.Bundle {
18-
static let module: Bundle = {
19-
let mainPath = Bundle.main.bundleURL.appendingPathComponent("SwiftBuild_SWBQNXPlatform.resources").path
20-
let buildPath = #"@_SWBQNXPlatform_NATIVE_CMAKE_CURRENT_BINARY_DIR@\SwiftBuild_SWBQNXPlatform.resources"#
21-
let preferredBundle = Bundle(path: mainPath)
22-
guard let bundle = preferredBundle ?? Bundle(path: buildPath) else {
23-
Swift.fatalError("could not load resource bundle: from \(mainPath) or \(buildPath)")
24-
}
25-
return bundle
26-
}()
27-
}
28-
]]
29-
ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF)
30-
3111
add_library(SWBQNXPlatform
3212
Plugin.swift
3313
QNXSDP.swift)
14+
SwiftBuild_Bundle(MODULE SWBQNXPlatform FILES
15+
Specs/QNX.xcspec
16+
Specs/QNXCompile.xcspec
17+
Specs/QNXLd.xcspec
18+
Specs/QNXLibtool.xcspec)
3419
target_link_libraries(SWBQNXPlatform PUBLIC
3520
SWBCore
3621
SWBMacro
3722
SWBUtil)
38-
target_sources(SWBQNXPlatform PRIVATE
39-
"${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift")
4023

4124
set_target_properties(SWBQNXPlatform PROPERTIES
4225
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

0 commit comments

Comments
 (0)