forked from CycloneDX/cdxgen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbinary.js
66 lines (61 loc) · 1.53 KB
/
binary.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const os = require("os");
const fs = require("fs");
const path = require("path");
const { spawnSync } = require("child_process");
// Debug mode flag
const DEBUG_MODE =
process.env.SCAN_DEBUG_MODE === "debug" ||
process.env.SHIFTLEFT_LOGGING_LEVEL === "debug" ||
process.env.NODE_ENV === "development";
let platform = os.platform();
let extn = "";
if (platform === "win32") {
platform = "windows";
extn = ".exe";
}
let arch = os.arch();
switch (arch) {
case "x32":
arch = "386";
break;
case "x64":
arch = "amd64";
break;
}
let GOVERSION_BIN = null;
if (fs.existsSync(path.join(__dirname, "plugins", "goversion"))) {
GOVERSION_BIN = path.join(
__dirname,
"plugins",
"goversion",
"goversion-" + platform + "-" + arch + extn
);
}
const getGoBuildInfo = (src) => {
if (GOVERSION_BIN) {
let result = spawnSync(GOVERSION_BIN, [src], {
encoding: "utf-8",
});
if (result.status === 1 || result.error) {
console.error(result.stdout, result.stderr);
if (DEBUG_MODE) {
console.log("Falling back to go version command");
}
result = spawnSync("go", ["version", "-v", "-m", src], {
encoding: "utf-8",
});
if (result.status === 1 || result.error) {
console.error(result.stdout, result.stderr);
}
}
if (result) {
const stdout = result.stdout;
if (stdout) {
const cmdOutput = Buffer.from(stdout).toString();
return cmdOutput;
}
}
}
return undefined;
};
exports.getGoBuildInfo = getGoBuildInfo;