peachsim 0.1.2430 → 0.1.2432
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/commands/preview.ts +2 -1
- package/cli/outbound-endpoints.ts +10 -2
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/bundle-channel.cjs +15765 -5973
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/config.mjs +1 -1
- package/dist-lib/detox/index.cjs +1 -1
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/expo-swift-bundle.cjs +14638 -4888
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +15464 -5754
- package/dist-lib/host/fetch-proxy-handler.cjs +3204 -54
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +3541 -391
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +3437 -287
- package/dist-lib/native-app-identity-project.cjs +2 -2
- package/dist-lib/native-app-identity-project.mjs +2 -2
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +1 -1
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/pdfium-raster.cjs +1 -1
- package/dist-lib/pdfium-raster.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +24 -24
- package/dist-lib/public-origins-lib.json +172 -79
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/reap-browser.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +1 -1
- package/dist-lib/skills.cjs +16786 -6994
- package/dist-lib/swift-compile.cjs +2 -2
- package/dist-lib/swift-compile.mjs +2 -2
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +1 -1
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +74 -6
- package/dist-lib/vite.cjs +3331 -181
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +1 -1
- package/package.json +1 -1
- package/src/expo-native-workspace.ts +23 -63
- package/src/pbx-table.ts +200 -0
- package/src/pod-sources.ts +628 -0
- package/src/podfile-cocoapods.ts +40 -3
- package/src/pods-analysis.ts +488 -0
- package/src/pods-build-settings.ts +1015 -0
- package/src/pods-files.ts +478 -0
- package/src/pods-install.ts +475 -0
- package/src/pods-integration.ts +778 -0
- package/src/pods-post-install.ts +1811 -0
- package/src/pods-project.ts +2416 -0
- package/src/pods-scripts.ts +409 -0
- package/src/pods-targets.ts +757 -0
- package/src/pods-xcconfig.ts +198 -0
- package/src/podspec-cocoapods.ts +29 -3
- package/src/podspec-ruby-stdlib.ts +111 -10
- package/src/podspec-ruby.ts +52 -8
- package/src/swift-catalog-png.ts +75 -0
- package/src/swift-host.ts +4 -3
- package/src/swift-root-lock.ts +0 -10
- package/src/swift-source-pods.ts +29 -73
- package/src/turbo-source.ts +16 -37
|
@@ -0,0 +1,2416 @@
|
|
|
1
|
+
// CocoaPods 1.17's SinglePodsProjectGenerator (MIT, Eloy Durán and the CocoaPods
|
|
2
|
+
// team) over the Xcodeproj 1.28 object model it drives: the Pods project's
|
|
3
|
+
// groups, file references and targets, and the support files each target
|
|
4
|
+
// installer writes under the sandbox. library specs only; schemes are skipped.
|
|
5
|
+
import fs from 'node:fs'
|
|
6
|
+
import path from 'node:path'
|
|
7
|
+
import { isDict } from './openstep-plist'
|
|
8
|
+
import {
|
|
9
|
+
normalizeArraySettings,
|
|
10
|
+
PbxTable,
|
|
11
|
+
type PlistDict,
|
|
12
|
+
type PlistValue,
|
|
13
|
+
} from './pbx-table'
|
|
14
|
+
import { type PodsBuildSettings } from './pods-build-settings'
|
|
15
|
+
import {
|
|
16
|
+
HEADER_EXTENSIONS,
|
|
17
|
+
SOURCE_FILE_EXTENSIONS,
|
|
18
|
+
type FileAccessor,
|
|
19
|
+
type XCFramework,
|
|
20
|
+
} from './pods-files'
|
|
21
|
+
import {
|
|
22
|
+
COPY_XCFRAMEWORKS_BODY,
|
|
23
|
+
COPY_XCFRAMEWORKS_HEADER,
|
|
24
|
+
EMBED_FRAMEWORKS_HEADER,
|
|
25
|
+
INSTALL_RESOURCES_FUNCTION,
|
|
26
|
+
RESOURCES_TAIL,
|
|
27
|
+
} from './pods-scripts'
|
|
28
|
+
import {
|
|
29
|
+
type AggregateTarget,
|
|
30
|
+
type ConfigurationType,
|
|
31
|
+
type PodTarget,
|
|
32
|
+
type PodTargets,
|
|
33
|
+
relativePath,
|
|
34
|
+
} from './pods-targets'
|
|
35
|
+
import { type XcodeConfig } from './pods-xcconfig'
|
|
36
|
+
|
|
37
|
+
type Id = string
|
|
38
|
+
|
|
39
|
+
// Xcodeproj::Constants::FILE_TYPES_BY_EXTENSION
|
|
40
|
+
const FILE_TYPES: Record<string, string> = {
|
|
41
|
+
a: 'archive.ar',
|
|
42
|
+
apns: 'text',
|
|
43
|
+
app: 'wrapper.application',
|
|
44
|
+
appex: 'wrapper.app-extension',
|
|
45
|
+
bundle: 'wrapper.plug-in',
|
|
46
|
+
cpp: 'sourcecode.cpp.cpp',
|
|
47
|
+
dylib: 'compiled.mach-o.dylib',
|
|
48
|
+
entitlements: 'text.plist.entitlements',
|
|
49
|
+
framework: 'wrapper.framework',
|
|
50
|
+
gif: 'image.gif',
|
|
51
|
+
gpx: 'text.xml',
|
|
52
|
+
h: 'sourcecode.c.h',
|
|
53
|
+
hpp: 'sourcecode.cpp.h',
|
|
54
|
+
m: 'sourcecode.c.objc',
|
|
55
|
+
markdown: 'text',
|
|
56
|
+
mdimporter: 'wrapper.cfbundle',
|
|
57
|
+
modulemap: 'sourcecode.module',
|
|
58
|
+
mov: 'video.quicktime',
|
|
59
|
+
mp3: 'audio.mp3',
|
|
60
|
+
octest: 'wrapper.cfbundle',
|
|
61
|
+
pch: 'sourcecode.c.h',
|
|
62
|
+
plist: 'text.plist.xml',
|
|
63
|
+
png: 'image.png',
|
|
64
|
+
sh: 'text.script.sh',
|
|
65
|
+
sks: 'file.sks',
|
|
66
|
+
storyboard: 'file.storyboard',
|
|
67
|
+
strings: 'text.plist.strings',
|
|
68
|
+
swift: 'sourcecode.swift',
|
|
69
|
+
xcassets: 'folder.assetcatalog',
|
|
70
|
+
xcconfig: 'text.xcconfig',
|
|
71
|
+
xcdatamodel: 'wrapper.xcdatamodel',
|
|
72
|
+
xcodeproj: 'wrapper.pb-project',
|
|
73
|
+
xctest: 'wrapper.cfbundle',
|
|
74
|
+
xib: 'file.xib',
|
|
75
|
+
zip: 'archive.zip',
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const PRODUCT_UTI = {
|
|
79
|
+
application: 'com.apple.product-type.application',
|
|
80
|
+
framework: 'com.apple.product-type.framework',
|
|
81
|
+
static_library: 'com.apple.product-type.library.static',
|
|
82
|
+
bundle: 'com.apple.product-type.bundle',
|
|
83
|
+
}
|
|
84
|
+
type ProductType = keyof typeof PRODUCT_UTI
|
|
85
|
+
const PRODUCT_EXTENSIONS: Record<ProductType, string> = {
|
|
86
|
+
application: 'app',
|
|
87
|
+
framework: 'framework',
|
|
88
|
+
static_library: 'a',
|
|
89
|
+
bundle: 'bundle',
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const COMPATIBILITY_VERSION: Record<number, string> = {
|
|
93
|
+
100: 'Xcode 26.3',
|
|
94
|
+
77: 'Xcode 16.0',
|
|
95
|
+
71: 'Xcode 16.2',
|
|
96
|
+
70: 'Xcode 16.0',
|
|
97
|
+
63: 'Xcode 15.3',
|
|
98
|
+
60: 'Xcode 15.0',
|
|
99
|
+
56: 'Xcode 14.0',
|
|
100
|
+
55: 'Xcode 13.0',
|
|
101
|
+
54: 'Xcode 12.0',
|
|
102
|
+
53: 'Xcode 11.4',
|
|
103
|
+
52: 'Xcode 11.0',
|
|
104
|
+
51: 'Xcode 10.0',
|
|
105
|
+
50: 'Xcode 9.3',
|
|
106
|
+
48: 'Xcode 8.0',
|
|
107
|
+
47: 'Xcode 6.3',
|
|
108
|
+
46: 'Xcode 3.2',
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const PROJECT_DEFAULT_BUILD_SETTINGS: Record<'all' | ConfigurationType, PlistDict> = {
|
|
112
|
+
all: {
|
|
113
|
+
ALWAYS_SEARCH_USER_PATHS: 'NO',
|
|
114
|
+
CLANG_ANALYZER_NONNULL: 'YES',
|
|
115
|
+
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION: 'YES_AGGRESSIVE',
|
|
116
|
+
CLANG_CXX_LANGUAGE_STANDARD: 'gnu++14',
|
|
117
|
+
CLANG_CXX_LIBRARY: 'libc++',
|
|
118
|
+
CLANG_ENABLE_MODULES: 'YES',
|
|
119
|
+
CLANG_ENABLE_OBJC_ARC: 'YES',
|
|
120
|
+
CLANG_ENABLE_OBJC_WEAK: 'YES',
|
|
121
|
+
CLANG_WARN__DUPLICATE_METHOD_MATCH: 'YES',
|
|
122
|
+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING: 'YES',
|
|
123
|
+
CLANG_WARN_BOOL_CONVERSION: 'YES',
|
|
124
|
+
CLANG_WARN_COMMA: 'YES',
|
|
125
|
+
CLANG_WARN_CONSTANT_CONVERSION: 'YES',
|
|
126
|
+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS: 'YES',
|
|
127
|
+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE: 'YES_ERROR',
|
|
128
|
+
CLANG_WARN_DOCUMENTATION_COMMENTS: 'YES',
|
|
129
|
+
CLANG_WARN_EMPTY_BODY: 'YES',
|
|
130
|
+
CLANG_WARN_ENUM_CONVERSION: 'YES',
|
|
131
|
+
CLANG_WARN_INFINITE_RECURSION: 'YES',
|
|
132
|
+
CLANG_WARN_INT_CONVERSION: 'YES',
|
|
133
|
+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION: 'YES',
|
|
134
|
+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF: 'YES',
|
|
135
|
+
CLANG_WARN_OBJC_LITERAL_CONVERSION: 'YES',
|
|
136
|
+
CLANG_WARN_OBJC_ROOT_CLASS: 'YES_ERROR',
|
|
137
|
+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER: 'YES',
|
|
138
|
+
CLANG_WARN_RANGE_LOOP_ANALYSIS: 'YES',
|
|
139
|
+
CLANG_WARN_STRICT_PROTOTYPES: 'YES',
|
|
140
|
+
CLANG_WARN_SUSPICIOUS_MOVE: 'YES',
|
|
141
|
+
CLANG_WARN_UNGUARDED_AVAILABILITY: 'YES_AGGRESSIVE',
|
|
142
|
+
CLANG_WARN_UNREACHABLE_CODE: 'YES',
|
|
143
|
+
COPY_PHASE_STRIP: 'NO',
|
|
144
|
+
ENABLE_STRICT_OBJC_MSGSEND: 'YES',
|
|
145
|
+
GCC_C_LANGUAGE_STANDARD: 'gnu11',
|
|
146
|
+
GCC_NO_COMMON_BLOCKS: 'YES',
|
|
147
|
+
GCC_WARN_64_TO_32_BIT_CONVERSION: 'YES',
|
|
148
|
+
GCC_WARN_ABOUT_RETURN_TYPE: 'YES_ERROR',
|
|
149
|
+
GCC_WARN_UNDECLARED_SELECTOR: 'YES',
|
|
150
|
+
GCC_WARN_UNINITIALIZED_AUTOS: 'YES_AGGRESSIVE',
|
|
151
|
+
GCC_WARN_UNUSED_FUNCTION: 'YES',
|
|
152
|
+
GCC_WARN_UNUSED_VARIABLE: 'YES',
|
|
153
|
+
MTL_FAST_MATH: 'YES',
|
|
154
|
+
PRODUCT_NAME: '$(TARGET_NAME)',
|
|
155
|
+
SWIFT_VERSION: '5.0',
|
|
156
|
+
},
|
|
157
|
+
release: {
|
|
158
|
+
DEBUG_INFORMATION_FORMAT: 'dwarf-with-dsym',
|
|
159
|
+
ENABLE_NS_ASSERTIONS: 'NO',
|
|
160
|
+
MTL_ENABLE_DEBUG_INFO: 'NO',
|
|
161
|
+
SWIFT_COMPILATION_MODE: 'wholemodule',
|
|
162
|
+
SWIFT_OPTIMIZATION_LEVEL: '-O',
|
|
163
|
+
},
|
|
164
|
+
debug: {
|
|
165
|
+
DEBUG_INFORMATION_FORMAT: 'dwarf',
|
|
166
|
+
ENABLE_TESTABILITY: 'YES',
|
|
167
|
+
GCC_DYNAMIC_NO_PIC: 'NO',
|
|
168
|
+
GCC_OPTIMIZATION_LEVEL: '0',
|
|
169
|
+
GCC_PREPROCESSOR_DEFINITIONS: ['DEBUG=1', '$(inherited)'],
|
|
170
|
+
MTL_ENABLE_DEBUG_INFO: 'INCLUDE_SOURCE',
|
|
171
|
+
ONLY_ACTIVE_ARCH: 'YES',
|
|
172
|
+
SWIFT_ACTIVE_COMPILATION_CONDITIONS: 'DEBUG',
|
|
173
|
+
SWIFT_OPTIMIZATION_LEVEL: '-Onone',
|
|
174
|
+
},
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Xcodeproj::Constants::COMMON_BUILD_SETTINGS for iOS, keyed by the joined key combination
|
|
178
|
+
const COMMON_BUILD_SETTINGS: Record<string, PlistDict> = {
|
|
179
|
+
ios: { SDKROOT: 'iphoneos' },
|
|
180
|
+
'release,ios': { VALIDATE_PRODUCT: 'YES' },
|
|
181
|
+
framework: {
|
|
182
|
+
CURRENT_PROJECT_VERSION: '1',
|
|
183
|
+
DEFINES_MODULE: 'YES',
|
|
184
|
+
DYLIB_COMPATIBILITY_VERSION: '1',
|
|
185
|
+
DYLIB_CURRENT_VERSION: '1',
|
|
186
|
+
DYLIB_INSTALL_NAME_BASE: '@rpath',
|
|
187
|
+
INSTALL_PATH: '$(LOCAL_LIBRARY_DIR)/Frameworks',
|
|
188
|
+
PRODUCT_NAME: '$(TARGET_NAME:c99extidentifier)',
|
|
189
|
+
SKIP_INSTALL: 'YES',
|
|
190
|
+
VERSION_INFO_PREFIX: '',
|
|
191
|
+
VERSIONING_SYSTEM: 'apple-generic',
|
|
192
|
+
},
|
|
193
|
+
'ios,framework': {
|
|
194
|
+
LD_RUNPATH_SEARCH_PATHS:
|
|
195
|
+
'$(inherited) @executable_path/Frameworks @loader_path/Frameworks',
|
|
196
|
+
TARGETED_DEVICE_FAMILY: '1,2',
|
|
197
|
+
},
|
|
198
|
+
'framework,swift': { DEFINES_MODULE: 'YES' },
|
|
199
|
+
'ios,static_library': {
|
|
200
|
+
OTHER_LDFLAGS: '-ObjC',
|
|
201
|
+
SKIP_INSTALL: 'YES',
|
|
202
|
+
TARGETED_DEVICE_FAMILY: '1,2',
|
|
203
|
+
},
|
|
204
|
+
application: {
|
|
205
|
+
ASSETCATALOG_COMPILER_APPICON_NAME: 'AppIcon',
|
|
206
|
+
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME: 'AccentColor',
|
|
207
|
+
},
|
|
208
|
+
'ios,application': {
|
|
209
|
+
LD_RUNPATH_SEARCH_PATHS: '$(inherited) @executable_path/Frameworks',
|
|
210
|
+
TARGETED_DEVICE_FAMILY: '1,2',
|
|
211
|
+
},
|
|
212
|
+
bundle: { WRAPPER_EXTENSION: 'bundle', SKIP_INSTALL: 'YES' },
|
|
213
|
+
'ios,bundle': { SDKROOT: 'iphoneos' },
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const LAST_KNOWN_IOS_SDK = '26.0'
|
|
217
|
+
const HEADERS = new Set(HEADER_EXTENSIONS)
|
|
218
|
+
const SOURCES = new Set(SOURCE_FILE_EXTENSIONS)
|
|
219
|
+
const LOCALIZATION_REGION = /(\/|^)(?<region>[^/]*?)\.lproj(\/|$)/
|
|
220
|
+
|
|
221
|
+
const deepCopy = (settings: PlistDict): PlistDict => structuredClone(settings)
|
|
222
|
+
|
|
223
|
+
// ruby's String#<=>, which compares bytes
|
|
224
|
+
const compareBytes = (a: string, b: string) =>
|
|
225
|
+
Buffer.compare(Buffer.from(a), Buffer.from(b))
|
|
226
|
+
|
|
227
|
+
// File.extname and File.basename(name, '.*')
|
|
228
|
+
const extname = (name: string) => path.extname(name)
|
|
229
|
+
const stem = (name: string) => path.basename(name, path.extname(name))
|
|
230
|
+
|
|
231
|
+
function combinations<T>(keys: T[]): T[][] {
|
|
232
|
+
const result: T[][] = []
|
|
233
|
+
for (let n = 1; n <= keys.length; n++) {
|
|
234
|
+
const pick = (start: number, chosen: T[]) => {
|
|
235
|
+
if (chosen.length === n) {
|
|
236
|
+
result.push(chosen)
|
|
237
|
+
return
|
|
238
|
+
}
|
|
239
|
+
for (let i = start; i < keys.length; i++) pick(i + 1, [...chosen, keys[i]!])
|
|
240
|
+
}
|
|
241
|
+
pick(0, [])
|
|
242
|
+
}
|
|
243
|
+
return result
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** ProjectHelper.common_build_settings for iOS. */
|
|
247
|
+
function commonBuildSettings(
|
|
248
|
+
type: ConfigurationType | null,
|
|
249
|
+
deploymentTarget: string | null,
|
|
250
|
+
productType: ProductType | null,
|
|
251
|
+
language: 'objc' | 'swift' | null,
|
|
252
|
+
): PlistDict {
|
|
253
|
+
const keys = [type, 'ios', productType ?? 'application', language].filter(
|
|
254
|
+
(key): key is string => key !== null,
|
|
255
|
+
)
|
|
256
|
+
const settings: PlistDict = {}
|
|
257
|
+
for (const combination of combinations(keys))
|
|
258
|
+
Object.assign(settings, deepCopy(COMMON_BUILD_SETTINGS[combination.join(',')] ?? {}))
|
|
259
|
+
if (deploymentTarget) {
|
|
260
|
+
settings.IPHONEOS_DEPLOYMENT_TARGET = deploymentTarget
|
|
261
|
+
if (deploymentTarget < '5') settings.CLANG_ENABLE_OBJC_WEAK = 'NO'
|
|
262
|
+
}
|
|
263
|
+
return settings
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Pod::Version#<=> on numeric segments
|
|
267
|
+
function versionLess(a: string, b: string): boolean {
|
|
268
|
+
const left = a.split('.').map((part) => Number.parseInt(part, 10) || 0)
|
|
269
|
+
const right = b.split('.').map((part) => Number.parseInt(part, 10) || 0)
|
|
270
|
+
for (let i = 0; i < Math.max(left.length, right.length); i++) {
|
|
271
|
+
const x = left[i] ?? 0
|
|
272
|
+
const y = right[i] ?? 0
|
|
273
|
+
if (x !== y) return x < y
|
|
274
|
+
}
|
|
275
|
+
return false
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const realpath = (file: string) => fs.realpathSync(file)
|
|
279
|
+
|
|
280
|
+
/** Xcodeproj::Project with Pod::Project's groups, kept as a PbxTable. */
|
|
281
|
+
class PodsProject {
|
|
282
|
+
readonly table = new PbxTable()
|
|
283
|
+
readonly root: Id
|
|
284
|
+
readonly mainGroup: Id
|
|
285
|
+
readonly productsGroup: Id
|
|
286
|
+
readonly frameworksGroup: Id
|
|
287
|
+
readonly supportFilesGroup: Id
|
|
288
|
+
readonly podsGroup: Id
|
|
289
|
+
readonly developmentPodsGroup: Id
|
|
290
|
+
readonly dependenciesGroup: Id
|
|
291
|
+
readonly #parents = new Map<Id, Id>()
|
|
292
|
+
readonly #refsByAbsolutePath = new Map<string, Id>()
|
|
293
|
+
readonly #variantGroups = new Map<string, Id>()
|
|
294
|
+
|
|
295
|
+
constructor(
|
|
296
|
+
readonly projectDir: string,
|
|
297
|
+
readonly objectVersion: number,
|
|
298
|
+
) {
|
|
299
|
+
const table = this.table
|
|
300
|
+
this.root = table.add('project', {
|
|
301
|
+
isa: 'PBXProject',
|
|
302
|
+
attributes: { LastSwiftUpdateCheck: '1600', LastUpgradeCheck: '1600' },
|
|
303
|
+
compatibilityVersion: COMPATIBILITY_VERSION[objectVersion] ?? 'Xcode 3.2',
|
|
304
|
+
developmentRegion: 'en',
|
|
305
|
+
hasScannedForEncodings: '0',
|
|
306
|
+
knownRegions: ['en', 'Base'],
|
|
307
|
+
minimizedProjectReferenceProxies: '0',
|
|
308
|
+
preferredProjectObjectVersion: '100',
|
|
309
|
+
projectDirPath: '',
|
|
310
|
+
projectRoot: '',
|
|
311
|
+
targets: [],
|
|
312
|
+
})
|
|
313
|
+
table.rootObject = this.root
|
|
314
|
+
this.mainGroup = table.add('main group', {
|
|
315
|
+
isa: 'PBXGroup',
|
|
316
|
+
children: [],
|
|
317
|
+
sourceTree: '<group>',
|
|
318
|
+
})
|
|
319
|
+
const project = table.get(this.root)
|
|
320
|
+
project.mainGroup = this.mainGroup
|
|
321
|
+
this.productsGroup = this.newGroup(this.mainGroup, 'Products')
|
|
322
|
+
project.productRefGroup = this.productsGroup
|
|
323
|
+
project.buildConfigurationList = this.newConfigurationList('project')
|
|
324
|
+
this.addProjectConfiguration('Debug', 'debug')
|
|
325
|
+
this.addProjectConfiguration('Release', 'release')
|
|
326
|
+
this.frameworksGroup = this.newGroup(this.mainGroup, 'Frameworks')
|
|
327
|
+
this.supportFilesGroup = this.newGroup(this.mainGroup, 'Targets Support Files')
|
|
328
|
+
this.podsGroup = this.newGroup(this.mainGroup, 'Pods')
|
|
329
|
+
this.developmentPodsGroup = this.newGroup(this.mainGroup, 'Development Pods')
|
|
330
|
+
this.dependenciesGroup = this.newGroup(this.mainGroup, 'Dependencies')
|
|
331
|
+
this.setSymroot()
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
get(id: Id): PlistDict {
|
|
335
|
+
return this.table.get(id)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
string(id: Id, key: string): string | undefined {
|
|
339
|
+
return this.table.string(id, key)
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
children(group: Id): Id[] {
|
|
343
|
+
return this.table.list(group, 'children')
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
#add(parent: Id, kind: string, object: PlistDict): Id {
|
|
347
|
+
return this.table.add(`${parent} ${kind}`, object)
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
setSymroot(): void {
|
|
351
|
+
for (const config of this.table.configurations(this.root))
|
|
352
|
+
this.table.buildSettings(config).SYMROOT = '${SRCROOT}/../build'
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
newConfigurationList(owner: string): Id {
|
|
356
|
+
return this.#add(owner, 'configuration list', {
|
|
357
|
+
isa: 'XCConfigurationList',
|
|
358
|
+
buildConfigurations: [],
|
|
359
|
+
defaultConfigurationIsVisible: '0',
|
|
360
|
+
defaultConfigurationName: 'Release',
|
|
361
|
+
})
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
newConfiguration(list: Id, name: string, settings: PlistDict): Id {
|
|
365
|
+
const config = this.#add(list, `configuration ${name}`, {
|
|
366
|
+
isa: 'XCBuildConfiguration',
|
|
367
|
+
buildSettings: settings,
|
|
368
|
+
name,
|
|
369
|
+
})
|
|
370
|
+
this.table.list(list, 'buildConfigurations').push(config)
|
|
371
|
+
return config
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
configurationNamed(owner: Id, name: string): Id | undefined {
|
|
375
|
+
return this.table.configurations(owner).find((id) => this.string(id, 'name') === name)
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** XCBuildConfiguration#type, by whether the configuration defines DEBUG=1. */
|
|
379
|
+
configurationType(config: Id): ConfigurationType {
|
|
380
|
+
const definitions = this.table.buildSettings(config).GCC_PREPROCESSOR_DEFINITIONS
|
|
381
|
+
const list = Array.isArray(definitions) ? definitions : [definitions]
|
|
382
|
+
return list.includes('DEBUG=1') ? 'debug' : 'release'
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/** Pod::Project#add_build_configuration. */
|
|
386
|
+
addProjectConfiguration(name: string, type: ConfigurationType): void {
|
|
387
|
+
if (this.configurationNamed(this.root, name)) return
|
|
388
|
+
const settings = {
|
|
389
|
+
...deepCopy(PROJECT_DEFAULT_BUILD_SETTINGS.all),
|
|
390
|
+
...deepCopy(PROJECT_DEFAULT_BUILD_SETTINGS[type]),
|
|
391
|
+
}
|
|
392
|
+
const list = this.string(this.root, 'buildConfigurationList')!
|
|
393
|
+
this.newConfiguration(list, name, settings)
|
|
394
|
+
const existing = settings.GCC_PREPROCESSOR_DEFINITIONS
|
|
395
|
+
const definitions = Array.isArray(existing) ? existing : ['$(inherited)']
|
|
396
|
+
const defines = [
|
|
397
|
+
`POD_CONFIGURATION_${underscore(name)}`
|
|
398
|
+
.replace(/[^a-zA-Z0-9_]/g, '_')
|
|
399
|
+
.toUpperCase(),
|
|
400
|
+
...(type === 'debug' ? ['DEBUG'] : []),
|
|
401
|
+
]
|
|
402
|
+
for (const define of defines)
|
|
403
|
+
if (!definitions.includes(`${define}=1`)) definitions.unshift(`${define}=1`)
|
|
404
|
+
settings.GCC_PREPROCESSOR_DEFINITIONS = definitions
|
|
405
|
+
if (type === 'debug') settings.SWIFT_ACTIVE_COMPILATION_CONDITIONS = 'DEBUG'
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// GroupableHelper
|
|
409
|
+
|
|
410
|
+
parent(id: Id): Id | undefined {
|
|
411
|
+
return this.#parents.get(id)
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
sourceTreeRealPath(id: Id): string {
|
|
415
|
+
const tree = this.string(id, 'sourceTree')
|
|
416
|
+
if (tree === '<group>') {
|
|
417
|
+
const parent = this.#parents.get(id)
|
|
418
|
+
return parent ? this.realPath(parent) : this.projectDir
|
|
419
|
+
}
|
|
420
|
+
if (tree === 'SOURCE_ROOT') return this.projectDir
|
|
421
|
+
if (tree === '<absolute>') return '/'
|
|
422
|
+
throw new Error(`no real path for the source tree ${tree}`)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
realPath(id: Id): string {
|
|
426
|
+
const base = this.sourceTreeRealPath(id)
|
|
427
|
+
const own = this.string(id, 'path')
|
|
428
|
+
return own ? path.resolve(base, own) : base
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
setPathWithSourceTree(id: Id, target: string, tree: string): void {
|
|
432
|
+
const object = this.get(id)
|
|
433
|
+
object.sourceTree = tree
|
|
434
|
+
if ((tree === '<group>' || tree === 'SOURCE_ROOT') && path.isAbsolute(target))
|
|
435
|
+
object.path = relativePath(target, this.sourceTreeRealPath(id))
|
|
436
|
+
else object.path = target
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
displayName(id: Id): string {
|
|
440
|
+
const object = this.get(id)
|
|
441
|
+
const isa = object.isa
|
|
442
|
+
const name = this.string(id, 'name')
|
|
443
|
+
const own = this.string(id, 'path')
|
|
444
|
+
if (isa === 'PBXFileReference') {
|
|
445
|
+
if (name !== undefined) return name
|
|
446
|
+
if (object.sourceTree === 'BUILT_PRODUCTS_DIR' && own !== undefined) return own
|
|
447
|
+
if (own !== undefined) return path.basename(own)
|
|
448
|
+
return ''
|
|
449
|
+
}
|
|
450
|
+
if (isa === 'PBXGroup' || isa === 'PBXVariantGroup') {
|
|
451
|
+
if (name !== undefined) return name
|
|
452
|
+
if (own !== undefined) return path.basename(own)
|
|
453
|
+
return id === this.mainGroup ? 'Main Group' : ''
|
|
454
|
+
}
|
|
455
|
+
if (isa === 'PBXBuildFile') {
|
|
456
|
+
const ref = this.string(id, 'fileRef')
|
|
457
|
+
return ref ? this.displayName(ref) : 'BuildFile'
|
|
458
|
+
}
|
|
459
|
+
if (isa === 'PBXTargetDependency') {
|
|
460
|
+
if (name !== undefined) return name
|
|
461
|
+
const target = this.string(id, 'target')
|
|
462
|
+
return target ? (this.string(target, 'name') ?? '') : ''
|
|
463
|
+
}
|
|
464
|
+
const generic = name ? name : String(isa).replace(/^(PBX|XC)/, '')
|
|
465
|
+
return String(isa).endsWith('BuildPhase')
|
|
466
|
+
? generic.replace(/BuildPhase$/, '')
|
|
467
|
+
: generic
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
childNamed(group: Id, name: string): Id | undefined {
|
|
471
|
+
return this.children(group).find((child) => this.displayName(child) === name)
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
newGroup(parent: Id, name: string, groupPath?: string): Id {
|
|
475
|
+
const group = this.#add(parent, `group ${name}`, {
|
|
476
|
+
isa: 'PBXGroup',
|
|
477
|
+
children: [],
|
|
478
|
+
name,
|
|
479
|
+
sourceTree: '<group>',
|
|
480
|
+
})
|
|
481
|
+
this.children(parent).push(group)
|
|
482
|
+
this.#parents.set(group, parent)
|
|
483
|
+
if (groupPath !== undefined) this.setPathWithSourceTree(group, groupPath, '<group>')
|
|
484
|
+
return group
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
newVariantGroup(parent: Id, name: string, groupPath: string): Id {
|
|
488
|
+
const group = this.#add(parent, `variant group ${name}`, {
|
|
489
|
+
isa: 'PBXVariantGroup',
|
|
490
|
+
children: [],
|
|
491
|
+
name,
|
|
492
|
+
sourceTree: '<group>',
|
|
493
|
+
})
|
|
494
|
+
this.children(parent).push(group)
|
|
495
|
+
this.#parents.set(group, parent)
|
|
496
|
+
this.setPathWithSourceTree(group, groupPath, '<group>')
|
|
497
|
+
return group
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** FileReferencesFactory.new_reference: a file reference with its type and defaults. */
|
|
501
|
+
newFile(group: Id, filePath: string, tree = '<group>'): Id {
|
|
502
|
+
const extension = extname(filePath)
|
|
503
|
+
if (extension === '.xcdatamodeld' || extension === '.xcodeproj')
|
|
504
|
+
throw new Error(`adding ${filePath} to the Pods project is not supported`)
|
|
505
|
+
const ref = this.#add(group, `file ${filePath}`, {
|
|
506
|
+
isa: 'PBXFileReference',
|
|
507
|
+
includeInIndex: '1',
|
|
508
|
+
sourceTree: tree,
|
|
509
|
+
})
|
|
510
|
+
this.children(group).push(ref)
|
|
511
|
+
this.#parents.set(ref, group)
|
|
512
|
+
this.setPathWithSourceTree(ref, filePath, tree)
|
|
513
|
+
const object = this.get(ref)
|
|
514
|
+
const own = this.string(ref, 'path')!
|
|
515
|
+
const type = FILE_TYPES[extname(own).slice(1)]
|
|
516
|
+
if (type) object.lastKnownFileType = type
|
|
517
|
+
if (own.includes('/')) object.name = own.split('/').at(-1)!
|
|
518
|
+
if (extname(own).toLowerCase() === '.framework') delete object.includeInIndex
|
|
519
|
+
return ref
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
markRuby(ref: Id): void {
|
|
523
|
+
Object.assign(this.get(ref), {
|
|
524
|
+
xcLanguageSpecificationIdentifier: 'xcode.lang.ruby',
|
|
525
|
+
explicitFileType: 'text.script.ruby',
|
|
526
|
+
lastKnownFileType: 'text',
|
|
527
|
+
tabWidth: '2',
|
|
528
|
+
indentWidth: '2',
|
|
529
|
+
})
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
newProductReference(basename: string, type: ProductType): Id {
|
|
533
|
+
const productPath = `${type === 'static_library' ? 'lib' : ''}${basename}.${PRODUCT_EXTENSIONS[type]}`
|
|
534
|
+
const ref = this.newFile(this.productsGroup, productPath, 'BUILT_PRODUCTS_DIR')
|
|
535
|
+
const object = this.get(ref)
|
|
536
|
+
object.includeInIndex = '0'
|
|
537
|
+
delete object.lastKnownFileType
|
|
538
|
+
const explicit =
|
|
539
|
+
type === 'bundle' ? 'wrapper.cfbundle' : FILE_TYPES[extname(productPath).slice(1)]
|
|
540
|
+
if (explicit) object.explicitFileType = explicit
|
|
541
|
+
return ref
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// Pod::Project
|
|
545
|
+
|
|
546
|
+
podGroups(): Id[] {
|
|
547
|
+
return [...this.children(this.podsGroup), ...this.children(this.developmentPodsGroup)]
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
podGroup(podName: string): Id {
|
|
551
|
+
const group = this.podGroups().find((id) => this.string(id, 'name') === podName)
|
|
552
|
+
if (!group)
|
|
553
|
+
throw new Error(`[Bug] Unable to locate group for Pod named \`${podName}\``)
|
|
554
|
+
return group
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
groupForSpec(specName: string, subgroup?: 'Resources' | 'Frameworks' | 'Pod'): Id {
|
|
558
|
+
const podName = specName.split('/')[0]!
|
|
559
|
+
let group = this.podGroup(podName)
|
|
560
|
+
if (specName !== podName)
|
|
561
|
+
for (const name of specName.slice(podName.length + 1).split('/'))
|
|
562
|
+
group = this.childNamed(group, name) ?? this.newGroup(group, name)
|
|
563
|
+
if (subgroup)
|
|
564
|
+
group = this.childNamed(group, subgroup) ?? this.newGroup(group, subgroup)
|
|
565
|
+
return group
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
podSupportFilesGroup(podName: string, dir: string): Id {
|
|
569
|
+
const group = this.podGroup(podName)
|
|
570
|
+
return (
|
|
571
|
+
this.childNamed(group, 'Support Files') ??
|
|
572
|
+
this.newGroup(group, 'Support Files', dir)
|
|
573
|
+
)
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
referenceForPath(absolute: string): Id | undefined {
|
|
577
|
+
const found = this.#refsByAbsolutePath.get(absolute)
|
|
578
|
+
if (found) return found
|
|
579
|
+
const real = this.#refsByAbsolutePath.get(realpath(absolute))
|
|
580
|
+
if (real) this.#refsByAbsolutePath.set(absolute, real)
|
|
581
|
+
return real
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
addFileReference(
|
|
585
|
+
absolute: string,
|
|
586
|
+
group: Id,
|
|
587
|
+
reflect = false,
|
|
588
|
+
basePath: string | null = null,
|
|
589
|
+
): Id {
|
|
590
|
+
const existing = this.referenceForPath(absolute)
|
|
591
|
+
if (existing) return existing
|
|
592
|
+
const parent = this.#groupForPathInGroup(absolute, group, reflect, basePath)
|
|
593
|
+
const ref = this.newFile(parent, realpath(absolute))
|
|
594
|
+
this.#refsByAbsolutePath.set(absolute, ref)
|
|
595
|
+
return ref
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
#groupForPathInGroup(
|
|
599
|
+
absolute: string,
|
|
600
|
+
start: Id,
|
|
601
|
+
reflect: boolean,
|
|
602
|
+
basePath: string | null,
|
|
603
|
+
): Id {
|
|
604
|
+
let group = start
|
|
605
|
+
const relativeBase = basePath === null ? this.realPath(group) : realpath(basePath)
|
|
606
|
+
const relativeDir = path.dirname(relativePath(absolute, relativeBase))
|
|
607
|
+
if (reflect) {
|
|
608
|
+
let groupPath = relativeBase
|
|
609
|
+
for (const name of relativeDir.split('/').filter((part) => part !== '')) {
|
|
610
|
+
if (name.toLowerCase().includes('.lproj')) break
|
|
611
|
+
if (name === '.') continue
|
|
612
|
+
groupPath = path.join(groupPath, name)
|
|
613
|
+
group = this.childNamed(group, name) ?? this.newGroup(group, name, groupPath)
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
if (path.basename(relativeDir).toLowerCase().includes('.lproj')) {
|
|
617
|
+
const name = variantGroupName(absolute)
|
|
618
|
+
const lprojParent = path.dirname(path.dirname(absolute))
|
|
619
|
+
const key = `${lprojParent}\0${name}`
|
|
620
|
+
let variant = this.#variantGroups.get(key)
|
|
621
|
+
if (!variant) {
|
|
622
|
+
variant = this.newVariantGroup(group, name, lprojParent)
|
|
623
|
+
this.#variantGroups.set(key, variant)
|
|
624
|
+
}
|
|
625
|
+
group = variant
|
|
626
|
+
}
|
|
627
|
+
return group
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// targets
|
|
631
|
+
|
|
632
|
+
targets(): Id[] {
|
|
633
|
+
return this.table.list(this.root, 'targets')
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
addSystemFramework(target: Id, name: string): void {
|
|
637
|
+
const ios =
|
|
638
|
+
this.childNamed(this.frameworksGroup, 'iOS') ??
|
|
639
|
+
this.newGroup(this.frameworksGroup, 'iOS')
|
|
640
|
+
const frameworkPath = `Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${LAST_KNOWN_IOS_SDK}.sdk/System/Library/Frameworks/${name}.framework`
|
|
641
|
+
const ref =
|
|
642
|
+
this.children(ios).find((child) => this.string(child, 'path') === frameworkPath) ??
|
|
643
|
+
this.newFile(ios, frameworkPath, 'DEVELOPER_DIR')
|
|
644
|
+
this.addBuildFile(this.phase(target, 'PBXFrameworksBuildPhase'), ref, true)
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
newPhase(target: Id, isa: string, fields: PlistDict = {}): Id {
|
|
648
|
+
const phases = this.table.list(target, 'buildPhases')
|
|
649
|
+
const phase = this.#add(target, `${isa} ${String(fields.name ?? '')}`, {
|
|
650
|
+
isa,
|
|
651
|
+
buildActionMask: '2147483647',
|
|
652
|
+
files: [],
|
|
653
|
+
runOnlyForDeploymentPostprocessing: '0',
|
|
654
|
+
...fields,
|
|
655
|
+
})
|
|
656
|
+
phases.push(phase)
|
|
657
|
+
return phase
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
findPhase(target: Id, isa: string): Id | undefined {
|
|
661
|
+
return this.table
|
|
662
|
+
.list(target, 'buildPhases')
|
|
663
|
+
.find((phase) => this.get(phase).isa === isa)
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/** find_or_create_build_phase_by_class. */
|
|
667
|
+
phase(target: Id, isa: string): Id {
|
|
668
|
+
return this.findPhase(target, isa) ?? this.newPhase(target, isa)
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
newShellScriptPhase(target: Id, name: string): Id {
|
|
672
|
+
return this.newPhase(target, 'PBXShellScriptBuildPhase', {
|
|
673
|
+
inputFileListPaths: [],
|
|
674
|
+
inputPaths: [],
|
|
675
|
+
name,
|
|
676
|
+
outputFileListPaths: [],
|
|
677
|
+
outputPaths: [],
|
|
678
|
+
shellPath: '/bin/sh',
|
|
679
|
+
shellScript:
|
|
680
|
+
'# Type a script or drag a script file from your workspace to insert its path.\n',
|
|
681
|
+
})
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
buildFileFor(phase: Id, ref: Id): Id | undefined {
|
|
685
|
+
return this.table
|
|
686
|
+
.list(phase, 'files')
|
|
687
|
+
.find((file) => this.string(file, 'fileRef') === ref)
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
addBuildFile(phase: Id, ref: Id, avoidDuplicates = false): Id {
|
|
691
|
+
if (avoidDuplicates) {
|
|
692
|
+
const existing = this.buildFileFor(phase, ref)
|
|
693
|
+
if (existing) return existing
|
|
694
|
+
}
|
|
695
|
+
const file = this.#add(phase, `build file ${ref}`, {
|
|
696
|
+
isa: 'PBXBuildFile',
|
|
697
|
+
fileRef: ref,
|
|
698
|
+
})
|
|
699
|
+
this.table.list(phase, 'files').push(file)
|
|
700
|
+
return file
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/** AbstractTarget#add_file_references. */
|
|
704
|
+
addFileReferences(
|
|
705
|
+
target: Id,
|
|
706
|
+
refs: Id[],
|
|
707
|
+
compilerFlags: string | null = null,
|
|
708
|
+
each?: (file: Id) => void,
|
|
709
|
+
): void {
|
|
710
|
+
for (const ref of refs) {
|
|
711
|
+
const header = HEADERS.has(extname(this.string(ref, 'path') ?? '').toLowerCase())
|
|
712
|
+
const phase = this.phase(
|
|
713
|
+
target,
|
|
714
|
+
header ? 'PBXHeadersBuildPhase' : 'PBXSourcesBuildPhase',
|
|
715
|
+
)
|
|
716
|
+
const file = this.buildFileFor(phase, ref) ?? this.addBuildFile(phase, ref)
|
|
717
|
+
if (compilerFlags && !header) {
|
|
718
|
+
const object = this.get(file)
|
|
719
|
+
const settings = isDict(object.settings)
|
|
720
|
+
? object.settings
|
|
721
|
+
: (object.settings = {})
|
|
722
|
+
const old =
|
|
723
|
+
typeof settings.COMPILER_FLAGS === 'string' ? settings.COMPILER_FLAGS : null
|
|
724
|
+
settings.COMPILER_FLAGS = old === null ? compilerFlags : `${old} ${compilerFlags}`
|
|
725
|
+
}
|
|
726
|
+
each?.(file)
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
addResources(target: Id, refs: Id[]): void {
|
|
731
|
+
const phase = this.phase(target, 'PBXResourcesBuildPhase')
|
|
732
|
+
for (const ref of refs)
|
|
733
|
+
if (!this.buildFileFor(phase, ref)) this.addBuildFile(phase, ref)
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
addDependency(target: Id, dependency: Id): void {
|
|
737
|
+
const dependencies = this.table.list(target, 'dependencies')
|
|
738
|
+
if (dependencies.some((id) => this.string(id, 'target') === dependency)) return
|
|
739
|
+
const name = this.string(dependency, 'name')!
|
|
740
|
+
const proxy = this.#add(target, `proxy ${dependency}`, {
|
|
741
|
+
isa: 'PBXContainerItemProxy',
|
|
742
|
+
containerPortal: this.root,
|
|
743
|
+
proxyType: '1',
|
|
744
|
+
remoteGlobalIDString: dependency,
|
|
745
|
+
remoteInfo: name,
|
|
746
|
+
})
|
|
747
|
+
dependencies.push(
|
|
748
|
+
this.#add(target, `dependency ${dependency}`, {
|
|
749
|
+
isa: 'PBXTargetDependency',
|
|
750
|
+
name,
|
|
751
|
+
target: dependency,
|
|
752
|
+
targetProxy: proxy,
|
|
753
|
+
}),
|
|
754
|
+
)
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/** ProjectHelper.configuration_list. */
|
|
758
|
+
#targetConfigurationList(
|
|
759
|
+
owner: string,
|
|
760
|
+
deploymentTarget: string | null,
|
|
761
|
+
productType: ProductType | null,
|
|
762
|
+
language: 'objc' | 'swift' | null,
|
|
763
|
+
): Id {
|
|
764
|
+
const list = this.newConfigurationList(owner)
|
|
765
|
+
this.newConfiguration(
|
|
766
|
+
list,
|
|
767
|
+
'Release',
|
|
768
|
+
commonBuildSettings('release', deploymentTarget, productType, language),
|
|
769
|
+
)
|
|
770
|
+
this.newConfiguration(
|
|
771
|
+
list,
|
|
772
|
+
'Debug',
|
|
773
|
+
commonBuildSettings('debug', deploymentTarget, productType, language),
|
|
774
|
+
)
|
|
775
|
+
for (const config of this.table.configurations(this.root)) {
|
|
776
|
+
const name = this.string(config, 'name')!
|
|
777
|
+
if (name === 'Release' || name === 'Debug') continue
|
|
778
|
+
this.newConfiguration(
|
|
779
|
+
list,
|
|
780
|
+
name,
|
|
781
|
+
commonBuildSettings(
|
|
782
|
+
this.configurationType(config),
|
|
783
|
+
deploymentTarget,
|
|
784
|
+
productType,
|
|
785
|
+
language,
|
|
786
|
+
),
|
|
787
|
+
)
|
|
788
|
+
}
|
|
789
|
+
return list
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/** ProjectHelper.new_target. */
|
|
793
|
+
newTarget(
|
|
794
|
+
type: 'framework' | 'static_library',
|
|
795
|
+
name: string,
|
|
796
|
+
deploymentTarget: string,
|
|
797
|
+
language: 'objc' | 'swift',
|
|
798
|
+
productBasename: string,
|
|
799
|
+
): Id {
|
|
800
|
+
const target = this.table.add(`target ${name}`, {
|
|
801
|
+
isa: 'PBXNativeTarget',
|
|
802
|
+
buildConfigurationList: this.#targetConfigurationList(
|
|
803
|
+
`target ${name}`,
|
|
804
|
+
deploymentTarget,
|
|
805
|
+
type,
|
|
806
|
+
language,
|
|
807
|
+
),
|
|
808
|
+
buildPhases: [],
|
|
809
|
+
buildRules: [],
|
|
810
|
+
dependencies: [],
|
|
811
|
+
name,
|
|
812
|
+
productName: productBasename,
|
|
813
|
+
productReference: this.newProductReference(productBasename, type),
|
|
814
|
+
productType: PRODUCT_UTI[type],
|
|
815
|
+
})
|
|
816
|
+
this.targets().push(target)
|
|
817
|
+
const phases = [
|
|
818
|
+
'PBXHeadersBuildPhase',
|
|
819
|
+
'PBXSourcesBuildPhase',
|
|
820
|
+
'PBXFrameworksBuildPhase',
|
|
821
|
+
]
|
|
822
|
+
if (type === 'framework') phases.push('PBXResourcesBuildPhase')
|
|
823
|
+
for (const isa of phases) this.newPhase(target, isa)
|
|
824
|
+
if (type !== 'static_library') this.addSystemFramework(target, 'Foundation')
|
|
825
|
+
return target
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/** ProjectHelper.new_resources_bundle; both configurations share one settings hash. */
|
|
829
|
+
newResourcesBundle(name: string, productBasename: string): Id {
|
|
830
|
+
const settings = commonBuildSettings(null, null, 'bundle', 'objc')
|
|
831
|
+
const list = this.newConfigurationList(`target ${name}`)
|
|
832
|
+
this.newConfiguration(list, 'Release', settings)
|
|
833
|
+
this.newConfiguration(list, 'Debug', settings)
|
|
834
|
+
const productPath = `${productBasename}.bundle`
|
|
835
|
+
const product = this.newFile(this.productsGroup, productPath, 'BUILT_PRODUCTS_DIR')
|
|
836
|
+
const productObject = this.get(product)
|
|
837
|
+
productObject.includeInIndex = '0'
|
|
838
|
+
delete productObject.lastKnownFileType
|
|
839
|
+
productObject.explicitFileType = 'wrapper.cfbundle'
|
|
840
|
+
const target = this.table.add(`target ${name}`, {
|
|
841
|
+
isa: 'PBXNativeTarget',
|
|
842
|
+
buildConfigurationList: list,
|
|
843
|
+
buildPhases: [],
|
|
844
|
+
buildRules: [],
|
|
845
|
+
dependencies: [],
|
|
846
|
+
name,
|
|
847
|
+
productName: productBasename,
|
|
848
|
+
productReference: product,
|
|
849
|
+
productType: PRODUCT_UTI.bundle,
|
|
850
|
+
})
|
|
851
|
+
this.targets().push(target)
|
|
852
|
+
for (const isa of [
|
|
853
|
+
'PBXSourcesBuildPhase',
|
|
854
|
+
'PBXFrameworksBuildPhase',
|
|
855
|
+
'PBXResourcesBuildPhase',
|
|
856
|
+
])
|
|
857
|
+
this.newPhase(target, isa)
|
|
858
|
+
return target
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
/** ProjectHelper.new_aggregate_target. */
|
|
862
|
+
newAggregateTarget(name: string, deploymentTarget: string): Id {
|
|
863
|
+
const target = this.table.add(`target ${name}`, {
|
|
864
|
+
isa: 'PBXAggregateTarget',
|
|
865
|
+
buildConfigurationList: this.#targetConfigurationList(
|
|
866
|
+
`target ${name}`,
|
|
867
|
+
deploymentTarget,
|
|
868
|
+
null,
|
|
869
|
+
null,
|
|
870
|
+
),
|
|
871
|
+
buildPhases: [],
|
|
872
|
+
dependencies: [],
|
|
873
|
+
name,
|
|
874
|
+
})
|
|
875
|
+
this.targets().push(target)
|
|
876
|
+
return target
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/** AbstractTarget#add_build_configuration. */
|
|
880
|
+
addTargetConfiguration(target: Id, name: string, type: ConfigurationType): void {
|
|
881
|
+
if (this.configurationNamed(target, name)) return
|
|
882
|
+
const object = this.get(target)
|
|
883
|
+
const productType = Object.entries(PRODUCT_UTI).find(
|
|
884
|
+
([, uti]) => uti === object.productType,
|
|
885
|
+
)?.[0]
|
|
886
|
+
const settings = commonBuildSettings(
|
|
887
|
+
type,
|
|
888
|
+
this.deploymentTarget(target),
|
|
889
|
+
productType === 'framework' ||
|
|
890
|
+
productType === 'static_library' ||
|
|
891
|
+
productType === 'bundle'
|
|
892
|
+
? productType
|
|
893
|
+
: null,
|
|
894
|
+
'objc',
|
|
895
|
+
)
|
|
896
|
+
this.newConfiguration(this.string(target, 'buildConfigurationList')!, name, settings)
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
deploymentTarget(target: Id): string | null {
|
|
900
|
+
const values = this.table
|
|
901
|
+
.configurations(target)
|
|
902
|
+
.map((config) => this.table.buildSettings(config).IPHONEOS_DEPLOYMENT_TARGET)
|
|
903
|
+
.filter((value): value is string => typeof value === 'string')
|
|
904
|
+
return values[0] ?? null
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
settingsOf(target: Id): PlistDict[] {
|
|
908
|
+
return this.table
|
|
909
|
+
.configurations(target)
|
|
910
|
+
.map((config) => this.table.buildSettings(config))
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
// String#underscore from ActiveSupport
|
|
915
|
+
function underscore(word: string): string {
|
|
916
|
+
return word
|
|
917
|
+
.replace(/::/g, '/')
|
|
918
|
+
.replace(/([A-Z\d]+)([A-Z][a-z])/g, '$1_$2')
|
|
919
|
+
.replace(/([a-z\d])([A-Z])/g, '$1_$2')
|
|
920
|
+
.replace(/-/g, '_')
|
|
921
|
+
.toLowerCase()
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// Pod::Project#variant_group_name
|
|
925
|
+
function variantGroupName(file: string): string {
|
|
926
|
+
if (!file.toLowerCase().includes('.lproj/'))
|
|
927
|
+
throw new Error('Only localized resources can be added to variant groups.')
|
|
928
|
+
if (extname(file).toLowerCase() === '.strings')
|
|
929
|
+
for (const extension of ['.xib', '.storyboard']) {
|
|
930
|
+
const candidate = path.join(
|
|
931
|
+
path.dirname(path.dirname(file)),
|
|
932
|
+
'Base.lproj',
|
|
933
|
+
`${stem(file)}${extension}`,
|
|
934
|
+
)
|
|
935
|
+
if (fs.existsSync(candidate)) return path.basename(candidate)
|
|
936
|
+
}
|
|
937
|
+
return path.basename(file)
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
// generators
|
|
941
|
+
|
|
942
|
+
const HEADER_PREAMBLE =
|
|
943
|
+
'#ifdef __OBJC__\n#import <UIKit/UIKit.h>\n#else\n#ifndef FOUNDATION_EXPORT\n#if defined(__cplusplus)\n#define FOUNDATION_EXPORT extern "C"\n#else\n#define FOUNDATION_EXPORT extern\n#endif\n#endif\n#endif\n\n'
|
|
944
|
+
|
|
945
|
+
const PLIST_HEADER =
|
|
946
|
+
'<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n'
|
|
947
|
+
|
|
948
|
+
type InfoValue = string | boolean | InfoValue[] | { [key: string]: InfoValue }
|
|
949
|
+
|
|
950
|
+
function toInfoValue(value: unknown): InfoValue | null {
|
|
951
|
+
if (typeof value === 'string' || typeof value === 'boolean') return value
|
|
952
|
+
if (Array.isArray(value))
|
|
953
|
+
return value.map(toInfoValue).filter((item): item is InfoValue => item !== null)
|
|
954
|
+
if (typeof value === 'object' && value !== null) {
|
|
955
|
+
const result: { [key: string]: InfoValue } = {}
|
|
956
|
+
for (const [key, item] of Object.entries(value)) {
|
|
957
|
+
const converted = toInfoValue(item)
|
|
958
|
+
if (converted !== null) result[key] = converted
|
|
959
|
+
}
|
|
960
|
+
return result
|
|
961
|
+
}
|
|
962
|
+
return null
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
/** Generator::InfoPlistFile. */
|
|
966
|
+
function infoPlist(
|
|
967
|
+
version: string,
|
|
968
|
+
packageType: 'fmwk' | 'bndl',
|
|
969
|
+
additional: Record<string, unknown> = {},
|
|
970
|
+
): string {
|
|
971
|
+
const info: { [key: string]: InfoValue } = {
|
|
972
|
+
CFBundleIdentifier: '${PRODUCT_BUNDLE_IDENTIFIER}',
|
|
973
|
+
CFBundleInfoDictionaryVersion: '6.0',
|
|
974
|
+
CFBundleName: '${PRODUCT_NAME}',
|
|
975
|
+
CFBundlePackageType: packageType.toUpperCase(),
|
|
976
|
+
CFBundleShortVersionString: version,
|
|
977
|
+
CFBundleSignature: '????',
|
|
978
|
+
CFBundleVersion: packageType === 'bndl' ? '1' : '${CURRENT_PROJECT_VERSION}',
|
|
979
|
+
NSPrincipalClass: '',
|
|
980
|
+
CFBundleDevelopmentRegion: '${PODS_DEVELOPMENT_LANGUAGE}',
|
|
981
|
+
}
|
|
982
|
+
if (packageType !== 'bndl') info.CFBundleExecutable = '${EXECUTABLE_NAME}'
|
|
983
|
+
for (const [key, value] of Object.entries(additional)) {
|
|
984
|
+
const converted = toInfoValue(value)
|
|
985
|
+
if (converted !== null) info[key] = converted
|
|
986
|
+
}
|
|
987
|
+
let out = PLIST_HEADER
|
|
988
|
+
const serialize = (value: InfoValue, indentation: number) => {
|
|
989
|
+
const indent = ' '.repeat(indentation)
|
|
990
|
+
if (Array.isArray(value)) {
|
|
991
|
+
out += `${indent}<array>\n`
|
|
992
|
+
for (const item of value) serialize(item, indentation + 2)
|
|
993
|
+
out += `${indent}</array>\n`
|
|
994
|
+
} else if (typeof value === 'object') {
|
|
995
|
+
out += `${indent}<dict>\n`
|
|
996
|
+
for (const key of Object.keys(value).sort(compareBytes)) {
|
|
997
|
+
out += `${indent} <key>${key}</key>\n`
|
|
998
|
+
serialize(value[key]!, indentation + 2)
|
|
999
|
+
}
|
|
1000
|
+
out += `${indent}</dict>\n`
|
|
1001
|
+
} else if (typeof value === 'string') out += `${indent}<string>${value}</string>\n`
|
|
1002
|
+
else out += `${indent}<${value}/>\n`
|
|
1003
|
+
}
|
|
1004
|
+
serialize(info, 0)
|
|
1005
|
+
return `${out}</plist>\n`
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
/** Xcodeproj::Plist's xml (Nanaimo, pretty): tab indents and sorted keys. */
|
|
1009
|
+
function xmlPlist(value: PlistValue): string {
|
|
1010
|
+
const escape = (text: string) =>
|
|
1011
|
+
text.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>')
|
|
1012
|
+
const lines = (item: PlistValue, depth: number): string => {
|
|
1013
|
+
const indent = '\t'.repeat(depth)
|
|
1014
|
+
if (typeof item === 'string') return `${indent}<string>${escape(item)}</string>\n`
|
|
1015
|
+
if (Array.isArray(item)) {
|
|
1016
|
+
if (item.length === 0) return `${indent}<array/>\n`
|
|
1017
|
+
return `${indent}<array>\n${item.map((entry) => lines(entry, depth + 1)).join('')}${indent}</array>\n`
|
|
1018
|
+
}
|
|
1019
|
+
const keys = Object.keys(item).sort(compareBytes)
|
|
1020
|
+
if (keys.length === 0) return `${indent}<dict/>\n`
|
|
1021
|
+
return `${indent}<dict>\n${keys
|
|
1022
|
+
.map(
|
|
1023
|
+
(key) => `${indent}\t<key>${escape(key)}</key>\n${lines(item[key]!, depth + 1)}`,
|
|
1024
|
+
)
|
|
1025
|
+
.join('')}${indent}</dict>\n`
|
|
1026
|
+
}
|
|
1027
|
+
return `${PLIST_HEADER}${lines(value, 0)}</plist>\n`
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
const dummySource = (label: string) => {
|
|
1031
|
+
const name = `PodsDummy_${label.replace(/[^0-9a-z_]/gi, '_')}`
|
|
1032
|
+
return `#import <Foundation/Foundation.h>\n@interface ${name} : NSObject\n@end\n@implementation ${name}\n@end\n`
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
const umbrellaHeader = (imports: string[], moduleName: string) =>
|
|
1036
|
+
`${HEADER_PREAMBLE}${imports.map((file) => `#import "${file}"\n`).join('')}\nFOUNDATION_EXPORT double ${moduleName}VersionNumber;\nFOUNDATION_EXPORT const unsigned char ${moduleName}VersionString[];\n\n`
|
|
1037
|
+
|
|
1038
|
+
const moduleMap = (framework: boolean, moduleName: string, headers: string[]) =>
|
|
1039
|
+
`${framework ? 'framework ' : ''}module ${moduleName} {\n ${headers.join('\n ')}\n\n export *\n module * { export * }\n}\n`
|
|
1040
|
+
|
|
1041
|
+
// String#strip_heredoc
|
|
1042
|
+
function stripHeredoc(text: string): string {
|
|
1043
|
+
const indents = text.match(/^[ \t]*(?=\S)/gm) ?? []
|
|
1044
|
+
if (indents.length === 0) return text
|
|
1045
|
+
const least = indents.reduce((min, indent) =>
|
|
1046
|
+
compareBytes(indent, min) < 0 ? indent : min,
|
|
1047
|
+
)
|
|
1048
|
+
return least === '' ? text : text.replace(new RegExp(`^${least}`, 'gm'), '')
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
interface License {
|
|
1052
|
+
type?: string
|
|
1053
|
+
file?: string
|
|
1054
|
+
text?: string
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
// Specification#license
|
|
1058
|
+
function normalizeLicense(raw: string | Record<string, unknown> | null): License {
|
|
1059
|
+
if (typeof raw === 'string') return { type: raw }
|
|
1060
|
+
if (!raw) return {}
|
|
1061
|
+
const field = (key: string) => (typeof raw[key] === 'string' ? raw[key] : undefined)
|
|
1062
|
+
const text = field('text')
|
|
1063
|
+
return {
|
|
1064
|
+
type: field('type'),
|
|
1065
|
+
file: field('file'),
|
|
1066
|
+
text: text === undefined ? undefined : stripHeredoc(text),
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
function licenseText(target: PodTarget): string | null {
|
|
1071
|
+
const license = normalizeLicense(target.analyzed.license)
|
|
1072
|
+
if (license.text !== undefined) return license.text
|
|
1073
|
+
const root = target.fileAccessors[0]!.root
|
|
1074
|
+
if (license.file !== undefined) {
|
|
1075
|
+
const file = path.join(root, license.file)
|
|
1076
|
+
return fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : null
|
|
1077
|
+
}
|
|
1078
|
+
const found = target.fileAccessors[0]!.pathList.glob(['licen{c,s}e{*,.*}'])[0]
|
|
1079
|
+
return found ? fs.readFileSync(found, 'utf8') : null
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
function acknowledgementTargets(aggregate: AggregateTarget): PodTarget[] {
|
|
1083
|
+
const seen = new Set<string>()
|
|
1084
|
+
return aggregate.podTargets.filter((target) => {
|
|
1085
|
+
if (seen.has(target.podName)) return false
|
|
1086
|
+
seen.add(target.podName)
|
|
1087
|
+
return true
|
|
1088
|
+
})
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
const ACKNOWLEDGEMENTS_HEADER =
|
|
1092
|
+
'This application makes use of the following third party libraries:'
|
|
1093
|
+
const ACKNOWLEDGEMENTS_FOOTNOTE = 'Generated by CocoaPods - https://cocoapods.org'
|
|
1094
|
+
|
|
1095
|
+
function acknowledgementsMarkdown(aggregate: AggregateTarget): string {
|
|
1096
|
+
let text = `# Acknowledgements\n${ACKNOWLEDGEMENTS_HEADER}\n`
|
|
1097
|
+
for (const target of acknowledgementTargets(aggregate)) {
|
|
1098
|
+
const license = licenseText(target)
|
|
1099
|
+
if (license !== null) text += `\n## ${target.podName}\n\n${license}\n`
|
|
1100
|
+
}
|
|
1101
|
+
return `${text}${ACKNOWLEDGEMENTS_FOOTNOTE}\n`
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
function acknowledgementsPlist(aggregate: AggregateTarget): string {
|
|
1105
|
+
const specifiers: PlistValue[] = [
|
|
1106
|
+
{
|
|
1107
|
+
FooterText: ACKNOWLEDGEMENTS_HEADER,
|
|
1108
|
+
Title: 'Acknowledgements',
|
|
1109
|
+
Type: 'PSGroupSpecifier',
|
|
1110
|
+
},
|
|
1111
|
+
]
|
|
1112
|
+
for (const target of acknowledgementTargets(aggregate)) {
|
|
1113
|
+
const license = licenseText(target)
|
|
1114
|
+
if (license === null) continue
|
|
1115
|
+
const type = normalizeLicense(target.analyzed.license).type
|
|
1116
|
+
specifiers.push({
|
|
1117
|
+
FooterText: license,
|
|
1118
|
+
...(type ? { License: type } : {}),
|
|
1119
|
+
Title: target.podName,
|
|
1120
|
+
Type: 'PSGroupSpecifier',
|
|
1121
|
+
})
|
|
1122
|
+
}
|
|
1123
|
+
specifiers.push({
|
|
1124
|
+
FooterText: ACKNOWLEDGEMENTS_FOOTNOTE,
|
|
1125
|
+
Title: '',
|
|
1126
|
+
Type: 'PSGroupSpecifier',
|
|
1127
|
+
})
|
|
1128
|
+
return xmlPlist({
|
|
1129
|
+
PreferenceSpecifiers: specifiers,
|
|
1130
|
+
StringsTable: 'Acknowledgements',
|
|
1131
|
+
Title: 'Acknowledgements',
|
|
1132
|
+
})
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
const XCFRAMEWORKS_BUILD_DIR = '${PODS_XCFRAMEWORKS_BUILD_DIR}'
|
|
1136
|
+
|
|
1137
|
+
/** Generator::EmbedFrameworksScript. */
|
|
1138
|
+
function embedFrameworksScript(aggregate: AggregateTarget): string {
|
|
1139
|
+
const frameworks = aggregate.frameworkPathsByConfig()
|
|
1140
|
+
const xcframeworks = aggregate.xcframeworksByConfig()
|
|
1141
|
+
let script = EMBED_FRAMEWORKS_HEADER
|
|
1142
|
+
const any =
|
|
1143
|
+
[...frameworks.values()].some((list) => list.length > 0) ||
|
|
1144
|
+
[...xcframeworks.values()].some((list) => list.length > 0)
|
|
1145
|
+
if (any) script += '\n'
|
|
1146
|
+
for (const config of [...frameworks.keys()].sort(compareBytes)) {
|
|
1147
|
+
const paths = frameworks.get(config) ?? []
|
|
1148
|
+
const vendored = xcframeworks.get(config) ?? []
|
|
1149
|
+
if (paths.length === 0 && vendored.length === 0) continue
|
|
1150
|
+
script += `if [[ "$CONFIGURATION" == "${config}" ]]; then\n`
|
|
1151
|
+
for (const framework of paths)
|
|
1152
|
+
script += ` install_framework "${framework.sourcePath}"\n`
|
|
1153
|
+
for (const xcframework of vendored)
|
|
1154
|
+
if (xcframework.dynamic && xcframework.packaging === 'framework')
|
|
1155
|
+
script += ` install_framework "${XCFRAMEWORKS_BUILD_DIR}/${xcframework.targetName}/${xcframework.name}.framework"\n`
|
|
1156
|
+
script += 'fi\n'
|
|
1157
|
+
}
|
|
1158
|
+
return `${script}if [ "\${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then\n wait\nfi\n`
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
/** Generator::CopyResourcesScript. */
|
|
1162
|
+
function copyResourcesScript(
|
|
1163
|
+
resourcesByConfig: Map<string, string[]>,
|
|
1164
|
+
deploymentTarget: string,
|
|
1165
|
+
): string {
|
|
1166
|
+
let script = versionLess(deploymentTarget, '6.0')
|
|
1167
|
+
? INSTALL_RESOURCES_FUNCTION.replaceAll(' --reference-external-strings-file', '')
|
|
1168
|
+
: INSTALL_RESOURCES_FUNCTION
|
|
1169
|
+
for (const [config, resources] of resourcesByConfig) {
|
|
1170
|
+
if (resources.length === 0) continue
|
|
1171
|
+
script += `if [[ "$CONFIGURATION" == "${config}" ]]; then\n`
|
|
1172
|
+
for (const resource of resources) script += ` install_resource "${resource}"\n`
|
|
1173
|
+
script += 'fi\n'
|
|
1174
|
+
}
|
|
1175
|
+
return script + RESOURCES_TAIL
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
/** Generator::CopyXCFrameworksScript. */
|
|
1179
|
+
function copyXcframeworksScript(
|
|
1180
|
+
xcframeworks: XCFramework[],
|
|
1181
|
+
sandboxRoot: string,
|
|
1182
|
+
targetPlatform: string,
|
|
1183
|
+
): string {
|
|
1184
|
+
const quote = (value: string) => `"${value}"`
|
|
1185
|
+
const sliceDir = (xcframework: XCFramework, slicePath: string) =>
|
|
1186
|
+
relativePath(path.dirname(slicePath), xcframework.path)
|
|
1187
|
+
const caseBlock = (
|
|
1188
|
+
name: string,
|
|
1189
|
+
value: (slice: XCFramework['slices'][number]) => string,
|
|
1190
|
+
) => {
|
|
1191
|
+
let block = `${name}()\n{\n case "$1" in\n`
|
|
1192
|
+
for (const xcframework of xcframeworks)
|
|
1193
|
+
for (const slice of xcframework.slices) {
|
|
1194
|
+
block += ` ${quote(path.join(path.basename(xcframework.path), sliceDir(xcframework, slice.path)))})\n`
|
|
1195
|
+
block += ` echo ${value(slice)}\n ;;\n`
|
|
1196
|
+
}
|
|
1197
|
+
return `${block} esac\n}`
|
|
1198
|
+
}
|
|
1199
|
+
let script = COPY_XCFRAMEWORKS_HEADER
|
|
1200
|
+
script += caseBlock('variant_for_slice', (slice) =>
|
|
1201
|
+
slice.platformVariant ? quote(slice.platformVariant) : '""',
|
|
1202
|
+
)
|
|
1203
|
+
script += '\n\n'
|
|
1204
|
+
script += caseBlock('archs_for_slice', (slice) =>
|
|
1205
|
+
quote([...slice.supportedArchs].sort(compareBytes).join(' ')),
|
|
1206
|
+
)
|
|
1207
|
+
script += COPY_XCFRAMEWORKS_BODY
|
|
1208
|
+
for (const xcframework of xcframeworks) {
|
|
1209
|
+
const slices = xcframework.slices.filter((slice) => slice.platform === targetPlatform)
|
|
1210
|
+
if (slices.length === 0) continue
|
|
1211
|
+
const args = [
|
|
1212
|
+
`\${PODS_ROOT}/${relativePath(xcframework.path, sandboxRoot)}`,
|
|
1213
|
+
xcframework.targetName,
|
|
1214
|
+
xcframework.packaging,
|
|
1215
|
+
...slices.map((slice) => sliceDir(xcframework, slice.path)),
|
|
1216
|
+
]
|
|
1217
|
+
script += `install_xcframework ${args.map(quote).join(' ')}\n`
|
|
1218
|
+
}
|
|
1219
|
+
if (xcframeworks.length > 0) script += '\n'
|
|
1220
|
+
return script
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
// FileAccessor#developer_files
|
|
1224
|
+
|
|
1225
|
+
function rubyPathCompare(a: string, b: string): number {
|
|
1226
|
+
return compareBytes(a.replaceAll('/', '\0'), b.replaceAll('/', '\0'))
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
function developerFiles(target: PodTarget, accessor: FileAccessor): string[] {
|
|
1230
|
+
const license = normalizeLicense(target.analyzed.license)
|
|
1231
|
+
const specLicense =
|
|
1232
|
+
license.file !== undefined && fs.existsSync(path.join(accessor.root, license.file))
|
|
1233
|
+
? path.join(accessor.root, license.file)
|
|
1234
|
+
: null
|
|
1235
|
+
const result: (string | null)[] = [accessor.moduleMap, accessor.prefixHeader]
|
|
1236
|
+
const podspecs = accessor.pathList.glob(['*.{podspec,podspec.json}'])
|
|
1237
|
+
if (podspecs.length <= 1)
|
|
1238
|
+
result.push(
|
|
1239
|
+
specLicense ?? accessor.pathList.glob(['licen{c,s}e{*,.*}'])[0] ?? null,
|
|
1240
|
+
accessor.pathList.glob(['readme{*,.*}'])[0] ?? null,
|
|
1241
|
+
...podspecs,
|
|
1242
|
+
...accessor.pathList.glob(['doc{s}{*,.*}/**/*']),
|
|
1243
|
+
)
|
|
1244
|
+
else {
|
|
1245
|
+
const name = accessor.specName
|
|
1246
|
+
result.push(
|
|
1247
|
+
podspecs.find((file) => path.basename(file, path.extname(file)) === name) ?? null,
|
|
1248
|
+
specLicense,
|
|
1249
|
+
)
|
|
1250
|
+
}
|
|
1251
|
+
return result.filter((file): file is string => file !== null).sort(rubyPathCompare)
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
// FileReferencesInstaller
|
|
1255
|
+
|
|
1256
|
+
function commonPath(paths: string[]): string | null {
|
|
1257
|
+
if (paths.length === 0) return null
|
|
1258
|
+
const dirs = paths.map((file) => path.dirname(file))
|
|
1259
|
+
const sorted = [...dirs].sort(compareBytes)
|
|
1260
|
+
const min = sorted[0]!.split('/')
|
|
1261
|
+
const max = sorted.at(-1)!.split('/')
|
|
1262
|
+
let index = 0
|
|
1263
|
+
while (index < min.length && min[index] === max[index]) index++
|
|
1264
|
+
const result = min.slice(0, index).join('/')
|
|
1265
|
+
return result === '' || result === '/' ? null : result
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
const isDirectory = (file: string) =>
|
|
1269
|
+
fs.existsSync(file) && fs.statSync(file).isDirectory()
|
|
1270
|
+
|
|
1271
|
+
function allowableProjectPaths(paths: string[]): string[] {
|
|
1272
|
+
const doccFolders: string[] = []
|
|
1273
|
+
const merged = paths.filter((file) => {
|
|
1274
|
+
if (!/\.docc(\/|$)/i.test(file)) return true
|
|
1275
|
+
if (isDirectory(file)) return false
|
|
1276
|
+
const folder = `${file.split('.docc')[0]}.docc`
|
|
1277
|
+
if (!doccFolders.includes(folder)) doccFolders.push(folder)
|
|
1278
|
+
return false
|
|
1279
|
+
})
|
|
1280
|
+
const lprojPaths: string[] = []
|
|
1281
|
+
const lprojWithFiles = new Set<string>()
|
|
1282
|
+
const allowed = [...merged, ...doccFolders].filter((file) => {
|
|
1283
|
+
if (/.*\.xcdatamodeld\/.+/i.test(file)) return false
|
|
1284
|
+
if (/.*\.xcmappingmodel\/.+/i.test(file)) return false
|
|
1285
|
+
if (/.*\.xcassets\/.+/i.test(file)) return false
|
|
1286
|
+
if (/\.lproj(\/|$)/i.test(file)) {
|
|
1287
|
+
if (/\.lproj$/i.test(file) && isDirectory(file)) {
|
|
1288
|
+
if (!lprojPaths.includes(file)) lprojPaths.push(file)
|
|
1289
|
+
return false
|
|
1290
|
+
}
|
|
1291
|
+
lprojWithFiles.add(/(^.*\.lproj)\/.*/i.exec(file)![1]!)
|
|
1292
|
+
}
|
|
1293
|
+
return true
|
|
1294
|
+
})
|
|
1295
|
+
return [...allowed, ...lprojPaths.filter((dir) => !lprojWithFiles.has(dir))]
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
function installFileReferences(project: PodsProject, targets: PodTarget[]): void {
|
|
1299
|
+
const accessors = targets.flatMap((target) =>
|
|
1300
|
+
target.fileAccessors.map((accessor) => ({ target, accessor })),
|
|
1301
|
+
)
|
|
1302
|
+
const addPaths = (
|
|
1303
|
+
pathsOf: (accessor: FileAccessor) => string[],
|
|
1304
|
+
subgroup: 'Resources' | 'Frameworks' | undefined,
|
|
1305
|
+
reflect: boolean,
|
|
1306
|
+
): Id[] =>
|
|
1307
|
+
accessors.flatMap(({ target, accessor }) => {
|
|
1308
|
+
const paths = allowableProjectPaths(pathsOf(accessor))
|
|
1309
|
+
if (paths.length === 0) return []
|
|
1310
|
+
const preserve = target.analyzed.local !== null && reflect
|
|
1311
|
+
const base = preserve ? commonPath(paths) : null
|
|
1312
|
+
const group = project.groupForSpec(
|
|
1313
|
+
accessor.specName,
|
|
1314
|
+
preserve ? undefined : subgroup,
|
|
1315
|
+
)
|
|
1316
|
+
return paths.map((file) => project.addFileReference(file, group, preserve, base))
|
|
1317
|
+
})
|
|
1318
|
+
addPaths((accessor) => accessor.sourceFiles, undefined, true)
|
|
1319
|
+
addPaths((accessor) => accessor.vendoredFrameworks, 'Frameworks', false)
|
|
1320
|
+
addPaths((accessor) => accessor.vendoredLibraries, 'Frameworks', false)
|
|
1321
|
+
const resourceRefs = [
|
|
1322
|
+
...addPaths((accessor) => accessor.resources, 'Resources', true),
|
|
1323
|
+
...addPaths(
|
|
1324
|
+
(accessor) => Object.values(accessor.resourceBundles).flat(),
|
|
1325
|
+
'Resources',
|
|
1326
|
+
true,
|
|
1327
|
+
),
|
|
1328
|
+
]
|
|
1329
|
+
const regions = resourceRefs
|
|
1330
|
+
.map(
|
|
1331
|
+
(ref) =>
|
|
1332
|
+
LOCALIZATION_REGION.exec(project.string(ref, 'path') ?? '')?.groups?.region,
|
|
1333
|
+
)
|
|
1334
|
+
.filter((region): region is string => region !== undefined)
|
|
1335
|
+
const root = project.get(project.root)
|
|
1336
|
+
const known = Array.isArray(root.knownRegions)
|
|
1337
|
+
? root.knownRegions.filter((r) => typeof r === 'string')
|
|
1338
|
+
: []
|
|
1339
|
+
root.knownRegions = [...new Set([...known, ...regions])].sort(compareBytes)
|
|
1340
|
+
if (targets.some((target) => target.analyzed.local !== null))
|
|
1341
|
+
for (const { target, accessor } of accessors) {
|
|
1342
|
+
if (target.analyzed.local === null) continue
|
|
1343
|
+
const paths = developerFiles(target, accessor)
|
|
1344
|
+
if (paths.length === 0) continue
|
|
1345
|
+
const group = project.groupForSpec(target.podName, 'Pod')
|
|
1346
|
+
for (const file of paths) {
|
|
1347
|
+
const ref = project.addFileReference(file, group, false)
|
|
1348
|
+
if (extname(file) === '.podspec') project.markRuby(ref)
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
// PodTargetInstaller
|
|
1354
|
+
|
|
1355
|
+
const COMPILABLE_RESOURCES = new Set([
|
|
1356
|
+
'.storyboard',
|
|
1357
|
+
'.xib',
|
|
1358
|
+
'.xcdatamodel',
|
|
1359
|
+
'.xcdatamodeld',
|
|
1360
|
+
'.xcmappingmodel',
|
|
1361
|
+
])
|
|
1362
|
+
|
|
1363
|
+
interface InstallContext {
|
|
1364
|
+
project: PodsProject
|
|
1365
|
+
settings: PodsBuildSettings
|
|
1366
|
+
sandboxRoot: string
|
|
1367
|
+
files: string[]
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
function writeSupportFile(
|
|
1371
|
+
context: InstallContext,
|
|
1372
|
+
file: string,
|
|
1373
|
+
contents: string,
|
|
1374
|
+
script = false,
|
|
1375
|
+
): void {
|
|
1376
|
+
fs.mkdirSync(path.dirname(file), { recursive: true })
|
|
1377
|
+
const text = script && !contents.endsWith('\n') ? `${contents}\n` : contents
|
|
1378
|
+
fs.writeFileSync(file, text)
|
|
1379
|
+
if (script) fs.chmodSync(file, 0o755)
|
|
1380
|
+
context.files.push(file)
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
function linkSupportFile(context: InstallContext, written: string, linked: string): void {
|
|
1384
|
+
if (written === linked) return
|
|
1385
|
+
fs.mkdirSync(path.dirname(linked), { recursive: true })
|
|
1386
|
+
fs.rmSync(linked, { force: true })
|
|
1387
|
+
fs.symlinkSync(relativePath(written, path.dirname(linked)), linked)
|
|
1388
|
+
context.files.push(linked)
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
interface PodInstallation {
|
|
1392
|
+
target: PodTarget
|
|
1393
|
+
nativeTarget: Id
|
|
1394
|
+
resourceBundleTargets: Id[]
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
function installPodTarget(
|
|
1398
|
+
context: InstallContext,
|
|
1399
|
+
target: PodTarget,
|
|
1400
|
+
umbrellaHeaderPaths: string[] | undefined,
|
|
1401
|
+
): PodInstallation {
|
|
1402
|
+
const { project, settings, sandboxRoot } = context
|
|
1403
|
+
const deploymentTarget = target.platform.deploymentTarget
|
|
1404
|
+
fs.mkdirSync(target.supportFilesDir, { recursive: true })
|
|
1405
|
+
let supportGroup: Id | undefined
|
|
1406
|
+
const addToSupportGroup = (file: string) => {
|
|
1407
|
+
supportGroup ??= project.podSupportFilesGroup(target.podName, target.supportFilesDir)
|
|
1408
|
+
return project.newFile(supportGroup, file)
|
|
1409
|
+
}
|
|
1410
|
+
const overrideKeys = (type: ConfigurationType) => [
|
|
1411
|
+
...settings.pod(target, type).mergedPodTargetXcconfigs().keys(),
|
|
1412
|
+
]
|
|
1413
|
+
const removeOverrides = (owner: Id) => {
|
|
1414
|
+
for (const config of project.table.configurations(owner)) {
|
|
1415
|
+
const type = target.userBuildConfigurations[project.string(config, 'name')!]
|
|
1416
|
+
if (!type) continue
|
|
1417
|
+
const buildSettings = project.table.buildSettings(config)
|
|
1418
|
+
for (const key of overrideKeys(type)) delete buildSettings[key]
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
const addUserConfigurations = (owner: Id) => {
|
|
1422
|
+
for (const [name, type] of Object.entries(target.userBuildConfigurations))
|
|
1423
|
+
project.addTargetConfiguration(owner, name, type)
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
let nativeTarget: Id
|
|
1427
|
+
if (target.shouldBuild) {
|
|
1428
|
+
nativeTarget = project.newTarget(
|
|
1429
|
+
target.buildAsFramework ? 'framework' : 'static_library',
|
|
1430
|
+
target.label,
|
|
1431
|
+
deploymentTarget,
|
|
1432
|
+
target.usesSwift ? 'swift' : 'objc',
|
|
1433
|
+
target.productBasename,
|
|
1434
|
+
)
|
|
1435
|
+
project.get(project.string(nativeTarget, 'productReference')!).name = target.label
|
|
1436
|
+
addUserConfigurations(nativeTarget)
|
|
1437
|
+
const custom: PlistDict = {}
|
|
1438
|
+
if (target.buildAsStaticFramework) custom.MACH_O_TYPE = 'staticlib'
|
|
1439
|
+
else if (target.buildAsStaticLibrary)
|
|
1440
|
+
Object.assign(custom, { OTHER_LDFLAGS: '', OTHER_LIBTOOLFLAGS: '' })
|
|
1441
|
+
custom.ENABLE_USER_SCRIPT_SANDBOXING = 'NO'
|
|
1442
|
+
custom.ENABLE_MODULE_VERIFIER = 'NO'
|
|
1443
|
+
if (!target.buildAsFramework)
|
|
1444
|
+
Object.assign(custom, {
|
|
1445
|
+
PRIVATE_HEADERS_FOLDER_PATH: '',
|
|
1446
|
+
PUBLIC_HEADERS_FOLDER_PATH: '',
|
|
1447
|
+
})
|
|
1448
|
+
Object.assign(custom, {
|
|
1449
|
+
PRODUCT_NAME: target.productBasename,
|
|
1450
|
+
PRODUCT_MODULE_NAME: target.productModuleName,
|
|
1451
|
+
'CODE_SIGN_IDENTITY[sdk=appletvos*]': '',
|
|
1452
|
+
'CODE_SIGN_IDENTITY[sdk=iphoneos*]': '',
|
|
1453
|
+
'CODE_SIGN_IDENTITY[sdk=watchos*]': '',
|
|
1454
|
+
SWIFT_ACTIVE_COMPILATION_CONDITIONS: '$(inherited) ',
|
|
1455
|
+
GENERATE_INFOPLIST_FILE: 'NO',
|
|
1456
|
+
SWIFT_INSTALL_OBJC_HEADER: 'YES',
|
|
1457
|
+
})
|
|
1458
|
+
if (target.swiftVersion !== null) custom.SWIFT_VERSION = target.swiftVersion
|
|
1459
|
+
const bundleId = target.analyzed.infoPlist.CFBundleIdentifier
|
|
1460
|
+
if (typeof bundleId === 'string') custom.PRODUCT_BUNDLE_IDENTIFIER = bundleId
|
|
1461
|
+
for (const buildSettings of project.settingsOf(nativeTarget))
|
|
1462
|
+
Object.assign(buildSettings, deepCopy(custom))
|
|
1463
|
+
removeOverrides(nativeTarget)
|
|
1464
|
+
} else {
|
|
1465
|
+
nativeTarget = project.newAggregateTarget(target.label, deploymentTarget)
|
|
1466
|
+
addUserConfigurations(nativeTarget)
|
|
1467
|
+
for (const buildSettings of project.settingsOf(nativeTarget))
|
|
1468
|
+
buildSettings.ENABLE_USER_SCRIPT_SANDBOXING = 'NO'
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
const referenceFor = (file: string, kind: string) => {
|
|
1472
|
+
const ref = project.referenceForPath(file)
|
|
1473
|
+
if (!ref)
|
|
1474
|
+
throw new Error(
|
|
1475
|
+
`Unable to find ${kind} ref for \`${path.basename(file)}\` for target \`${target.name}\`.`,
|
|
1476
|
+
)
|
|
1477
|
+
return ref
|
|
1478
|
+
}
|
|
1479
|
+
const filterResources = (files: string[]) => {
|
|
1480
|
+
const refs: Id[] = []
|
|
1481
|
+
for (const file of files) {
|
|
1482
|
+
const ref = project.referenceForPath(file)
|
|
1483
|
+
if (!ref) continue
|
|
1484
|
+
const parent = project.parent(ref)
|
|
1485
|
+
const chosen =
|
|
1486
|
+
parent && project.get(parent).isa === 'PBXVariantGroup' ? parent : ref
|
|
1487
|
+
if (!refs.includes(chosen)) refs.push(chosen)
|
|
1488
|
+
}
|
|
1489
|
+
const compile = refs.filter((ref) =>
|
|
1490
|
+
/.*\.(xcdatamodeld|rcproject)/i.test(project.string(ref, 'path') ?? ''),
|
|
1491
|
+
)
|
|
1492
|
+
return { compile, resources: refs.filter((ref) => !compile.includes(ref)) }
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
const resourceBundleTargets: Id[] = []
|
|
1496
|
+
for (const accessor of target.fileAccessors)
|
|
1497
|
+
for (const [bundle, paths] of Object.entries(accessor.resourceBundles)) {
|
|
1498
|
+
const label = target.resourcesBundleTargetLabel(bundle)
|
|
1499
|
+
const bundleTarget = project.newResourcesBundle(label, bundle)
|
|
1500
|
+
project.get(project.string(bundleTarget, 'productReference')!).name = label
|
|
1501
|
+
const { compile, resources } = filterResources(paths)
|
|
1502
|
+
project.addResources(bundleTarget, [...resources, ...compile])
|
|
1503
|
+
addUserConfigurations(bundleTarget)
|
|
1504
|
+
for (const buildSettings of project.settingsOf(bundleTarget))
|
|
1505
|
+
buildSettings.IPHONEOS_DEPLOYMENT_TARGET = deploymentTarget
|
|
1506
|
+
const infoPath = path.join(
|
|
1507
|
+
path.dirname(target.infoPlistPath),
|
|
1508
|
+
`ResourceBundle-${bundle}-${path.basename(target.infoPlistPath)}`,
|
|
1509
|
+
)
|
|
1510
|
+
writeSupportFile(context, infoPath, infoPlist(target.version, 'bndl'))
|
|
1511
|
+
for (const buildSettings of project.settingsOf(bundleTarget))
|
|
1512
|
+
buildSettings.INFOPLIST_FILE = relativePath(infoPath, sandboxRoot)
|
|
1513
|
+
addToSupportGroup(infoPath)
|
|
1514
|
+
const swift =
|
|
1515
|
+
compile.length > 0 &&
|
|
1516
|
+
target.fileAccessors.some((fa) => target.usesSwiftForSpec(fa.specName))
|
|
1517
|
+
for (const buildSettings of project.settingsOf(bundleTarget)) {
|
|
1518
|
+
buildSettings.PRODUCT_NAME = bundle
|
|
1519
|
+
buildSettings.CONFIGURATION_BUILD_DIR = target.configurationBuildDir(
|
|
1520
|
+
'$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)',
|
|
1521
|
+
)
|
|
1522
|
+
buildSettings.IBSC_MODULE = target.productModuleName
|
|
1523
|
+
buildSettings.CODE_SIGNING_ALLOWED = 'NO'
|
|
1524
|
+
if (swift && target.swiftVersion !== null)
|
|
1525
|
+
buildSettings.SWIFT_VERSION = target.swiftVersion
|
|
1526
|
+
buildSettings.TARGETED_DEVICE_FAMILY = '1,2'
|
|
1527
|
+
}
|
|
1528
|
+
removeOverrides(bundleTarget)
|
|
1529
|
+
resourceBundleTargets.push(bundleTarget)
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
if (target.shouldBuild)
|
|
1533
|
+
for (const accessor of target.fileAccessors) {
|
|
1534
|
+
const spec = target.specs.find((candidate) => candidate.name === accessor.specName)!
|
|
1535
|
+
const consumer = accessor.consumer
|
|
1536
|
+
const headers = accessor.headers
|
|
1537
|
+
const publicHeaders = new Set(accessor.publicHeaders().map(realpath))
|
|
1538
|
+
const projectHeaders = new Set(accessor.projectHeaders.map(realpath))
|
|
1539
|
+
const privateHeaders = new Set(accessor.privateHeaders.map(realpath))
|
|
1540
|
+
const otherSources = accessor.sourceFiles.filter(
|
|
1541
|
+
(file) => !SOURCES.has(extname(file)),
|
|
1542
|
+
)
|
|
1543
|
+
const excluded = new Set([...headers, ...otherSources])
|
|
1544
|
+
const compilerFlags = (arc: boolean, language: 'objc' | 'swift') => {
|
|
1545
|
+
const flags = [...consumer.compiler_flags]
|
|
1546
|
+
if (!arc && language === 'objc') flags.push('-fno-objc-arc')
|
|
1547
|
+
else if (
|
|
1548
|
+
spec.deploymentTarget === null ||
|
|
1549
|
+
versionLess(spec.deploymentTarget, '6')
|
|
1550
|
+
)
|
|
1551
|
+
flags.push('-DOS_OBJECT_USE_OBJC=0')
|
|
1552
|
+
if (target.inhibitWarnings && language === 'objc')
|
|
1553
|
+
flags.push('-w -Xanalyzer -analyzer-disable-all-checks')
|
|
1554
|
+
return flags.join(' ')
|
|
1555
|
+
}
|
|
1556
|
+
const byArc: [boolean, string[]][] = [
|
|
1557
|
+
[true, accessor.arcSourceFiles],
|
|
1558
|
+
[false, accessor.nonArcSourceFiles],
|
|
1559
|
+
]
|
|
1560
|
+
for (const [arc, files] of byArc) {
|
|
1561
|
+
if (files.length === 0) continue
|
|
1562
|
+
const sources = files.filter((file) => !excluded.has(file))
|
|
1563
|
+
const byLanguage: ['objc' | 'swift', string[]][] = [
|
|
1564
|
+
['objc', sources.filter((file) => extname(file) !== '.swift')],
|
|
1565
|
+
['swift', sources.filter((file) => extname(file) === '.swift')],
|
|
1566
|
+
]
|
|
1567
|
+
for (const [language, list] of byLanguage)
|
|
1568
|
+
project.addFileReferences(
|
|
1569
|
+
nativeTarget,
|
|
1570
|
+
list.map((file) => referenceFor(file, 'source')),
|
|
1571
|
+
compilerFlags(arc, language),
|
|
1572
|
+
)
|
|
1573
|
+
}
|
|
1574
|
+
const mappingsDir = consumer.header_mappings_dir
|
|
1575
|
+
? path.join(accessor.root, consumer.header_mappings_dir)
|
|
1576
|
+
: null
|
|
1577
|
+
project.addFileReferences(
|
|
1578
|
+
nativeTarget,
|
|
1579
|
+
headers.map((file) => referenceFor(file, 'header')),
|
|
1580
|
+
null,
|
|
1581
|
+
(buildFile) => {
|
|
1582
|
+
const ref = project.string(buildFile, 'fileRef')!
|
|
1583
|
+
const real = project.realPath(ref)
|
|
1584
|
+
const acl = !target.buildAsFramework
|
|
1585
|
+
? 'Project'
|
|
1586
|
+
: publicHeaders.has(real)
|
|
1587
|
+
? 'Public'
|
|
1588
|
+
: projectHeaders.has(real)
|
|
1589
|
+
? 'Project'
|
|
1590
|
+
: privateHeaders.has(real)
|
|
1591
|
+
? 'Private'
|
|
1592
|
+
: 'Project'
|
|
1593
|
+
if (target.buildAsFramework && mappingsDir && acl !== 'Project') {
|
|
1594
|
+
const phases = project.table.list(nativeTarget, 'buildPhases')
|
|
1595
|
+
const compileIndex = phases.findIndex(
|
|
1596
|
+
(phase) => project.get(phase).isa === 'PBXSourcesBuildPhase',
|
|
1597
|
+
)
|
|
1598
|
+
const subDir = path.dirname(relativePath(real, mappingsDir))
|
|
1599
|
+
const name = `Copy ${subDir} ${acl} Headers`
|
|
1600
|
+
const copyPhase =
|
|
1601
|
+
phases.find(
|
|
1602
|
+
(phase) =>
|
|
1603
|
+
project.get(phase).isa === 'PBXCopyFilesBuildPhase' &&
|
|
1604
|
+
project.string(phase, 'name') === name,
|
|
1605
|
+
) ??
|
|
1606
|
+
project.newPhase(nativeTarget, 'PBXCopyFilesBuildPhase', {
|
|
1607
|
+
dstPath: '',
|
|
1608
|
+
dstSubfolderSpec: '7',
|
|
1609
|
+
name,
|
|
1610
|
+
})
|
|
1611
|
+
if (compileIndex !== -1) moveTo(phases, copyPhase, compileIndex - 1)
|
|
1612
|
+
Object.assign(project.get(copyPhase), {
|
|
1613
|
+
dstSubfolderSpec: '16',
|
|
1614
|
+
dstPath: `$(${acl.toUpperCase()}_HEADERS_FOLDER_PATH)/${subDir}`,
|
|
1615
|
+
})
|
|
1616
|
+
project.addBuildFile(copyPhase, ref, true)
|
|
1617
|
+
} else project.get(buildFile).settings = { ATTRIBUTES: [acl] }
|
|
1618
|
+
},
|
|
1619
|
+
)
|
|
1620
|
+
project.addFileReferences(
|
|
1621
|
+
nativeTarget,
|
|
1622
|
+
otherSources.map((file) => referenceFor(file, 'other source')),
|
|
1623
|
+
)
|
|
1624
|
+
if (!target.buildAsFramework) continue
|
|
1625
|
+
const { compile, resources } = filterResources(accessor.resources)
|
|
1626
|
+
project.addFileReferences(nativeTarget, compile)
|
|
1627
|
+
project.addResources(
|
|
1628
|
+
nativeTarget,
|
|
1629
|
+
target.buildAsStaticFramework
|
|
1630
|
+
? resources.filter((ref) =>
|
|
1631
|
+
COMPILABLE_RESOURCES.has(
|
|
1632
|
+
extname(project.string(ref, 'name') ?? project.string(ref, 'path') ?? ''),
|
|
1633
|
+
),
|
|
1634
|
+
)
|
|
1635
|
+
: resources,
|
|
1636
|
+
)
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
if (
|
|
1640
|
+
target.shouldBuild &&
|
|
1641
|
+
project.table.list(project.phase(nativeTarget, 'PBXSourcesBuildPhase'), 'files')
|
|
1642
|
+
.length === 0
|
|
1643
|
+
)
|
|
1644
|
+
throw new Error(
|
|
1645
|
+
`Unable to install the \`${target.name}\` pod, because the \`${target.name}\` target in Xcode would have no sources to compile.`,
|
|
1646
|
+
)
|
|
1647
|
+
|
|
1648
|
+
const xcframeworks = [...target.xcframeworks.values()].flat()
|
|
1649
|
+
if (xcframeworks.length > 0) {
|
|
1650
|
+
writeSupportFile(
|
|
1651
|
+
context,
|
|
1652
|
+
target.copyXcframeworksScriptPath,
|
|
1653
|
+
copyXcframeworksScript(xcframeworks, sandboxRoot, target.platform.name),
|
|
1654
|
+
true,
|
|
1655
|
+
)
|
|
1656
|
+
addToSupportGroup(target.copyXcframeworksScriptPath)
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
const namesByType = new Map<ConfigurationType, string[]>()
|
|
1660
|
+
for (const [name, type] of Object.entries(target.userBuildConfigurations))
|
|
1661
|
+
namesByType.set(type, [...(namesByType.get(type) ?? []), name])
|
|
1662
|
+
const xcconfigs = new Map<ConfigurationType, XcodeConfig>()
|
|
1663
|
+
for (const [type, names] of namesByType) {
|
|
1664
|
+
const xcconfig = settings.pod(target, type).xcconfig()
|
|
1665
|
+
xcconfigs.set(type, xcconfig)
|
|
1666
|
+
const file = target.xcconfigPath(type)
|
|
1667
|
+
writeSupportFile(context, file, xcconfig.toString())
|
|
1668
|
+
const ref = addToSupportGroup(file)
|
|
1669
|
+
for (const owner of [nativeTarget, ...resourceBundleTargets])
|
|
1670
|
+
for (const config of project.table.configurations(owner))
|
|
1671
|
+
if (names.includes(project.string(config, 'name')!))
|
|
1672
|
+
project.get(config).baseConfigurationReference = ref
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
const customModuleMap = target.fileAccessors[0]?.moduleMap ?? null
|
|
1676
|
+
if (
|
|
1677
|
+
target.shouldBuild &&
|
|
1678
|
+
target.definesModule &&
|
|
1679
|
+
!target.specs.some((spec) => spec.consumer.module_map === false)
|
|
1680
|
+
) {
|
|
1681
|
+
const moduleMapToWrite = path.join(
|
|
1682
|
+
target.supportFilesDir,
|
|
1683
|
+
`${target.label}.modulemap`,
|
|
1684
|
+
)
|
|
1685
|
+
const contents = customModuleMap
|
|
1686
|
+
? target.buildAsFramework
|
|
1687
|
+
? fs.readFileSync(customModuleMap, 'utf8')
|
|
1688
|
+
: fs
|
|
1689
|
+
.readFileSync(customModuleMap, 'utf8')
|
|
1690
|
+
.replace(/^(\s*)framework\s+(module[^{}]+){/gm, '$1$2{')
|
|
1691
|
+
: moduleMap(target.buildAsFramework, target.productModuleName, [
|
|
1692
|
+
`umbrella header "${path.basename(target.umbrellaHeaderPath)}"`,
|
|
1693
|
+
...(umbrellaHeaderPaths ?? [])
|
|
1694
|
+
.filter((other) => other !== target.umbrellaHeaderPath)
|
|
1695
|
+
.map((other) => `exclude header "${path.basename(other)}"`),
|
|
1696
|
+
])
|
|
1697
|
+
writeSupportFile(context, moduleMapToWrite, contents)
|
|
1698
|
+
addToSupportGroup(moduleMapToWrite)
|
|
1699
|
+
linkSupportFile(context, moduleMapToWrite, target.moduleMapPath)
|
|
1700
|
+
for (const buildSettings of project.settingsOf(nativeTarget))
|
|
1701
|
+
buildSettings.MODULEMAP_FILE = relativePath(target.moduleMapPath, sandboxRoot)
|
|
1702
|
+
if (!customModuleMap) {
|
|
1703
|
+
const imports = target.fileAccessors.flatMap((accessor) => {
|
|
1704
|
+
const headerDir = !target.buildAsFramework ? accessor.consumer.header_dir : null
|
|
1705
|
+
const mappings = accessor.consumer.header_mappings_dir
|
|
1706
|
+
return accessor.publicHeaders().map((header) => {
|
|
1707
|
+
const relative = mappings
|
|
1708
|
+
? relativePath(header, path.join(accessor.root, mappings))
|
|
1709
|
+
: path.basename(header)
|
|
1710
|
+
return headerDir ? path.join(headerDir, relative) : relative
|
|
1711
|
+
})
|
|
1712
|
+
})
|
|
1713
|
+
const umbrellaToWrite = path.join(
|
|
1714
|
+
path.dirname(moduleMapToWrite),
|
|
1715
|
+
`${target.label}-umbrella.h`,
|
|
1716
|
+
)
|
|
1717
|
+
writeSupportFile(
|
|
1718
|
+
context,
|
|
1719
|
+
umbrellaToWrite,
|
|
1720
|
+
umbrellaHeader(imports, target.productModuleName),
|
|
1721
|
+
)
|
|
1722
|
+
const ref = addToSupportGroup(umbrellaToWrite)
|
|
1723
|
+
const buildFile = project.addBuildFile(
|
|
1724
|
+
project.phase(nativeTarget, 'PBXHeadersBuildPhase'),
|
|
1725
|
+
ref,
|
|
1726
|
+
)
|
|
1727
|
+
linkSupportFile(context, umbrellaToWrite, target.umbrellaHeaderPath)
|
|
1728
|
+
project.get(buildFile).settings = {
|
|
1729
|
+
ATTRIBUTES: [target.buildAsFramework ? 'Public' : 'Project'],
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
if (target.shouldBuild && target.buildAsFramework) {
|
|
1735
|
+
const declaresInfoPlist =
|
|
1736
|
+
project
|
|
1737
|
+
.settingsOf(nativeTarget)
|
|
1738
|
+
.some((buildSettings) => buildSettings.INFOPLIST_FILE !== undefined) ||
|
|
1739
|
+
[...xcconfigs.values()].some((xcconfig) => xcconfig.toHash().has('INFOPLIST_FILE'))
|
|
1740
|
+
if (!declaresInfoPlist) {
|
|
1741
|
+
writeSupportFile(
|
|
1742
|
+
context,
|
|
1743
|
+
target.infoPlistPath,
|
|
1744
|
+
infoPlist(target.version, 'fmwk', target.analyzed.infoPlist),
|
|
1745
|
+
)
|
|
1746
|
+
for (const buildSettings of project.settingsOf(nativeTarget))
|
|
1747
|
+
buildSettings.INFOPLIST_FILE = relativePath(target.infoPlistPath, sandboxRoot)
|
|
1748
|
+
addToSupportGroup(target.infoPlistPath)
|
|
1749
|
+
}
|
|
1750
|
+
if (target.fileAccessors.some((accessor) => accessor.consumer.header_mappings_dir))
|
|
1751
|
+
project.get(
|
|
1752
|
+
project.newShellScriptPhase(nativeTarget, 'Create Symlinks to Header Folders'),
|
|
1753
|
+
).shellScript =
|
|
1754
|
+
'cd "$CONFIGURATION_BUILD_DIR/$WRAPPER_NAME" || exit 1\nif [ ! -d Versions ]; then\n # Not a versioned framework, so no need to do anything\n exit 0\nfi\n\npublic_path="${PUBLIC_HEADERS_FOLDER_PATH#$CONTENTS_FOLDER_PATH/}"\nif [ ! -f "$public_path" ]; then\n ln -fs "${PUBLIC_HEADERS_FOLDER_PATH#$WRAPPER_NAME/}" "$public_path"\nfi\n\nprivate_path="${PRIVATE_HEADERS_FOLDER_PATH#$CONTENTS_FOLDER_PATH/}"\nif [ ! -f "$private_path" ]; then\n ln -fs "${PRIVATE_HEADERS_FOLDER_PATH#$WRAPPER_NAME/}" "$private_path"\nfi\n'
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
if (target.shouldBuild && target.buildAsLibrary && target.usesSwift) {
|
|
1758
|
+
if (customModuleMap)
|
|
1759
|
+
throw new Error(
|
|
1760
|
+
`Using Swift static libraries with custom module maps is currently not supported. Please build \`${target.label}\` as a framework or remove the custom module map.`,
|
|
1761
|
+
)
|
|
1762
|
+
const moduleMapPath = relativePath(target.moduleMapPath, sandboxRoot)
|
|
1763
|
+
const umbrellaPath = relativePath(target.umbrellaHeaderPath, sandboxRoot)
|
|
1764
|
+
Object.assign(
|
|
1765
|
+
project.get(
|
|
1766
|
+
project.newShellScriptPhase(nativeTarget, 'Copy generated compatibility header'),
|
|
1767
|
+
),
|
|
1768
|
+
{
|
|
1769
|
+
shellScript: `COMPATIBILITY_HEADER_PATH="\${BUILT_PRODUCTS_DIR}/Swift Compatibility Header/\${PRODUCT_MODULE_NAME}-Swift.h"\nMODULE_MAP_PATH="\${BUILT_PRODUCTS_DIR}/\${PRODUCT_MODULE_NAME}.modulemap"\n\nditto "\${DERIVED_SOURCES_DIR}/\${PRODUCT_MODULE_NAME}-Swift.h" "\${COMPATIBILITY_HEADER_PATH}"\nditto "\${PODS_ROOT}/${moduleMapPath}" "\${MODULE_MAP_PATH}"\nditto "\${PODS_ROOT}/${umbrellaPath}" "\${BUILT_PRODUCTS_DIR}"\nprintf "\\n\\nmodule \${PRODUCT_MODULE_NAME}.Swift {\\n header \\"\${COMPATIBILITY_HEADER_PATH}\\"\\n requires objc\\n}\\n" >> "\${MODULE_MAP_PATH}"\n`,
|
|
1770
|
+
inputPaths: [
|
|
1771
|
+
'${DERIVED_SOURCES_DIR}/${PRODUCT_MODULE_NAME}-Swift.h',
|
|
1772
|
+
`\${PODS_ROOT}/${moduleMapPath}`,
|
|
1773
|
+
`\${PODS_ROOT}/${umbrellaPath}`,
|
|
1774
|
+
],
|
|
1775
|
+
outputPaths: [
|
|
1776
|
+
'${BUILT_PRODUCTS_DIR}/${PRODUCT_MODULE_NAME}.modulemap',
|
|
1777
|
+
`\${BUILT_PRODUCTS_DIR}/${path.basename(umbrellaPath)}`,
|
|
1778
|
+
'${BUILT_PRODUCTS_DIR}/Swift Compatibility Header/${PRODUCT_MODULE_NAME}-Swift.h',
|
|
1779
|
+
],
|
|
1780
|
+
},
|
|
1781
|
+
)
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
if (target.shouldBuild && target.rootSpec.consumer.prefix_header_file !== false) {
|
|
1785
|
+
const contents = [
|
|
1786
|
+
...new Set(
|
|
1787
|
+
target.fileAccessors
|
|
1788
|
+
.map((accessor) => accessor.consumer.prefix_header_contents)
|
|
1789
|
+
.filter((value): value is string | string[] => value !== null)
|
|
1790
|
+
.map((value) => (Array.isArray(value) ? value.join('\n') : value)),
|
|
1791
|
+
),
|
|
1792
|
+
]
|
|
1793
|
+
const prefixFiles = [
|
|
1794
|
+
...new Set(
|
|
1795
|
+
target.fileAccessors
|
|
1796
|
+
.map((accessor) => accessor.prefixHeader)
|
|
1797
|
+
.filter((file) => file !== null),
|
|
1798
|
+
),
|
|
1799
|
+
]
|
|
1800
|
+
writeSupportFile(
|
|
1801
|
+
context,
|
|
1802
|
+
target.prefixHeaderPath,
|
|
1803
|
+
HEADER_PREAMBLE +
|
|
1804
|
+
contents.map((text) => `${text}\n`).join('') +
|
|
1805
|
+
prefixFiles.map((file) => fs.readFileSync(file, 'utf8')).join(''),
|
|
1806
|
+
)
|
|
1807
|
+
for (const buildSettings of project.settingsOf(nativeTarget))
|
|
1808
|
+
buildSettings.GCC_PREFIX_HEADER = relativePath(
|
|
1809
|
+
target.prefixHeaderPath,
|
|
1810
|
+
project.projectDir,
|
|
1811
|
+
)
|
|
1812
|
+
addToSupportGroup(target.prefixHeaderPath)
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
if (target.shouldBuild) {
|
|
1816
|
+
writeSupportFile(context, target.dummySourcePath, dummySource(target.label))
|
|
1817
|
+
project.addBuildFile(
|
|
1818
|
+
project.phase(nativeTarget, 'PBXSourcesBuildPhase'),
|
|
1819
|
+
addToSupportGroup(target.dummySourcePath),
|
|
1820
|
+
)
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
if ([...target.frameworkPaths.values()].flat().some((paths) => paths.dsymPath !== null))
|
|
1824
|
+
throw new Error(
|
|
1825
|
+
`${target.label} vendors dSYMs, which Peach's Pods project does not copy yet`,
|
|
1826
|
+
)
|
|
1827
|
+
return { target, nativeTarget, resourceBundleTargets }
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
// ObjectList#move
|
|
1831
|
+
function moveTo(list: Id[], id: Id, index: number): void {
|
|
1832
|
+
const current = list.indexOf(id)
|
|
1833
|
+
if (current === index) return
|
|
1834
|
+
list.splice(current, 1)
|
|
1835
|
+
list.splice(index, 0, id)
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
// AggregateTargetInstaller
|
|
1839
|
+
|
|
1840
|
+
function installAggregateTarget(
|
|
1841
|
+
context: InstallContext,
|
|
1842
|
+
aggregate: AggregateTarget,
|
|
1843
|
+
): { nativeTarget: Id; xcconfigs: Record<string, XcodeConfig> } {
|
|
1844
|
+
const { project, settings, sandboxRoot } = context
|
|
1845
|
+
const nativeTarget = project.newTarget(
|
|
1846
|
+
aggregate.buildAsFramework ? 'framework' : 'static_library',
|
|
1847
|
+
aggregate.label,
|
|
1848
|
+
aggregate.platform.deploymentTarget,
|
|
1849
|
+
aggregate.usesSwift ? 'swift' : 'objc',
|
|
1850
|
+
aggregate.productBasename,
|
|
1851
|
+
)
|
|
1852
|
+
project.get(project.string(nativeTarget, 'productReference')!).name = aggregate.label
|
|
1853
|
+
for (const [name, type] of Object.entries(aggregate.userBuildConfigurations))
|
|
1854
|
+
project.addTargetConfiguration(nativeTarget, name, type)
|
|
1855
|
+
const custom: PlistDict = {}
|
|
1856
|
+
if (aggregate.buildAsStaticFramework) custom.MACH_O_TYPE = 'staticlib'
|
|
1857
|
+
else if (aggregate.buildAsStaticLibrary)
|
|
1858
|
+
Object.assign(custom, { OTHER_LDFLAGS: '', OTHER_LIBTOOLFLAGS: '' })
|
|
1859
|
+
Object.assign(custom, {
|
|
1860
|
+
ENABLE_USER_SCRIPT_SANDBOXING: 'NO',
|
|
1861
|
+
ENABLE_MODULE_VERIFIER: 'NO',
|
|
1862
|
+
'CODE_SIGN_IDENTITY[sdk=appletvos*]': '',
|
|
1863
|
+
'CODE_SIGN_IDENTITY[sdk=iphoneos*]': '',
|
|
1864
|
+
'CODE_SIGN_IDENTITY[sdk=watchos*]': '',
|
|
1865
|
+
MACH_O_TYPE: 'staticlib',
|
|
1866
|
+
OTHER_LDFLAGS: '',
|
|
1867
|
+
OTHER_LIBTOOLFLAGS: '',
|
|
1868
|
+
PODS_ROOT: '$(SRCROOT)',
|
|
1869
|
+
PRODUCT_BUNDLE_IDENTIFIER: 'org.cocoapods.${PRODUCT_NAME:rfc1034identifier}',
|
|
1870
|
+
SKIP_INSTALL: 'YES',
|
|
1871
|
+
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES: 'NO',
|
|
1872
|
+
})
|
|
1873
|
+
for (const buildSettings of project.settingsOf(nativeTarget))
|
|
1874
|
+
Object.assign(buildSettings, deepCopy(custom))
|
|
1875
|
+
fs.mkdirSync(aggregate.supportFilesDir, { recursive: true })
|
|
1876
|
+
const supportGroup = project.newGroup(
|
|
1877
|
+
project.supportFilesGroup,
|
|
1878
|
+
aggregate.label,
|
|
1879
|
+
aggregate.supportFilesDir,
|
|
1880
|
+
)
|
|
1881
|
+
const addToSupportGroup = (file: string) => project.newFile(supportGroup, file)
|
|
1882
|
+
|
|
1883
|
+
const xcconfigs: Record<string, XcodeConfig> = {}
|
|
1884
|
+
for (const config of project.table.configurations(nativeTarget)) {
|
|
1885
|
+
const name = project.string(config, 'name')!
|
|
1886
|
+
if (!(name in aggregate.userBuildConfigurations)) continue
|
|
1887
|
+
const xcconfig = settings.aggregate(aggregate, name).xcconfig()
|
|
1888
|
+
const file = aggregate.xcconfigPath(name)
|
|
1889
|
+
writeSupportFile(context, file, xcconfig.toString())
|
|
1890
|
+
xcconfigs[name] = xcconfig
|
|
1891
|
+
project.get(config).baseConfigurationReference = addToSupportGroup(file)
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
if (aggregate.buildAsFramework) {
|
|
1895
|
+
writeSupportFile(context, aggregate.infoPlistPath, infoPlist('1.0.0', 'fmwk'))
|
|
1896
|
+
for (const buildSettings of project.settingsOf(nativeTarget))
|
|
1897
|
+
buildSettings.INFOPLIST_FILE = relativePath(aggregate.infoPlistPath, sandboxRoot)
|
|
1898
|
+
addToSupportGroup(aggregate.infoPlistPath)
|
|
1899
|
+
}
|
|
1900
|
+
if (aggregate.buildAsFramework || aggregate.usesSwift) {
|
|
1901
|
+
writeSupportFile(
|
|
1902
|
+
context,
|
|
1903
|
+
aggregate.moduleMapPath,
|
|
1904
|
+
moduleMap(aggregate.buildAsFramework, aggregate.productModuleName, [
|
|
1905
|
+
`umbrella header "${path.basename(aggregate.umbrellaHeaderPath)}"`,
|
|
1906
|
+
]),
|
|
1907
|
+
)
|
|
1908
|
+
addToSupportGroup(aggregate.moduleMapPath)
|
|
1909
|
+
for (const buildSettings of project.settingsOf(nativeTarget))
|
|
1910
|
+
buildSettings.MODULEMAP_FILE = relativePath(aggregate.moduleMapPath, sandboxRoot)
|
|
1911
|
+
writeSupportFile(
|
|
1912
|
+
context,
|
|
1913
|
+
aggregate.umbrellaHeaderPath,
|
|
1914
|
+
umbrellaHeader([], aggregate.productModuleName),
|
|
1915
|
+
)
|
|
1916
|
+
const buildFile = project.addBuildFile(
|
|
1917
|
+
project.phase(nativeTarget, 'PBXHeadersBuildPhase'),
|
|
1918
|
+
addToSupportGroup(aggregate.umbrellaHeaderPath),
|
|
1919
|
+
)
|
|
1920
|
+
project.get(buildFile).settings = {
|
|
1921
|
+
ATTRIBUTES: [aggregate.buildAsFramework ? 'Public' : 'Project'],
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
const dynamicXcframeworks = [...aggregate.xcframeworksByConfig().values()]
|
|
1926
|
+
.flat()
|
|
1927
|
+
.some((xcframework) => xcframework.dynamic && xcframework.packaging === 'framework')
|
|
1928
|
+
if (aggregate.includesFrameworks || dynamicXcframeworks) {
|
|
1929
|
+
writeSupportFile(
|
|
1930
|
+
context,
|
|
1931
|
+
aggregate.embedFrameworksScriptPath,
|
|
1932
|
+
embedFrameworksScript(aggregate),
|
|
1933
|
+
true,
|
|
1934
|
+
)
|
|
1935
|
+
addToSupportGroup(aggregate.embedFrameworksScriptPath)
|
|
1936
|
+
}
|
|
1937
|
+
if (aggregate.includesResources) {
|
|
1938
|
+
writeSupportFile(
|
|
1939
|
+
context,
|
|
1940
|
+
aggregate.copyResourcesScriptPath,
|
|
1941
|
+
copyResourcesScript(
|
|
1942
|
+
aggregate.resourcePathsByConfig(),
|
|
1943
|
+
aggregate.platform.deploymentTarget,
|
|
1944
|
+
),
|
|
1945
|
+
true,
|
|
1946
|
+
)
|
|
1947
|
+
addToSupportGroup(aggregate.copyResourcesScriptPath)
|
|
1948
|
+
}
|
|
1949
|
+
for (const [extension, contents] of [
|
|
1950
|
+
['.plist', acknowledgementsPlist(aggregate)],
|
|
1951
|
+
['.markdown', acknowledgementsMarkdown(aggregate)],
|
|
1952
|
+
]) {
|
|
1953
|
+
const file = `${aggregate.acknowledgementsBasepath}${extension}`
|
|
1954
|
+
writeSupportFile(context, file, contents!)
|
|
1955
|
+
addToSupportGroup(file)
|
|
1956
|
+
}
|
|
1957
|
+
writeSupportFile(context, aggregate.dummySourcePath, dummySource(aggregate.label))
|
|
1958
|
+
project.addBuildFile(
|
|
1959
|
+
project.phase(nativeTarget, 'PBXSourcesBuildPhase'),
|
|
1960
|
+
addToSupportGroup(aggregate.dummySourcePath),
|
|
1961
|
+
)
|
|
1962
|
+
return { nativeTarget, xcconfigs }
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
// PodTargetIntegrator and the script phase helpers of UserProjectIntegrator::TargetIntegrator
|
|
1966
|
+
|
|
1967
|
+
function shellScriptPhase(
|
|
1968
|
+
project: PodsProject,
|
|
1969
|
+
target: Id,
|
|
1970
|
+
name: string,
|
|
1971
|
+
showEnvVarsInLog: string | null,
|
|
1972
|
+
): Id {
|
|
1973
|
+
const existing = project.table
|
|
1974
|
+
.list(target, 'buildPhases')
|
|
1975
|
+
.find(
|
|
1976
|
+
(phase) =>
|
|
1977
|
+
project.get(phase).isa === 'PBXShellScriptBuildPhase' &&
|
|
1978
|
+
(project.string(phase, 'name') ?? '').endsWith(name),
|
|
1979
|
+
)
|
|
1980
|
+
if (existing) {
|
|
1981
|
+
project.get(existing).name = name
|
|
1982
|
+
return existing
|
|
1983
|
+
}
|
|
1984
|
+
const phase = project.newShellScriptPhase(target, name)
|
|
1985
|
+
if (showEnvVarsInLog !== null) project.get(phase).showEnvVarsInLog = showEnvVarsInLog
|
|
1986
|
+
return phase
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
function reorderScriptPhase(
|
|
1990
|
+
project: PodsProject,
|
|
1991
|
+
target: Id,
|
|
1992
|
+
phase: Id,
|
|
1993
|
+
position: string,
|
|
1994
|
+
): void {
|
|
1995
|
+
if (position === 'any' || position === '') return
|
|
1996
|
+
const relative: Record<string, [string, boolean]> = {
|
|
1997
|
+
before_compile: ['PBXSourcesBuildPhase', true],
|
|
1998
|
+
after_compile: ['PBXSourcesBuildPhase', false],
|
|
1999
|
+
before_headers: ['PBXHeadersBuildPhase', true],
|
|
2000
|
+
after_headers: ['PBXHeadersBuildPhase', false],
|
|
2001
|
+
}
|
|
2002
|
+
const found = relative[position]
|
|
2003
|
+
if (!found) throw new Error(`Unknown execution position \`${position}\``)
|
|
2004
|
+
const [isa, before] = found
|
|
2005
|
+
const phases = project.table.list(target, 'buildPhases')
|
|
2006
|
+
const targetIndex = phases.findIndex((id) => project.get(id).isa === isa)
|
|
2007
|
+
if (targetIndex === -1) return
|
|
2008
|
+
const name = project.string(phase, 'name')
|
|
2009
|
+
const scriptIndex = phases.findIndex(
|
|
2010
|
+
(id) =>
|
|
2011
|
+
project.get(id).isa === 'PBXShellScriptBuildPhase' &&
|
|
2012
|
+
project.string(id, 'name') === name,
|
|
2013
|
+
)
|
|
2014
|
+
if ((before && scriptIndex > targetIndex) || (!before && scriptIndex < targetIndex)) {
|
|
2015
|
+
const [moved] = phases.splice(scriptIndex, 1)
|
|
2016
|
+
phases.splice(targetIndex, 0, moved!)
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
function integratePodTarget(
|
|
2021
|
+
context: InstallContext,
|
|
2022
|
+
installation: PodInstallation,
|
|
2023
|
+
): void {
|
|
2024
|
+
const { project, sandboxRoot } = context
|
|
2025
|
+
const { target, nativeTarget } = installation
|
|
2026
|
+
const xcframeworks = [...target.xcframeworks.values()].flat()
|
|
2027
|
+
if (xcframeworks.length > 0) {
|
|
2028
|
+
const podsRelative = (file: string) =>
|
|
2029
|
+
`\${PODS_ROOT}/${relativePath(file, sandboxRoot)}`
|
|
2030
|
+
const scriptPath = podsRelative(target.copyXcframeworksScriptPath)
|
|
2031
|
+
const inputList = path.join(
|
|
2032
|
+
target.supportFilesDir,
|
|
2033
|
+
`${target.label}-xcframeworks-input-files.xcfilelist`,
|
|
2034
|
+
)
|
|
2035
|
+
const outputList = path.join(
|
|
2036
|
+
target.supportFilesDir,
|
|
2037
|
+
`${target.label}-xcframeworks-output-files.xcfilelist`,
|
|
2038
|
+
)
|
|
2039
|
+
const phase = shellScriptPhase(project, nativeTarget, '[CP] Copy XCFrameworks', '0')
|
|
2040
|
+
writeSupportFile(
|
|
2041
|
+
context,
|
|
2042
|
+
inputList,
|
|
2043
|
+
[
|
|
2044
|
+
scriptPath,
|
|
2045
|
+
...xcframeworks.map((xcframework) => podsRelative(xcframework.path)),
|
|
2046
|
+
].join('\n'),
|
|
2047
|
+
)
|
|
2048
|
+
writeSupportFile(
|
|
2049
|
+
context,
|
|
2050
|
+
outputList,
|
|
2051
|
+
xcframeworks
|
|
2052
|
+
.map(
|
|
2053
|
+
(xcframework) =>
|
|
2054
|
+
`${XCFRAMEWORKS_BUILD_DIR}/${xcframework.targetName}/${xcframework.name}.framework`,
|
|
2055
|
+
)
|
|
2056
|
+
.join('\n'),
|
|
2057
|
+
)
|
|
2058
|
+
const object = project.get(phase)
|
|
2059
|
+
object.shellScript = `"${scriptPath}"\n`
|
|
2060
|
+
delete object.inputPaths
|
|
2061
|
+
delete object.outputPaths
|
|
2062
|
+
object.inputFileListPaths = [podsRelative(inputList)]
|
|
2063
|
+
object.outputFileListPaths = [podsRelative(outputList)]
|
|
2064
|
+
reorderScriptPhase(project, nativeTarget, phase, 'before_compile')
|
|
2065
|
+
}
|
|
2066
|
+
for (const script of target.scriptPhases) {
|
|
2067
|
+
const text = (key: string) => {
|
|
2068
|
+
const value = script[key]
|
|
2069
|
+
if (value === undefined || value === null) return undefined
|
|
2070
|
+
if (typeof value !== 'string')
|
|
2071
|
+
throw new Error(`script phase ${key} of ${target.label} is not a string`)
|
|
2072
|
+
return value
|
|
2073
|
+
}
|
|
2074
|
+
const strings = (key: string) => {
|
|
2075
|
+
const value = script[key]
|
|
2076
|
+
if (value === undefined || value === null) return undefined
|
|
2077
|
+
if (!Array.isArray(value) || !value.every((item) => typeof item === 'string'))
|
|
2078
|
+
throw new Error(`script phase ${key} of ${target.label} is not a list of strings`)
|
|
2079
|
+
return value.filter((item): item is string => typeof item === 'string')
|
|
2080
|
+
}
|
|
2081
|
+
const phase = shellScriptPhase(
|
|
2082
|
+
project,
|
|
2083
|
+
nativeTarget,
|
|
2084
|
+
`[CP-User] ${text('name')}`,
|
|
2085
|
+
null,
|
|
2086
|
+
)
|
|
2087
|
+
const object = project.get(phase)
|
|
2088
|
+
object.shellScript = text('script') ?? ''
|
|
2089
|
+
object.shellPath = text('shell_path') ?? '/bin/sh'
|
|
2090
|
+
const fields: [string, string[] | string | undefined][] = [
|
|
2091
|
+
['inputPaths', strings('input_files')],
|
|
2092
|
+
['outputPaths', strings('output_files')],
|
|
2093
|
+
['inputFileListPaths', strings('input_file_lists')],
|
|
2094
|
+
['outputFileListPaths', strings('output_file_lists')],
|
|
2095
|
+
['dependencyFile', text('dependency_file')],
|
|
2096
|
+
['alwaysOutOfDate', text('always_out_of_date')],
|
|
2097
|
+
]
|
|
2098
|
+
for (const [key, value] of fields) {
|
|
2099
|
+
if (value === undefined) delete object[key]
|
|
2100
|
+
else object[key] = value
|
|
2101
|
+
}
|
|
2102
|
+
if (script.show_env_vars_in_log === '0') object.showEnvVarsInLog = '0'
|
|
2103
|
+
reorderScriptPhase(project, nativeTarget, phase, text('execution_position') ?? '')
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2107
|
+
/** the objects table, support files and target results of a generated Pods project. */
|
|
2108
|
+
export interface GeneratedPodsProject {
|
|
2109
|
+
table: PbxTable
|
|
2110
|
+
objectVersion: string
|
|
2111
|
+
/** every support file and header link written under the sandbox. */
|
|
2112
|
+
files: string[]
|
|
2113
|
+
results: {
|
|
2114
|
+
pods: Record<string, { nativeTarget: string; resourceBundleTargets: string[] }>
|
|
2115
|
+
aggregates: Record<string, { nativeTarget: string }>
|
|
2116
|
+
}
|
|
2117
|
+
/** each aggregate target's xcconfig by user configuration name. */
|
|
2118
|
+
aggregateXcconfigs: Record<string, Record<string, XcodeConfig>>
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
const byName = <T extends { name: string }>(targets: T[]) =>
|
|
2122
|
+
[...targets].sort((a, b) => compareBytes(a.name, b.name))
|
|
2123
|
+
|
|
2124
|
+
/**
|
|
2125
|
+
* the Pods project `pod install` generates before its post_install hooks run,
|
|
2126
|
+
* with its support files written under the sandbox. call finalizePodsProject
|
|
2127
|
+
* after the hooks.
|
|
2128
|
+
*/
|
|
2129
|
+
export function generatePodsProject(
|
|
2130
|
+
targets: PodTargets,
|
|
2131
|
+
settings: PodsBuildSettings,
|
|
2132
|
+
options: { podfilePath: string; objectVersion: number },
|
|
2133
|
+
): GeneratedPodsProject {
|
|
2134
|
+
const { sandbox, podTargets, aggregateTargets } = targets
|
|
2135
|
+
const project = new PodsProject(
|
|
2136
|
+
path.dirname(sandbox.projectPath),
|
|
2137
|
+
options.objectVersion,
|
|
2138
|
+
)
|
|
2139
|
+
const context: InstallContext = {
|
|
2140
|
+
project,
|
|
2141
|
+
settings,
|
|
2142
|
+
sandboxRoot: sandbox.root,
|
|
2143
|
+
files: [],
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
for (const [name, type] of Object.entries(
|
|
2147
|
+
aggregateTargets[0]?.userBuildConfigurations ?? {},
|
|
2148
|
+
))
|
|
2149
|
+
project.addProjectConfiguration(name, type)
|
|
2150
|
+
project.setSymroot()
|
|
2151
|
+
const added = new Set<string>()
|
|
2152
|
+
for (const target of podTargets) {
|
|
2153
|
+
if (added.has(target.podName)) continue
|
|
2154
|
+
added.add(target.podName)
|
|
2155
|
+
const parent =
|
|
2156
|
+
target.analyzed.local !== null ? project.developmentPodsGroup : project.podsGroup
|
|
2157
|
+
project.newGroup(parent, target.podName, target.podDir)
|
|
2158
|
+
}
|
|
2159
|
+
project.markRuby(project.newFile(project.mainGroup, options.podfilePath, 'SOURCE_ROOT'))
|
|
2160
|
+
const deploymentTargets = aggregateTargets.map(
|
|
2161
|
+
(aggregate) => aggregate.platform.deploymentTarget,
|
|
2162
|
+
)
|
|
2163
|
+
const minimum = deploymentTargets.reduce<string | null>(
|
|
2164
|
+
(min, value) => (min === null || versionLess(value, min) ? value : min),
|
|
2165
|
+
null,
|
|
2166
|
+
)
|
|
2167
|
+
for (const config of project.table.configurations(project.root)) {
|
|
2168
|
+
const buildSettings = project.table.buildSettings(config)
|
|
2169
|
+
if (minimum !== null) buildSettings.IPHONEOS_DEPLOYMENT_TARGET = minimum
|
|
2170
|
+
buildSettings.STRIP_INSTALLED_PRODUCT = 'NO'
|
|
2171
|
+
buildSettings.CLANG_ENABLE_OBJC_ARC = 'YES'
|
|
2172
|
+
buildSettings.CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = 'YES'
|
|
2173
|
+
}
|
|
2174
|
+
|
|
2175
|
+
installFileReferences(project, podTargets)
|
|
2176
|
+
fs.rmSync(sandbox.headersRoot, { recursive: true, force: true })
|
|
2177
|
+
for (const store of [
|
|
2178
|
+
sandbox.publicHeaders,
|
|
2179
|
+
...podTargets.map((target) => target.buildHeaders),
|
|
2180
|
+
])
|
|
2181
|
+
for (const { link, target } of store.links) {
|
|
2182
|
+
const file = path.join(sandbox.root, link)
|
|
2183
|
+
fs.mkdirSync(path.dirname(file), { recursive: true })
|
|
2184
|
+
fs.rmSync(file, { force: true })
|
|
2185
|
+
fs.symlinkSync(target, file)
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2188
|
+
const umbrellaHeadersByDir = new Map<string, string[]>()
|
|
2189
|
+
for (const target of podTargets) {
|
|
2190
|
+
if (!target.shouldBuild || !target.definesModule) continue
|
|
2191
|
+
const dir = path.dirname(target.umbrellaHeaderPath)
|
|
2192
|
+
umbrellaHeadersByDir.set(dir, [
|
|
2193
|
+
...(umbrellaHeadersByDir.get(dir) ?? []),
|
|
2194
|
+
target.umbrellaHeaderPath,
|
|
2195
|
+
])
|
|
2196
|
+
}
|
|
2197
|
+
const pods = byName(podTargets).map((target) =>
|
|
2198
|
+
installPodTarget(
|
|
2199
|
+
context,
|
|
2200
|
+
target,
|
|
2201
|
+
umbrellaHeadersByDir.get(path.dirname(target.moduleMapPath)),
|
|
2202
|
+
),
|
|
2203
|
+
)
|
|
2204
|
+
for (const { target, nativeTarget } of pods) {
|
|
2205
|
+
if (!target.shouldBuild || target.buildAsStatic) continue
|
|
2206
|
+
for (const accessor of target.fileAccessors)
|
|
2207
|
+
for (const framework of accessor.consumer.frameworks)
|
|
2208
|
+
project.addSystemFramework(nativeTarget, framework)
|
|
2209
|
+
}
|
|
2210
|
+
const aggregates = byName(aggregateTargets).map((aggregate) => ({
|
|
2211
|
+
aggregate,
|
|
2212
|
+
...installAggregateTarget(context, aggregate),
|
|
2213
|
+
}))
|
|
2214
|
+
for (const installation of pods)
|
|
2215
|
+
if (
|
|
2216
|
+
installation.target.scriptPhases.length > 0 ||
|
|
2217
|
+
[...installation.target.xcframeworks.values()].some((list) => list.length > 0)
|
|
2218
|
+
)
|
|
2219
|
+
integratePodTarget(context, installation)
|
|
2220
|
+
|
|
2221
|
+
const podsByLabel = new Map(
|
|
2222
|
+
pods.map((installation) => [installation.target.label, installation]),
|
|
2223
|
+
)
|
|
2224
|
+
const aggregatesByLabel = new Map(
|
|
2225
|
+
aggregates.map((installation) => [installation.aggregate.label, installation]),
|
|
2226
|
+
)
|
|
2227
|
+
for (const { aggregate, nativeTarget } of aggregates) {
|
|
2228
|
+
for (const searched of aggregate.searchPathsAggregateTargets)
|
|
2229
|
+
project.addDependency(
|
|
2230
|
+
nativeTarget,
|
|
2231
|
+
aggregatesByLabel.get(searched.label)!.nativeTarget,
|
|
2232
|
+
)
|
|
2233
|
+
for (const target of aggregate.podTargets)
|
|
2234
|
+
project.addDependency(nativeTarget, podsByLabel.get(target.label)!.nativeTarget)
|
|
2235
|
+
}
|
|
2236
|
+
for (const { target, nativeTarget, resourceBundleTargets } of pods) {
|
|
2237
|
+
for (const bundle of resourceBundleTargets) {
|
|
2238
|
+
project.addDependency(nativeTarget, bundle)
|
|
2239
|
+
if (target.buildAsDynamicFramework && target.shouldBuild)
|
|
2240
|
+
project.addResources(nativeTarget, [project.string(bundle, 'productReference')!])
|
|
2241
|
+
}
|
|
2242
|
+
for (const dependency of target.dependentTargets)
|
|
2243
|
+
project.addDependency(nativeTarget, podsByLabel.get(dependency.label)!.nativeTarget)
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
return {
|
|
2247
|
+
table: project.table,
|
|
2248
|
+
objectVersion: String(options.objectVersion),
|
|
2249
|
+
files: context.files,
|
|
2250
|
+
results: {
|
|
2251
|
+
pods: Object.fromEntries(
|
|
2252
|
+
pods.map(({ target, nativeTarget, resourceBundleTargets }) => [
|
|
2253
|
+
target.label,
|
|
2254
|
+
{ nativeTarget, resourceBundleTargets },
|
|
2255
|
+
]),
|
|
2256
|
+
),
|
|
2257
|
+
aggregates: Object.fromEntries(
|
|
2258
|
+
aggregates.map(({ aggregate, nativeTarget }) => [
|
|
2259
|
+
aggregate.label,
|
|
2260
|
+
{ nativeTarget },
|
|
2261
|
+
]),
|
|
2262
|
+
),
|
|
2263
|
+
},
|
|
2264
|
+
aggregateXcconfigs: Object.fromEntries(
|
|
2265
|
+
aggregates.map(({ aggregate, xcconfigs }) => [aggregate.label, xcconfigs]),
|
|
2266
|
+
),
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
// PodsProjectWriter#write!: what it does to the project after the hooks
|
|
2271
|
+
|
|
2272
|
+
/**
|
|
2273
|
+
* PodsProjectWriter: drops the Pods, Targets Support Files, Development Pods and
|
|
2274
|
+
* Dependencies groups when empty, sorts the project with groups below files,
|
|
2275
|
+
* and normalizes array build settings the way Xcodeproj saves them.
|
|
2276
|
+
*/
|
|
2277
|
+
export function finalizePodsProject(table: PbxTable, objectVersion: string): void {
|
|
2278
|
+
const root = table.get(table.rootObject)
|
|
2279
|
+
const mainGroup = String(root.mainGroup)
|
|
2280
|
+
const mainChildren = table.list(mainGroup, 'children')
|
|
2281
|
+
for (const name of [
|
|
2282
|
+
'Pods',
|
|
2283
|
+
'Targets Support Files',
|
|
2284
|
+
'Development Pods',
|
|
2285
|
+
'Dependencies',
|
|
2286
|
+
]) {
|
|
2287
|
+
const group = mainChildren.find(
|
|
2288
|
+
(id) => table.string(id, 'name') === name && table.get(id).isa === 'PBXGroup',
|
|
2289
|
+
)
|
|
2290
|
+
if (!group || table.list(group, 'children').length > 0) continue
|
|
2291
|
+
mainChildren.splice(mainChildren.indexOf(group), 1)
|
|
2292
|
+
delete table.objects[group]
|
|
2293
|
+
}
|
|
2294
|
+
|
|
2295
|
+
const parents = new Map<Id, Id>()
|
|
2296
|
+
const reachable = new Set<Id>()
|
|
2297
|
+
const visit = (id: Id) => {
|
|
2298
|
+
if (reachable.has(id) || !table.objects[id]) return
|
|
2299
|
+
reachable.add(id)
|
|
2300
|
+
for (const value of Object.values(table.get(id))) {
|
|
2301
|
+
if (typeof value === 'string') visit(value)
|
|
2302
|
+
else if (Array.isArray(value))
|
|
2303
|
+
for (const item of value) if (typeof item === 'string') visit(item)
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
visit(table.rootObject)
|
|
2307
|
+
for (const id of reachable)
|
|
2308
|
+
if (table.get(id).isa === 'PBXGroup' || table.get(id).isa === 'PBXVariantGroup')
|
|
2309
|
+
for (const child of table.list(id, 'children')) parents.set(child, id)
|
|
2310
|
+
|
|
2311
|
+
const name = (id: Id) => table.string(id, 'name')
|
|
2312
|
+
const ownPath = (id: Id) => table.string(id, 'path')
|
|
2313
|
+
const displayName = (id: Id): string => {
|
|
2314
|
+
const object = table.get(id)
|
|
2315
|
+
const isa = String(object.isa)
|
|
2316
|
+
if (isa === 'PBXFileReference') {
|
|
2317
|
+
if (name(id) !== undefined) return name(id)!
|
|
2318
|
+
if (object.sourceTree === 'BUILT_PRODUCTS_DIR' && ownPath(id) !== undefined)
|
|
2319
|
+
return ownPath(id)!
|
|
2320
|
+
return ownPath(id) === undefined ? '' : path.basename(ownPath(id)!)
|
|
2321
|
+
}
|
|
2322
|
+
if (isa === 'PBXGroup' || isa === 'PBXVariantGroup') {
|
|
2323
|
+
if (name(id) !== undefined) return name(id)!
|
|
2324
|
+
if (ownPath(id) !== undefined) return path.basename(ownPath(id)!)
|
|
2325
|
+
return id === mainGroup ? 'Main Group' : ''
|
|
2326
|
+
}
|
|
2327
|
+
if (isa === 'PBXBuildFile') {
|
|
2328
|
+
const ref = table.string(id, 'fileRef')
|
|
2329
|
+
return ref && table.objects[ref] ? displayName(ref) : 'BuildFile'
|
|
2330
|
+
}
|
|
2331
|
+
if (isa === 'PBXTargetDependency') {
|
|
2332
|
+
if (name(id) !== undefined) return name(id)!
|
|
2333
|
+
const target = table.string(id, 'target')
|
|
2334
|
+
return target ? (table.string(target, 'name') ?? '') : ''
|
|
2335
|
+
}
|
|
2336
|
+
const generic = name(id) ? name(id)! : isa.replace(/^(PBX|XC)/, '')
|
|
2337
|
+
return isa.endsWith('BuildPhase') ? generic.replace(/BuildPhase$/, '') : generic
|
|
2338
|
+
}
|
|
2339
|
+
const fullPath = (id: Id): string => {
|
|
2340
|
+
const tree = table.string(id, 'sourceTree')
|
|
2341
|
+
let folder = ''
|
|
2342
|
+
if (tree === '<group>') {
|
|
2343
|
+
const parent = parents.get(id)
|
|
2344
|
+
folder = parent ? fullPath(parent) : ''
|
|
2345
|
+
} else if (tree === '<absolute>') folder = '/'
|
|
2346
|
+
else if (tree !== 'SOURCE_ROOT') folder = `\${${tree}}`
|
|
2347
|
+
const own = ownPath(id)
|
|
2348
|
+
if (!own) return folder
|
|
2349
|
+
if (path.isAbsolute(own)) return path.normalize(own)
|
|
2350
|
+
return folder ? path.join(folder, own) : path.normalize(own)
|
|
2351
|
+
}
|
|
2352
|
+
const byDisplay = (list: Id[], lower: boolean) =>
|
|
2353
|
+
list.sort((a, b) =>
|
|
2354
|
+
lower
|
|
2355
|
+
? compareBytes(displayName(a).toLowerCase(), displayName(b).toLowerCase())
|
|
2356
|
+
: compareBytes(displayName(a), displayName(b)),
|
|
2357
|
+
)
|
|
2358
|
+
const byFileName = (a: string, b: string) => {
|
|
2359
|
+
const x = a.toLowerCase()
|
|
2360
|
+
const y = b.toLowerCase()
|
|
2361
|
+
return compareBytes(stem(x), stem(y)) || compareBytes(extname(x), extname(y))
|
|
2362
|
+
}
|
|
2363
|
+
|
|
2364
|
+
for (const id of reachable) {
|
|
2365
|
+
const object = table.get(id)
|
|
2366
|
+
const isa = String(object.isa)
|
|
2367
|
+
if (isa === 'PBXGroup' || isa === 'PBXVariantGroup')
|
|
2368
|
+
table.list(id, 'children').sort((a, b) => {
|
|
2369
|
+
const groupA = table.get(a).isa === 'PBXGroup'
|
|
2370
|
+
const groupB = table.get(b).isa === 'PBXGroup'
|
|
2371
|
+
if (groupA !== groupB) return groupA ? 1 : -1
|
|
2372
|
+
const result = byFileName(displayName(a), displayName(b))
|
|
2373
|
+
if (result !== 0) return result
|
|
2374
|
+
const pathA = ownPath(a)
|
|
2375
|
+
const pathB = ownPath(b)
|
|
2376
|
+
return pathA === undefined || pathB === undefined
|
|
2377
|
+
? 0
|
|
2378
|
+
: compareBytes(pathA.toLowerCase(), pathB.toLowerCase())
|
|
2379
|
+
})
|
|
2380
|
+
else if (isa.endsWith('BuildPhase'))
|
|
2381
|
+
table.list(id, 'files').sort((a, b) => {
|
|
2382
|
+
const result = byFileName(displayName(a), displayName(b))
|
|
2383
|
+
if (result !== 0) return result
|
|
2384
|
+
const refA = table.string(a, 'fileRef')
|
|
2385
|
+
const refB = table.string(b, 'fileRef')
|
|
2386
|
+
return refA && refB
|
|
2387
|
+
? compareBytes(fullPath(refA).toLowerCase(), fullPath(refB).toLowerCase())
|
|
2388
|
+
: 0
|
|
2389
|
+
})
|
|
2390
|
+
else if (isa === 'PBXNativeTarget') {
|
|
2391
|
+
for (const key of [
|
|
2392
|
+
'buildRules',
|
|
2393
|
+
'dependencies',
|
|
2394
|
+
'packageProductDependencies',
|
|
2395
|
+
'fileSystemSynchronizedGroups',
|
|
2396
|
+
])
|
|
2397
|
+
if (Array.isArray(object[key])) byDisplay(table.list(id, key), false)
|
|
2398
|
+
} else if (isa === 'PBXAggregateTarget') {
|
|
2399
|
+
byDisplay(table.list(id, 'buildPhases'), true)
|
|
2400
|
+
byDisplay(table.list(id, 'dependencies'), true)
|
|
2401
|
+
} else if (isa === 'PBXProject') {
|
|
2402
|
+
byDisplay(table.list(id, 'targets'), true)
|
|
2403
|
+
if (Array.isArray(object.packageReferences))
|
|
2404
|
+
byDisplay(table.list(id, 'packageReferences'), true)
|
|
2405
|
+
} else if (isa === 'XCConfigurationList')
|
|
2406
|
+
byDisplay(table.list(id, 'buildConfigurations'), true)
|
|
2407
|
+
else if (isa === 'XCBuildConfiguration') {
|
|
2408
|
+
const settings = table.buildSettings(id)
|
|
2409
|
+
const sorted: PlistDict = {}
|
|
2410
|
+
for (const key of Object.keys(settings).sort(compareBytes))
|
|
2411
|
+
sorted[key] = settings[key]!
|
|
2412
|
+
normalizeArraySettings(sorted, objectVersion)
|
|
2413
|
+
object.buildSettings = sorted
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
}
|