mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 14:18:04 +08:00
Fix issue from timeout
This commit is contained in:
@@ -255,57 +255,27 @@ function generateRustLicenses(): LicenseInfo[] | undefined {
|
|||||||
console.info("\n\nGenerating license information for Rust code\n");
|
console.info("\n\nGenerating license information for Rust code\n");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// DEBUG:
|
|
||||||
|
|
||||||
// Print all programs in the PATH
|
|
||||||
console.info("\n\nPrograms in PATH:\n");
|
|
||||||
const pathDirs = process.env.PATH?.split(path.delimiter) || [];
|
|
||||||
pathDirs.forEach((dir) => {
|
|
||||||
try {
|
|
||||||
const files = fs.readdirSync(dir);
|
|
||||||
files.forEach((file) => {
|
|
||||||
const filePath = path.join(dir, file);
|
|
||||||
try {
|
|
||||||
if (fs.statSync(filePath).isFile()) {
|
|
||||||
fs.accessSync(filePath, fs.constants.X_OK);
|
|
||||||
console.info(filePath);
|
|
||||||
}
|
|
||||||
} catch (_accessErr) {
|
|
||||||
// Ignore files that are not executable
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
console.error(`Error reading directory ${dir}:`, err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// END DEBUG
|
|
||||||
|
|
||||||
// Call `cargo about` in the terminal to generate the license information for Rust crates.
|
// Call `cargo about` in the terminal to generate the license information for Rust crates.
|
||||||
// The `about.hbs` file is written so it generates a valid JavaScript array expression which we evaluate below.
|
// The `about.hbs` file is written so it generates a valid JavaScript array expression which we evaluate below.
|
||||||
const spawnReturn = spawnSync("cargo", ["about", "generate", "about.hbs"], {
|
const { stdout, stderr, status, error } = spawnSync("cargo", ["about", "generate", "about.hbs"], {
|
||||||
cwd: path.join(__dirname, ".."),
|
cwd: path.join(__dirname, ".."),
|
||||||
encoding: "utf8",
|
encoding: "utf8",
|
||||||
timeout: 60000, // One minute
|
timeout: 5 * 60000, // Five minutes
|
||||||
shell: true,
|
shell: true,
|
||||||
windowsHide: true, // Hide the terminal on Windows
|
windowsHide: true, // Hide the terminal on Windows
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("spawnReturn:\n", spawnReturn);
|
|
||||||
console.log("spawnReturn JSON:\n", JSON.stringify(spawnReturn));
|
|
||||||
|
|
||||||
// If the command failed, print the error message and exit early.
|
// If the command failed, print the error message and exit early.
|
||||||
if (spawnReturn.status !== 0) {
|
if (status !== 0) {
|
||||||
// Cargo returns 101 when the subcommand (`about`) wasn't found, so we skip printing the below error message in that case.
|
// Cargo returns 101 when the subcommand (`about`) wasn't found, so we skip printing the below error message in that case.
|
||||||
if (spawnReturn.status !== 101) {
|
if (status !== 101) console.error("cargo-about failed.\n", "Status: ", status, "Error: ", error, "\nstderr:", stderr);
|
||||||
console.error("cargo-about failed", spawnReturn.status, spawnReturn.stderr);
|
|
||||||
}
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the output starts with this expected label, which lets us know the file generated with expected output.
|
// Make sure the output starts with this expected label, which lets us know the file generated with expected output.
|
||||||
// We don't want to eval an error message or something else, so we fail early if that happens.
|
// We don't want to eval an error message or something else, so we fail early if that happens.
|
||||||
if (!spawnReturn.stdout.trim().startsWith("GENERATED_BY_CARGO_ABOUT:")) {
|
if (!stdout.trim().startsWith("GENERATED_BY_CARGO_ABOUT:")) {
|
||||||
console.error("Unexpected output from cargo-about", spawnReturn.stdout);
|
console.error("Unexpected output from cargo-about", stdout);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,7 +283,7 @@ function generateRustLicenses(): LicenseInfo[] | undefined {
|
|||||||
// Security-wise, eval() isn't any worse than require(), but it's able to work without a temporary file.
|
// Security-wise, eval() isn't any worse than require(), but it's able to work without a temporary file.
|
||||||
// We call eval indirectly to avoid a warning as explained here: <https://esbuild.github.io/content-types/#direct-eval>.
|
// We call eval indirectly to avoid a warning as explained here: <https://esbuild.github.io/content-types/#direct-eval>.
|
||||||
const indirectEval = eval;
|
const indirectEval = eval;
|
||||||
const licensesArray = indirectEval(spawnReturn.stdout) as LicenseInfo[];
|
const licensesArray = indirectEval(stdout) as LicenseInfo[];
|
||||||
|
|
||||||
// Remove the HTML character encoding caused by Handlebars.
|
// Remove the HTML character encoding caused by Handlebars.
|
||||||
const rustLicenses = (licensesArray || []).map(
|
const rustLicenses = (licensesArray || []).map(
|
||||||
|
|||||||
Reference in New Issue
Block a user