Skip to content

Commit 603c1df

Browse files
Fix UIDeviceFamily warning by patching Info.plist (#260)
Patch Info.plist files to remove Xcode warning about UIDeviceFamily key.
1 parent beb0cc6 commit 603c1df

File tree

6 files changed

+108
-7
lines changed

6 files changed

+108
-7
lines changed

examples/ios_app/test/fixtures/project.xcodeproj/project.pbxproj

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
8B6377F4DA6FAE3ED76C177A /* Generate Files */,
1515
64D3406EB908D4BD044C581E /* Copy Files */,
1616
C977250D6EB972BF2FF38593 /* Fix Modulemaps */,
17+
700DDA896776846733B25577 /* Fix Info.plists */,
1718
);
1819
dependencies = (
1920
);
@@ -924,6 +925,27 @@
924925
shellScript = "set -eu\n\ncd \"bazel-out\"\n\nrsync \\\n --files-from \"$PROJECT_DIR/test/fixtures/project.xcodeproj/rules_xcodeproj/generated.rsynclist\" \\\n --chmod=u+w \\\n -L \\\n . \\\n \"$BUILD_DIR/bazel-out\"\n\ncd \"$PROJECT_FILE_PATH/rules_xcodeproj\"\n\n# Need to remove the directory that Xcode creates as part of output prep\nrm -rf gen_dir\n\nln -sf \"$BUILD_DIR/bazel-out\" gen_dir\n";
925926
showEnvVarsInLog = 0;
926927
};
928+
700DDA896776846733B25577 /* Fix Info.plists */ = {
929+
isa = PBXShellScriptBuildPhase;
930+
buildActionMask = 2147483647;
931+
files = (
932+
);
933+
inputFileListPaths = (
934+
"$(PROJECT_DIR)/test/fixtures/project.xcodeproj/rules_xcodeproj/infoplists.xcfilelist",
935+
);
936+
inputPaths = (
937+
);
938+
name = "Fix Info.plists";
939+
outputFileListPaths = (
940+
"$(PROJECT_DIR)/test/fixtures/project.xcodeproj/rules_xcodeproj/infoplists.fixed.xcfilelist",
941+
);
942+
outputPaths = (
943+
);
944+
runOnlyForDeploymentPostprocessing = 0;
945+
shellPath = /bin/sh;
946+
shellScript = "set -eu\n\nwhile IFS= read -r input; do\n output=\"${input%.plist}.xcode.plist\"\n cp \"$input\" \"$output\"\n plutil -remove UIDeviceFamily \"$output\" || true\ndone < \"$SCRIPT_INPUT_FILE_LIST_0\"";
947+
showEnvVarsInLog = 0;
948+
};
927949
8B6377F4DA6FAE3ED76C177A /* Generate Files */ = {
928950
isa = PBXShellScriptBuildPhase;
929951
alwaysOutOfDate = 1;
@@ -1235,7 +1257,7 @@
12351257
ENABLE_BITCODE = NO;
12361258
ENABLE_TESTABILITY = YES;
12371259
ENABLE_TESTING_SEARCH_PATHS = YES;
1238-
INFOPLIST_FILE = "$(PROJECT_FILE_PATH)/rules_xcodeproj/gen_dir/applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/ExampleUITests/ExampleUITests.__internal__.__test_bundle-intermediates/Info.plist";
1260+
INFOPLIST_FILE = "$(PROJECT_FILE_PATH)/rules_xcodeproj/gen_dir/applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/ExampleUITests/ExampleUITests.__internal__.__test_bundle-intermediates/Info.xcode.plist";
12391261
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
12401262
OTHER_CFLAGS = (
12411263
"-D_FORTIFY_SOURCE=1",
@@ -1305,7 +1327,7 @@
13051327
"$(PROJECT_DIR)/CoreUtilsObjC",
13061328
"$(BUILD_DIR)/bazel-out/ios-x86_64-min15.0-applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/CoreUtilsObjC",
13071329
);
1308-
INFOPLIST_FILE = "$(PROJECT_FILE_PATH)/rules_xcodeproj/gen_dir/applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/ExampleTests/ExampleTests.__internal__.__test_bundle-intermediates/Info.plist";
1330+
INFOPLIST_FILE = "$(PROJECT_FILE_PATH)/rules_xcodeproj/gen_dir/applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/ExampleTests/ExampleTests.__internal__.__test_bundle-intermediates/Info.xcode.plist";
13091331
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
13101332
OTHER_CFLAGS = (
13111333
"-D_FORTIFY_SOURCE=1",
@@ -1549,7 +1571,7 @@
15491571
"$(PROJECT_DIR)/CoreUtilsObjC",
15501572
"$(BUILD_DIR)/bazel-out/ios-x86_64-min15.0-applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/CoreUtilsObjC",
15511573
);
1552-
INFOPLIST_FILE = "$(PROJECT_FILE_PATH)/rules_xcodeproj/gen_dir/applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/Example/Example-intermediates/Info.plist";
1574+
INFOPLIST_FILE = "$(PROJECT_FILE_PATH)/rules_xcodeproj/gen_dir/applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/Example/Example-intermediates/Info.xcode.plist";
15531575
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
15541576
LD_RUNPATH_SEARCH_PATHS = (
15551577
"$(inherited)",
@@ -1631,7 +1653,7 @@
16311653
"$(PROJECT_DIR)/CoreUtilsObjC",
16321654
"$(BUILD_DIR)/bazel-out/ios-x86_64-min15.0-applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/CoreUtilsObjC",
16331655
);
1634-
INFOPLIST_FILE = "$(PROJECT_FILE_PATH)/rules_xcodeproj/gen_dir/applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/ExampleObjcTests/ExampleObjcTests.__internal__.__test_bundle-intermediates/Info.plist";
1656+
INFOPLIST_FILE = "$(PROJECT_FILE_PATH)/rules_xcodeproj/gen_dir/applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/ExampleObjcTests/ExampleObjcTests.__internal__.__test_bundle-intermediates/Info.xcode.plist";
16351657
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
16361658
OTHER_CFLAGS = (
16371659
"-D_FORTIFY_SOURCE=1",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$(PROJECT_FILE_PATH)/rules_xcodeproj/gen_dir/applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/Example/Example-intermediates/Info.xcode.plist
2+
$(PROJECT_FILE_PATH)/rules_xcodeproj/gen_dir/applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/ExampleObjcTests/ExampleObjcTests.__internal__.__test_bundle-intermediates/Info.xcode.plist
3+
$(PROJECT_FILE_PATH)/rules_xcodeproj/gen_dir/applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/ExampleTests/ExampleTests.__internal__.__test_bundle-intermediates/Info.xcode.plist
4+
$(PROJECT_FILE_PATH)/rules_xcodeproj/gen_dir/applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/ExampleUITests/ExampleUITests.__internal__.__test_bundle-intermediates/Info.xcode.plist
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$(PROJECT_FILE_PATH)/rules_xcodeproj/gen_dir/applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/Example/Example-intermediates/Info.plist
2+
$(PROJECT_FILE_PATH)/rules_xcodeproj/gen_dir/applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/ExampleObjcTests/ExampleObjcTests.__internal__.__test_bundle-intermediates/Info.plist
3+
$(PROJECT_FILE_PATH)/rules_xcodeproj/gen_dir/applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/ExampleTests/ExampleTests.__internal__.__test_bundle-intermediates/Info.plist
4+
$(PROJECT_FILE_PATH)/rules_xcodeproj/gen_dir/applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd/bin/ExampleUITests/ExampleUITests.__internal__.__test_bundle-intermediates/Info.plist

tools/generator/src/Generator+AddTargets.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,20 @@ ln -sf "$BUILD_DIR/bazel-out" gen_dir
187187
filePathResolver: filePathResolver
188188
)
189189

190+
let fixInfoPlistsScript = createFixInfoPlistsScript(
191+
in: pbxProj,
192+
files: files,
193+
filePathResolver: filePathResolver
194+
)
195+
190196
let pbxTarget = PBXAggregateTarget(
191197
name: "Bazel Generated Files",
192198
buildConfigurationList: configurationList,
193199
buildPhases: [
194200
generateFilesScript,
195201
copyFilesScript,
196202
fixModuleMapsScript,
203+
fixInfoPlistsScript,
197204
].compactMap { $0 },
198205
productName: "Bazel Generated Files"
199206
)
@@ -247,6 +254,43 @@ ln -sfn "\#(
247254
filePathResolver.resolve(.external(""), useScriptVariables: true)
248255
)" external
249256
257+
"""#,
258+
showEnvVarsInLog: false
259+
)
260+
pbxProj.add(object: script)
261+
262+
return script
263+
}
264+
265+
private static func createFixInfoPlistsScript(
266+
in pbxProj: PBXProj,
267+
files: [FilePath: File],
268+
filePathResolver: FilePathResolver
269+
) -> PBXShellScriptBuildPhase? {
270+
guard files.containsInfoPlists else {
271+
return nil
272+
}
273+
274+
let script = PBXShellScriptBuildPhase(
275+
name: "Fix Info.plists",
276+
inputFileListPaths: [
277+
filePathResolver
278+
.resolve(.internal(infoPlistsFileListPath))
279+
.string,
280+
],
281+
outputFileListPaths: [
282+
filePathResolver
283+
.resolve(.internal(fixedInfoPlistsFileListPath))
284+
.string,
285+
],
286+
shellScript: #"""
287+
set -eu
288+
289+
while IFS= read -r input; do
290+
output="${input%.plist}.xcode.plist"
291+
cp "$input" "$output"
292+
plutil -remove UIDeviceFamily "$output" || true
293+
done < "$SCRIPT_INPUT_FILE_LIST_0"
250294
"""#,
251295
showEnvVarsInLog: false
252296
)
@@ -571,6 +615,13 @@ extension Dictionary where Key == FilePath {
571615
&& filePath.path.extension == "modulemap"
572616
})
573617
}
618+
619+
var containsInfoPlists: Bool {
620+
contains(where: { filePath, _ in
621+
return filePath.type == .generated
622+
&& filePath.path.lastComponent == "Info.plist"
623+
})
624+
}
574625
}
575626

576627
private extension Path {

tools/generator/src/Generator+CreateFilesAndGroups.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ extension Generator {
3636
static let copiedGeneratedFileListPath: Path = "generated.copied.xcfilelist"
3737
static let modulemapsFileListPath: Path = "modulemaps.xcfilelist"
3838
static let fixedModulemapsFileListPath: Path = "modulemaps.fixed.xcfilelist"
39+
static let infoPlistsFileListPath: Path = "infoplists.xcfilelist"
40+
static let fixedInfoPlistsFileListPath: Path = "infoplists.fixed.xcfilelist"
3941

4042
private static let localizedGroupExtensions: Set<String> = [
4143
"intentdefinition",
@@ -378,6 +380,16 @@ extension Generator {
378380
let fixedModulemapPaths = modulemapPaths.map { path in
379381
return path.replacingExtension("xcode.modulemap")
380382
}
383+
let infoPlistPaths = generatedFiles
384+
.filter { filePath, _ in filePath.path.lastComponent == "Info.plist" }
385+
.map { filePath, _ in
386+
// We need to use `gen_dir` instead of `$(BUILD_DIR)` here to match
387+
// the project navigator
388+
return filePathResolver.resolve(filePath, useBuildDir: false)
389+
}
390+
let fixedInfoPlistPaths = infoPlistPaths.map { path in
391+
return path.replacingExtension("xcode.plist")
392+
}
381393

382394
func addXCFileList(_ path: Path, paths: [Path]) {
383395
guard !paths.isEmpty else {
@@ -394,6 +406,8 @@ extension Generator {
394406
addXCFileList(copiedGeneratedFileListPath, paths: copiedGeneratedPaths)
395407
addXCFileList(modulemapsFileListPath, paths: modulemapPaths)
396408
addXCFileList(fixedModulemapsFileListPath, paths: fixedModulemapPaths)
409+
addXCFileList(infoPlistsFileListPath, paths: infoPlistPaths)
410+
addXCFileList(fixedInfoPlistsFileListPath, paths: fixedInfoPlistPaths)
397411

398412
// Write LinkFileLists
399413

tools/generator/src/Generator+SetTargetConfigurations.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,18 @@ Target "\(id)" not found in `pbxTargets`
111111
buildSettings["TARGET_NAME"] = target.name
112112

113113
if let infoPlist = target.infoPlist {
114-
let infoPlistPath = filePathResolver
114+
var infoPlistPath = filePathResolver
115115
// We need to use `gen_dir` instead of `$(BUILD_DIR)` here
116116
// to match the project navigator
117117
.resolve(infoPlist, useBuildDir: false)
118-
.string.quoted
119-
buildSettings["INFOPLIST_FILE"] = infoPlistPath
118+
119+
// If the plist is generated, use the patched version that
120+
// removes a specific key that causes a warning when building
121+
// with Xcode
122+
if infoPlist.type == .generated {
123+
infoPlistPath.replaceExtension("xcode.plist")
124+
}
125+
buildSettings["INFOPLIST_FILE"] = infoPlistPath.string.quoted
120126
} else {
121127
buildSettings["GENERATE_INFOPLIST_FILE"] = true
122128
}

0 commit comments

Comments
 (0)