Skip to content

Commit

Permalink
fix(cargo-cp-artifact): Hotfix for change in cargo diagnostics naming
Browse files Browse the repository at this point in the history
  • Loading branch information
kjvalencik committed May 10, 2024
1 parent c4a8e9b commit a328375
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
4 changes: 4 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# `cargo-cp-artifact`

`0.1.9` supports a [breaking change in `cargo`](https://github.com/rust-lang/cargo/issues/13867) that converts artifact names from `kebab-case` to `snake_case`.

# Version 1.0.0

## Commitment to Compatibility
Expand Down
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.8",
"version": "0.1.9",
"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 @@ -80,8 +80,8 @@ function processCargoBuildLine(options, copied, line) {
// `kind` and `filenames` zip up as key/value pairs
kinds.forEach((kind, i) => {
const filename = filenames[i];
const key = getArtifactName({ artifactType: kind, crateName: name });
const outputFiles = options.artifacts[key];
const { key, outputFiles } =
getOutputFiles(kind, name, options.artifacts) || {};

if (!outputFiles || !filename) {
return;
Expand All @@ -100,6 +100,24 @@ function processCargoBuildLine(options, copied, line) {
});
}

function getOutputFiles(kind, name, artifacts) {
const key = getArtifactName({ artifactType: kind, crateName: name });
const outputFiles = artifacts[key];

if (outputFiles) {
return { key, outputFiles };
}

// Cargo started replacing `-` with `_` in artifact names. Reverse the process
// and check again. https://github.com/rust-lang/cargo/issues/13867
const altKey = key.replace(/_/g, "-");

return {
key: altKey,
outputFiles: artifacts[altKey],
};
}

async function isNewer(filename, outputFile) {
try {
const prevStats = await stat(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.40.1",
"cargo-cp-artifact": "^0.1.8",
"cargo-cp-artifact": "^0.1.9",
"electron": "^27.1.3",
"playwright": "^1.40.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 @@ -10,7 +10,7 @@
"test": "mocha --v8-expose-gc --timeout 5000 --recursive lib"
},
"devDependencies": {
"cargo-cp-artifact": "^0.1.8",
"cargo-cp-artifact": "^0.1.9",
"chai": "^4.3.10",
"mocha": "^10.2.0"
}
Expand Down

0 comments on commit a328375

Please sign in to comment.