Skip to content
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

fix(cargo-cp-artifact): Hotfix for change in cargo diagnostics naming #1039

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, "-");
kjvalencik marked this conversation as resolved.
Show resolved Hide resolved

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
Loading