-
Notifications
You must be signed in to change notification settings - Fork 7
Convert binary plist files to xml and use a proper parser when linking #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,50 +1,184 @@ | ||
| import assert from "node:assert/strict"; | ||
| import { describe, it } from "node:test"; | ||
| import path from "node:path"; | ||
| import { readInfoPlist } from "./apple"; | ||
| import fs from "node:fs"; | ||
|
|
||
| import { | ||
| determineInfoPlistPath, | ||
| readInfoPlist, | ||
| updateInfoPlist, | ||
| } from "./apple"; | ||
| import { setupTempDirectory } from "../test-utils"; | ||
|
|
||
| describe("apple", () => { | ||
| describe("Info.plist lookup", () => { | ||
| it("should find Info.plist files in unversioned frameworks", async (context) => { | ||
| describe("determineInfoPlistPath", () => { | ||
| it("should find Info.plist files in unversioned frameworks", (context) => { | ||
| const infoPlistContents = `<?xml version="1.0" encoding="UTF-8"?>...`; | ||
| const infoPlistSubPath = "Info.plist"; | ||
| const tempDirectoryPath = setupTempDirectory(context, { | ||
| [infoPlistSubPath]: infoPlistContents, | ||
| }); | ||
|
|
||
| const result = await readInfoPlist(tempDirectoryPath); | ||
|
|
||
| assert.strictEqual(result.contents, infoPlistContents); | ||
| assert.strictEqual( | ||
| result.infoPlistPath, | ||
| determineInfoPlistPath(tempDirectoryPath), | ||
| path.join(tempDirectoryPath, infoPlistSubPath), | ||
| ); | ||
| }); | ||
|
|
||
| it("should find Info.plist files in versioned frameworks", async (context) => { | ||
| it("should find Info.plist files in versioned frameworks", (context) => { | ||
| const infoPlistContents = `<?xml version="1.0" encoding="UTF-8"?>...`; | ||
| const infoPlistSubPath = "Versions/Current/Resources/Info.plist"; | ||
| const tempDirectoryPath = setupTempDirectory(context, { | ||
| [infoPlistSubPath]: infoPlistContents, | ||
| }); | ||
|
|
||
| const result = await readInfoPlist(tempDirectoryPath); | ||
|
|
||
| assert.strictEqual(result.contents, infoPlistContents); | ||
| assert.strictEqual( | ||
| result.infoPlistPath, | ||
| determineInfoPlistPath(tempDirectoryPath), | ||
| path.join(tempDirectoryPath, infoPlistSubPath), | ||
| ); | ||
| }); | ||
|
|
||
| it("should throw if Info.plist is missing from framework", async (context) => { | ||
| it("should throw if Info.plist is missing from framework", (context) => { | ||
| const tempDirectoryPath = setupTempDirectory(context, {}); | ||
|
|
||
| assert.throws( | ||
| () => determineInfoPlistPath(tempDirectoryPath), | ||
| /Unable to locate an Info.plist file within framework./, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("readInfoPlist", () => { | ||
| it("should read Info.plist contents", async (context) => { | ||
| const infoPlistContents = ` | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>CFBundleExecutable</key> | ||
| <string>ExecutableFileName</string> | ||
| <key>CFBundleIconFile</key> | ||
| <string>AppIcon</string> | ||
| </dict> | ||
| </plist> | ||
| `; | ||
| const infoPlistSubPath = "Info.plist"; | ||
| const tempDirectoryPath = setupTempDirectory(context, { | ||
| [infoPlistSubPath]: infoPlistContents, | ||
| }); | ||
| const infoPlistPath = path.join(tempDirectoryPath, infoPlistSubPath); | ||
|
|
||
| const contents = await readInfoPlist(infoPlistPath); | ||
| assert.deepEqual(contents, { | ||
| CFBundleExecutable: "ExecutableFileName", | ||
| CFBundleIconFile: "AppIcon", | ||
| }); | ||
| }); | ||
|
|
||
| it("should throw if Info.plist doesn't exist", async (context) => { | ||
| const tempDirectoryPath = setupTempDirectory(context, {}); | ||
| const infoPlistPath = path.join(tempDirectoryPath, "Info.plist"); | ||
|
|
||
| await assert.rejects( | ||
| async () => readInfoPlist(tempDirectoryPath), | ||
| /Unable to read Info.plist for framework at path ".*?", as an Info.plist file couldn't be found./, | ||
| () => readInfoPlist(infoPlistPath), | ||
| /Unable to read Info.plist at path/, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("updateInfoPlist", () => { | ||
| it( | ||
| "updates an xml plist", | ||
| { skip: process.platform !== "darwin" }, | ||
| async (context) => { | ||
| const infoPlistSubPath = "Info.plist"; | ||
| const tempDirectoryPath = setupTempDirectory(context, { | ||
| [infoPlistSubPath]: ` | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>CFBundleExecutable</key> | ||
| <string>addon</string> | ||
| </dict> | ||
| </plist> | ||
| `, | ||
| }); | ||
|
|
||
| await updateInfoPlist({ | ||
| frameworkPath: tempDirectoryPath, | ||
| oldLibraryName: "addon", | ||
| newLibraryName: "new-addon-name", | ||
| }); | ||
|
|
||
| const contents = await fs.promises.readFile( | ||
| path.join(tempDirectoryPath, infoPlistSubPath), | ||
| "utf-8", | ||
| ); | ||
| assert.match(contents, /<\?xml version="1.0" encoding="UTF-8"\?>/); | ||
| assert.match( | ||
| contents, | ||
| /<key>CFBundleExecutable<\/key>\s*<string>new-addon-name<\/string>/, | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| it( | ||
| "converts a binary plist to xml", | ||
| { skip: process.platform !== "darwin" }, | ||
| async (context) => { | ||
| const tempDirectoryPath = setupTempDirectory(context, {}); | ||
| // Write a binary plist file | ||
| const binaryPlistContents = Buffer.from( | ||
| // Generated running "base64 -i <path-to-binary-plist>" on a plist file from a framework in the node-examples package | ||
| "YnBsaXN0MDDfEBUBAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4cICEiIyQiJSYnJChfEBNCdWlsZE1hY2hpbmVPU0J1aWxkXxAZQ0ZCdW5kbGVEZXZlbG9wbWVudFJlZ2lvbl8QEkNGQnVuZGxlRXhlY3V0YWJsZV8QEkNGQnVuZGxlSWRlbnRpZmllcl8QHUNGQnVuZGxlSW5mb0RpY3Rpb25hcnlWZXJzaW9uXxATQ0ZCdW5kbGVQYWNrYWdlVHlwZV8QGkNGQnVuZGxlU2hvcnRWZXJzaW9uU3RyaW5nXxARQ0ZCdW5kbGVTaWduYXR1cmVfEBpDRkJ1bmRsZVN1cHBvcnRlZFBsYXRmb3Jtc18QD0NGQnVuZGxlVmVyc2lvbl8QFUNTUmVzb3VyY2VzRmlsZU1hcHBlZFpEVENvbXBpbGVyXxAPRFRQbGF0Zm9ybUJ1aWxkXkRUUGxhdGZvcm1OYW1lXxARRFRQbGF0Zm9ybVZlcnNpb25aRFRTREtCdWlsZFlEVFNES05hbWVXRFRYY29kZVxEVFhjb2RlQnVpbGRfEBBNaW5pbXVtT1NWZXJzaW9uXlVJRGV2aWNlRmFtaWx5VjI0RzIzMVdFbmdsaXNoVWFkZG9uXxAPZXhhbXBsZV82LmFkZG9uUzYuMFRGTVdLUzEuMFQ/Pz8/oR9fEA9pUGhvbmVTaW11bGF0b3IJXxAiY29tLmFwcGxlLmNvbXBpbGVycy5sbHZtLmNsYW5nLjFfMFYyMkMxNDZfEA9pcGhvbmVzaW11bGF0b3JUMTguMl8QE2lwaG9uZXNpbXVsYXRvcjE4LjJUMTYyMFgxNkM1MDMyYaEpEAEACAA1AEsAZwB8AJEAsQDHAOQA+AEVAScBPwFKAVwBawF/AYoBlAGcAakBvAHLAdIB2gHgAfIB9gH7Af8CBAIGAhgCGQI+AkUCVwJcAnICdwKAAoIAAAAAAAACAQAAAAAAAAAqAAAAAAAAAAAAAAAAAAAChA==", | ||
| "base64", | ||
| ); | ||
| const binaryPlistPath = path.join(tempDirectoryPath, "Info.plist"); | ||
| await fs.promises.writeFile(binaryPlistPath, binaryPlistContents); | ||
|
|
||
| await updateInfoPlist({ | ||
| frameworkPath: tempDirectoryPath, | ||
| oldLibraryName: "addon", | ||
| newLibraryName: "new-addon-name", | ||
| }); | ||
|
|
||
| const contents = await fs.promises.readFile(binaryPlistPath, "utf-8"); | ||
| assert.match(contents, /<\?xml version="1.0" encoding="UTF-8"\?>/); | ||
| assert.match( | ||
| contents, | ||
| /<key>CFBundleExecutable<\/key>\s*<string>new-addon-name<\/string>/, | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| it( | ||
| "throws when not on darwin", | ||
| { skip: process.platform === "darwin" }, | ||
| async (context) => { | ||
| const tempDirectoryPath = setupTempDirectory(context, { | ||
| ["Info.plist"]: '<?xml version="1.0" encoding="UTF-8"?>', | ||
| }); | ||
|
|
||
| await assert.rejects( | ||
| () => | ||
| updateInfoPlist({ | ||
| frameworkPath: tempDirectoryPath, | ||
| oldLibraryName: "addon", | ||
| newLibraryName: "new-addon-name", | ||
| }), | ||
| (err) => { | ||
| assert(err instanceof Error); | ||
| assert.match(err.message, /Failed to convert Info.plist at path/); | ||
| assert(err.cause instanceof Error); | ||
| assert.match( | ||
| err.cause.message, | ||
| /Updating Info.plist files are not supported on this platform/, | ||
| ); | ||
| return true; | ||
| }, | ||
| ); | ||
| }, | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Info.plist Update Incomplete
The
updateInfoPlistfunction now only updatesCFBundleExecutable. Unlike the previous global string replacement, this misses other fields likeCFBundleIdentifierandCFBundleName, leading to inconsistencies in the Info.plist file and potential framework linking issues.