Skip to content

Commit

Permalink
Merge pull request #921 from neon-bindings/kv/unlink-before-copy
Browse files Browse the repository at this point in the history
fix(cargo-cp-artifact): Unlink .node files before copying to flush macOS code signature cache
  • Loading branch information
kjvalencik authored Aug 26, 2022
2 parents e7ac0a4 + 871d67a commit e7c733a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkgs/cargo-cp-artifact/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cargo-cp-artifact",
"version": "0.1.6",
"version": "0.1.7",
"description": "Copies compiler artifacts emitted by rustc by parsing Cargo metadata",
"main": "src/index.js",
"files": [
Expand Down
22 changes: 20 additions & 2 deletions pkgs/cargo-cp-artifact/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

const { spawn } = require("child_process");
const {
promises: { copyFile, mkdir, stat },
promises: { copyFile, mkdir, stat, unlink },
} = require("fs");
const { dirname } = require("path");
const { dirname, extname } = require("path");
const readline = require("readline");

const { ParseError, getArtifactName, parse } = require("./args");
Expand Down Expand Up @@ -122,6 +122,24 @@ async function copyArtifact(filename, outputFile) {
await mkdir(outputDir, { recursive: true });
}

// Apple Silicon (M1, etc.) requires shared libraries to be signed. However,
// the macOS code signing cache isn't cleared when overwriting a file.
// Deleting the file before copying works around the issue.
//
// Unfortunately, this workaround is incomplete because the file must be
// deleted from the location it is loaded. If further steps in the user's
// build process copy or move the file in place, the code signing cache
// will not be cleared.
//
// https://github.com/neon-bindings/neon/issues/911
if (extname(outputFile) === ".node") {
try {
await unlink(outputFile);
} catch (_e) {
// Ignore errors; the file might not exist
}
}

await copyFile(filename, outputFile);
}

Expand Down
2 changes: 1 addition & 1 deletion test/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"repository": "https://github.com/electron/electron-quick-start",
"devDependencies": {
"@playwright/test": "^1.23.1",
"cargo-cp-artifact": "^0.1.6",
"cargo-cp-artifact": "^0.1.7",
"electron": "^19.0.7",
"playwright": "^1.23.1"
}
Expand Down
2 changes: 1 addition & 1 deletion test/napi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"test": "mocha --v8-expose-gc --timeout 5000 --recursive lib"
},
"devDependencies": {
"cargo-cp-artifact": "^0.1.6",
"cargo-cp-artifact": "^0.1.7",
"chai": "^4.3.6",
"mocha": "^10.0.0"
}
Expand Down

0 comments on commit e7c733a

Please sign in to comment.