Skip to content

Commit 9d3694c

Browse files
committed
Make ActionUIVerifier Xcode friendly with proper warning and error messages
Xcode needs to see the proper prefixes for warning and error: "warning: not great but we will live" "error: bad situation" Add ActionUIVerifier as a dependency for ActionUISwiftTestApp and run the verification when building. This will catch mistakes and also is a demonstration of the best practice in production environment. Turned off Xcode user script sandboxing because it does not let specify a directory with GLOB content for the source declaration.
1 parent 8c4ca37 commit 9d3694c

3 files changed

Lines changed: 64 additions & 9 deletions

File tree

ActionUI.xcodeproj/project.pbxproj

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@
8686
remoteGlobalIDString = 1D03F8E52E49EEC3004A42BB;
8787
remoteInfo = ActionUI;
8888
};
89+
1DB786D12F5B978A0082EE55 /* PBXContainerItemProxy */ = {
90+
isa = PBXContainerItemProxy;
91+
containerPortal = 1D03F8DD2E49EEC3004A42BB /* Project object */;
92+
proxyType = 1;
93+
remoteGlobalIDString = 1DDC483B2F3DA52D00604C66;
94+
remoteInfo = ActionUIVerifier;
95+
};
8996
1DC076BE2F41B8830036DA50 /* PBXContainerItemProxy */ = {
9097
isa = PBXContainerItemProxy;
9198
containerPortal = 1D03F8DD2E49EEC3004A42BB /* Project object */;
@@ -780,11 +787,13 @@
780787
1DB255E92E6BADCE00544C2F /* Sources */,
781788
1DB255EA2E6BADCE00544C2F /* Frameworks */,
782789
1DB255EB2E6BADCE00544C2F /* Resources */,
790+
1DB786D62F5B97D60082EE55 /* Verify JSON Resources */,
783791
1D6DF6A62E6DB5F5002563AE /* Embed Frameworks */,
784792
);
785793
buildRules = (
786794
);
787795
dependencies = (
796+
1DB786D22F5B978A0082EE55 /* PBXTargetDependency */,
788797
1DB2561A2E6C236300544C2F /* PBXTargetDependency */,
789798
1DD4E42F2E8F3228001E0C83 /* PBXTargetDependency */,
790799
1DD4E4432E8F9DF2001E0C83 /* PBXTargetDependency */,
@@ -1146,6 +1155,29 @@
11461155
};
11471156
/* End PBXResourcesBuildPhase section */
11481157

