Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.2k
Do not silently install cargo-about.#377
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
+60
−21
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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
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,18 +1,37 @@ | ||
| /* eslint-disable @typescript-eslint/no-var-requires */ | ||
| /* eslint-disable @typescript-eslint/no-var-requires, no-console */ | ||
| const path = require("path"); | ||
| const { unlink } = require("fs"); | ||
| const { spawnSync } = require("child_process"); | ||
| const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin"); | ||
| const LicenseCheckerWebpackPlugin = require("license-checker-webpack-plugin"); | ||
| let rustLicenses = []; | ||
| let debugMode = false; | ||
| try { | ||
| // eslint-disable-next-line global-require, import/extensions, import/no-unresolved | ||
| rustLicenses = require("./rust-licenses"); | ||
| } catch (_) { | ||
| // Rust licenses are not generated by Cargo About except in release mode (`npm run build`) | ||
| debugMode = true; | ||
| function generateRustLicenses() { | ||
| console.info("Generating license information for rust code"); | ||
| const { stdout, stderr, status } = spawnSync("cargo", ["about", "generate", "about.hbs"], { | ||
| cwd: path.join(__dirname, ".."), | ||
| encoding: "utf8", | ||
| timeout: 60000, // one minute | ||
| shell: true, | ||
| windowsHide: true, // hide the DOS window on windows | ||
| }); | ||
| if (status !== 0) { | ||
| if (status !== 101) { | ||
| // cargo returns 101 when the subcommand wasn't found | ||
| console.error("cargo-about failed", status, stderr); | ||
| } | ||
| return null; | ||
| } | ||
| // Make sure the output starts as expected, we don't want to eval an error message. | ||
| if (!stdout.trim().startsWith("GENERATED_BY_CARGO_ABOUT:")) { | ||
| console.error("Unexpected output from cargo-about", stdout); | ||
| return null; | ||
| } | ||
| // Security-wise, eval() isn't any worse than require(), but it doesn't need a temporary file. | ||
| // eslint-disable-next-line no-eval | ||
| return eval(stdout); | ||
| } | ||
| module.exports = { | ||
| @@ -78,8 +97,27 @@ module.exports = { | ||
| }; | ||
| function formatThirdPartyLicenses(jsLicenses) { | ||
| let rustLicenses = null; | ||
| if (process.env.NODE_ENV === "production") { | ||
| try { | ||
| rustLicenses = generateRustLicenses(); | ||
| } catch (e) { | ||
| // Nothing to show. Error messages were printed above. | ||
| } | ||
| if (rustLicenses === null) { | ||
| // This is probably caused by cargo about not being installed | ||
| console.error(` | ||
| Could not run 'cargo about', which is required to generate license information. | ||
| To install cargo-about on your system, you can run: | ||
| cargo install cargo-about | ||
| License information is required on production builds. Aborting.`); | ||
| process.exit(1); | ||
| } | ||
| } | ||
| // Remove the HTML character encoding caused by Handlebars | ||
| let licenses = rustLicenses.map((rustLicense) => ({ | ||
| let licenses = (rustLicenses || []).map((rustLicense) => ({ | ||
| licenseName: htmlDecode(rustLicense.licenseName), | ||
| licenseText: trimBlankLines(htmlDecode(rustLicense.licenseText)), | ||
| packages: rustLicense.packages.map((package) => ({ | ||
| @@ -131,7 +169,7 @@ function formatThirdPartyLicenses(jsLicenses) { | ||
| // Generate the formatted text file | ||
| let formattedLicenseNotice = "GRAPHITE THIRD-PARTY SOFTWARE LICENSE NOTICES\n\n"; | ||
| if (debugMode) formattedLicenseNotice += "WARNING: Licenses for Rust packages are excluded in debug mode to improve performance — do not release without their inclusion!\n\n"; | ||
| if (!rustLicenses) formattedLicenseNotice += "WARNING: Licenses for Rust packages are excluded in debug mode to improve performance — do not release without their inclusion!\n\n"; | ||
Keavon marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| licenses.forEach((license) => { | ||
| let packagesWithSameLicense = ""; | ||
| @@ -153,9 +191,6 @@ ${license.licenseText} | ||
| `; | ||
| }); | ||
| // Clean up by deleting the `rust-licenses.js` Rust licenses data file generated by Cargo About | ||
| unlink("./rust-licenses.js", (_) => _); | ||
| return formattedLicenseNotice; | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.