1158+
/* Begin PBXShellScriptBuildPhase section */
1159+
1DB786D62F5B97D60082EE55 /* Verify JSON Resources */ = {
1160+
isa = PBXShellScriptBuildPhase;
1161+
alwaysOutOfDate = 1;
1162+
buildActionMask = 2147483647;
1163+
files = (
1164+
);
1165+
inputFileListPaths = (
1166+
);
1167+
inputPaths = (
1168+
"${SRCROOT}/ActionUISwiftTestApp/Resources",
1169+
);
1170+
name = "Verify JSON Resources";
1171+
outputFileListPaths = (
1172+
);
1173+
outputPaths = (
1174+
);
1175+
runOnlyForDeploymentPostprocessing = 0;
1176+
shellPath = /bin/sh;
1177+
shellScript = "source \"${SRCROOT}/ActionUISwiftTestApp/Scripts/verify_json_resources.sh\"\n";
1178+
};
1179+
/* End PBXShellScriptBuildPhase section */
1180+
11491181
/* Begin PBXSourcesBuildPhase section */
11501182
1D03F8E22E49EEC3004A42BB /* Sources */ = {
11511183
isa = PBXSourcesBuildPhase;
@@ -1300,6 +1332,11 @@
13001332
target = 1D03F8E52E49EEC3004A42BB /* ActionUI */;
13011333
targetProxy = 1DB256192E6C236300544C2F /* PBXContainerItemProxy */;
13021334
};
1335+
1DB786D22F5B978A0082EE55 /* PBXTargetDependency */ = {
1336+
isa = PBXTargetDependency;
1337+
target = 1DDC483B2F3DA52D00604C66 /* ActionUIVerifier */;
1338+
targetProxy = 1DB786D12F5B978A0082EE55 /* PBXContainerItemProxy */;
1339+
};
13031340
1DC076BD2F41B8830036DA50 /* PBXTargetDependency */ = {
13041341
isa = PBXTargetDependency;
13051342
target = 1D03F8E52E49EEC3004A42BB /* ActionUI */;
@@ -1386,7 +1423,6 @@
13861423
DEBUG_INFORMATION_FORMAT = dwarf;
13871424
ENABLE_STRICT_OBJC_MSGSEND = YES;
13881425
ENABLE_TESTABILITY = YES;
1389-
ENABLE_USER_SCRIPT_SANDBOXING = YES;
13901426
GCC_C_LANGUAGE_STANDARD = gnu17;
13911427
GCC_DYNAMIC_NO_PIC = NO;
13921428
GCC_NO_COMMON_BLOCKS = YES;
@@ -1456,7 +1492,6 @@
14561492
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
14571493
ENABLE_NS_ASSERTIONS = NO;
14581494
ENABLE_STRICT_OBJC_MSGSEND = YES;
1459-
ENABLE_USER_SCRIPT_SANDBOXING = YES;
14601495
GCC_C_LANGUAGE_STANDARD = gnu17;
14611496
GCC_NO_COMMON_BLOCKS = YES;
14621497
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
# Verify all JSON resource files using ActionUIVerifier during build.
3+
# Add this as a "Run Script" build phase in ActionUISwiftTestApp,
4+
# after the "Copy Bundle Resources" phase.
5+
# Ensure ActionUIVerifier is listed as a target dependency.
6+
7+
VERIFIER="${BUILT_PRODUCTS_DIR}/ActionUIVerifier"
8+
9+
if [ ! -x "$VERIFIER" ]; then
10+
echo "error: ActionUIVerifier not found at $VERIFIER"
11+
exit 1
12+
fi
13+
14+
RESOURCES_DIR="${SRCROOT}/ActionUISwiftTestApp/Resources"
15+
16+
if [ ! -d "$RESOURCES_DIR" ]; then
17+
echo "error: Resources directory not found at $RESOURCES_DIR"
18+
exit 1
19+
fi
20+
21+
"$VERIFIER" "$RESOURCES_DIR"

ActionUIVerifier/ActionUIVerifier.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct ActionUIVerifier {
4141
includingPropertiesForKeys: nil,
4242
options: [.skipsHiddenFiles]
4343
) else {
44-
logger.log("Failed to read directory: \(directoryPath)", .error)
44+
logger.log("Failed to read directory: \(directoryPath). Check path exists and is accessible.", .error)
4545
return false
4646
}
4747

@@ -146,10 +146,10 @@ private class VerifierLogger: ActionUILogger {
146146
func log(_ message: String, _ level: ActionUI.LoggerLevel) {
147147

148148
if level == .warning {
149-
fputs("[WARNING] \(message)\n", stdout)
149+
fputs("warning: \(message)\n", stderr)
150150
hasWarnings = true
151151
} else if level == .error {
152-
fputs("[ERROR] \(message)\n", stderr)
152+
fputs("error: \(message)\n", stderr)
153153
hasErrors = true
154154
}
155155
}
@@ -181,14 +181,13 @@ struct ActionUIVerifierMain {
181181
let attributes = try fileManager.attributesOfItem(atPath: path)
182182
isDirectory = attributes[.type] as? FileAttributeType == .typeDirectory
183183
} catch {
184-
fputs("Error: Cannot access path \(path): \(error)\n", stderr)
184+
fputs("error: Cannot access path \(path): \(error)\n", stderr)
185185
exit(1)
186186
}
187-
187+
188188
let success = isDirectory ? verifier.verifyDirectory(path) : verifier.verify(jsonPath: path)
189189
if !success || verifier.hadErrors {
190-
191-
fputs("Verification failed\n", stdout)
190+
fputs("error: Verification failed\n", stderr)
192191
exit(1)
193192
}
194193

0 commit comments

Comments
 (0)