Update temp dir and tools dir
This commit is contained in:
parent
39b361ed69
commit
b42ed69542
3 changed files with 26 additions and 17 deletions
22
lib/runner.js
generated
22
lib/runner.js
generated
|
|
@ -6,9 +6,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
result["default"] = mod;
|
result["default"] = mod;
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const commander_1 = require("commander");
|
const commander_1 = require("commander");
|
||||||
const fs = __importStar(require("fs"));
|
const fs = __importStar(require("fs"));
|
||||||
|
const md5_1 = __importDefault(require("md5"));
|
||||||
const os = __importStar(require("os"));
|
const os = __importStar(require("os"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
const analyze_1 = require("./analyze");
|
const analyze_1 = require("./analyze");
|
||||||
|
|
@ -40,14 +44,16 @@ function parseGithubUrl(inputUrl) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function getTempDir(userInput) {
|
function getTempDir(userInput) {
|
||||||
const tempDir = path.join(userInput || os.tmpdir(), 'codeql-runner-temp');
|
const cwd = process.cwd();
|
||||||
|
const cwdHash = md5_1.default(cwd);
|
||||||
|
const tempDir = path.join(userInput || process.cwd(), 'codeql-runner', cwdHash);
|
||||||
if (!fs.existsSync(tempDir)) {
|
if (!fs.existsSync(tempDir)) {
|
||||||
fs.mkdirSync(tempDir, { recursive: true });
|
fs.mkdirSync(tempDir, { recursive: true });
|
||||||
}
|
}
|
||||||
return tempDir;
|
return tempDir;
|
||||||
}
|
}
|
||||||
function getToolsDir(userInput, tmpDir) {
|
function getToolsDir(userInput) {
|
||||||
const toolsDir = path.join(userInput || path.dirname(tmpDir), 'codeql-runner-tools');
|
const toolsDir = userInput || path.join(os.homedir(), 'codeql-runner-tools');
|
||||||
if (!fs.existsSync(toolsDir)) {
|
if (!fs.existsSync(toolsDir)) {
|
||||||
fs.mkdirSync(toolsDir, { recursive: true });
|
fs.mkdirSync(toolsDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
@ -64,13 +70,13 @@ program
|
||||||
.option('--queries <queries>', 'Comma-separated list of additional queries to run. By default, this overrides the same setting in a configuration file.')
|
.option('--queries <queries>', 'Comma-separated list of additional queries to run. By default, this overrides the same setting in a configuration file.')
|
||||||
.option('--config-file <file>', 'Path to config file')
|
.option('--config-file <file>', 'Path to config file')
|
||||||
.option('--codeql-path <path>', 'Path to a copy of the CodeQL CLI executable to use. Otherwise downloads a copy.')
|
.option('--codeql-path <path>', 'Path to a copy of the CodeQL CLI executable to use. Otherwise downloads a copy.')
|
||||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. Defaults to OS temp dir.')
|
.option('--temp-dir <dir>', 'Directory to use for temporary files. By default will use current working directory.')
|
||||||
.option('--tools-dir <dir>', 'Directory to use for CodeQL tools and other files to store between runs. Defaults to same as temp dir.')
|
.option('--tools-dir <dir>', 'Directory to use for CodeQL tools and other files to store between runs. By default will use home directory.')
|
||||||
.option('--checkout-path <path>', 'Checkout path (default: current working directory)')
|
.option('--checkout-path <path>', 'Checkout path (default: current working directory)')
|
||||||
.action(async (cmd) => {
|
.action(async (cmd) => {
|
||||||
try {
|
try {
|
||||||
const tempDir = getTempDir(cmd.tempDir);
|
const tempDir = getTempDir(cmd.tempDir);
|
||||||
const toolsDir = getToolsDir(cmd.toolsDir, tempDir);
|
const toolsDir = getToolsDir(cmd.toolsDir);
|
||||||
// Wipe the temp dir
|
// Wipe the temp dir
|
||||||
fs.rmdirSync(tempDir, { recursive: true });
|
fs.rmdirSync(tempDir, { recursive: true });
|
||||||
fs.mkdirSync(tempDir, { recursive: true });
|
fs.mkdirSync(tempDir, { recursive: true });
|
||||||
|
|
@ -124,7 +130,7 @@ program
|
||||||
.command('autobuild')
|
.command('autobuild')
|
||||||
.description('Attempts to automatically build code')
|
.description('Attempts to automatically build code')
|
||||||
.requiredOption('--language <language>', 'The language to build')
|
.requiredOption('--language <language>', 'The language to build')
|
||||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. Defaults to OS temp dir.')
|
.option('--temp-dir <dir>', 'Directory to use for temporary files. By default will use current working directory.')
|
||||||
.action(async (cmd) => {
|
.action(async (cmd) => {
|
||||||
try {
|
try {
|
||||||
const language = languages_1.parseLanguage(cmd.language);
|
const language = languages_1.parseLanguage(cmd.language);
|
||||||
|
|
@ -150,7 +156,7 @@ program
|
||||||
.option('--checkout-path <path>', 'Checkout path (default: current working directory)')
|
.option('--checkout-path <path>', 'Checkout path (default: current working directory)')
|
||||||
.option('--no-upload', 'Do not upload results after analysis', false)
|
.option('--no-upload', 'Do not upload results after analysis', false)
|
||||||
.option('--output-dir <dir>', 'Directory to output SARIF files to. By default will use temp directory.')
|
.option('--output-dir <dir>', 'Directory to output SARIF files to. By default will use temp directory.')
|
||||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. Defaults to OS temp dir.')
|
.option('--temp-dir <dir>', 'Directory to use for temporary files. By default will use current working directory.')
|
||||||
.action(async (cmd) => {
|
.action(async (cmd) => {
|
||||||
try {
|
try {
|
||||||
const tempDir = getTempDir(cmd.tempDir);
|
const tempDir = getTempDir(cmd.tempDir);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,5 +1,6 @@
|
||||||
import { Command } from 'commander';
|
import { Command } from 'commander';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
import md5 from 'md5';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
|
|
@ -38,15 +39,17 @@ function parseGithubUrl(inputUrl: string): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTempDir(userInput: string | undefined): string {
|
function getTempDir(userInput: string | undefined): string {
|
||||||
const tempDir = path.join(userInput || os.tmpdir(), 'codeql-runner-temp');
|
const cwd = process.cwd();
|
||||||
|
const cwdHash = md5(cwd);
|
||||||
|
const tempDir = path.join(userInput || process.cwd(), 'codeql-runner', cwdHash);
|
||||||
if (!fs.existsSync(tempDir)) {
|
if (!fs.existsSync(tempDir)) {
|
||||||
fs.mkdirSync(tempDir, { recursive: true });
|
fs.mkdirSync(tempDir, { recursive: true });
|
||||||
}
|
}
|
||||||
return tempDir;
|
return tempDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getToolsDir(userInput: string | undefined, tmpDir: string): string {
|
function getToolsDir(userInput: string | undefined): string {
|
||||||
const toolsDir = path.join(userInput || path.dirname(tmpDir), 'codeql-runner-tools');
|
const toolsDir = userInput || path.join(os.homedir(), 'codeql-runner-tools');
|
||||||
if (!fs.existsSync(toolsDir)) {
|
if (!fs.existsSync(toolsDir)) {
|
||||||
fs.mkdirSync(toolsDir, { recursive: true });
|
fs.mkdirSync(toolsDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
@ -78,13 +81,13 @@ program
|
||||||
.option('--queries <queries>', 'Comma-separated list of additional queries to run. By default, this overrides the same setting in a configuration file.')
|
.option('--queries <queries>', 'Comma-separated list of additional queries to run. By default, this overrides the same setting in a configuration file.')
|
||||||
.option('--config-file <file>', 'Path to config file')
|
.option('--config-file <file>', 'Path to config file')
|
||||||
.option('--codeql-path <path>', 'Path to a copy of the CodeQL CLI executable to use. Otherwise downloads a copy.')
|
.option('--codeql-path <path>', 'Path to a copy of the CodeQL CLI executable to use. Otherwise downloads a copy.')
|
||||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. Defaults to OS temp dir.')
|
.option('--temp-dir <dir>', 'Directory to use for temporary files. By default will use current working directory.')
|
||||||
.option('--tools-dir <dir>', 'Directory to use for CodeQL tools and other files to store between runs. Defaults to same as temp dir.')
|
.option('--tools-dir <dir>', 'Directory to use for CodeQL tools and other files to store between runs. By default will use home directory.')
|
||||||
.option('--checkout-path <path>', 'Checkout path (default: current working directory)')
|
.option('--checkout-path <path>', 'Checkout path (default: current working directory)')
|
||||||
.action(async (cmd: InitArgs) => {
|
.action(async (cmd: InitArgs) => {
|
||||||
try {
|
try {
|
||||||
const tempDir = getTempDir(cmd.tempDir);
|
const tempDir = getTempDir(cmd.tempDir);
|
||||||
const toolsDir = getToolsDir(cmd.toolsDir, tempDir);
|
const toolsDir = getToolsDir(cmd.toolsDir);
|
||||||
|
|
||||||
// Wipe the temp dir
|
// Wipe the temp dir
|
||||||
fs.rmdirSync(tempDir, { recursive: true });
|
fs.rmdirSync(tempDir, { recursive: true });
|
||||||
|
|
@ -168,7 +171,7 @@ program
|
||||||
.command('autobuild')
|
.command('autobuild')
|
||||||
.description('Attempts to automatically build code')
|
.description('Attempts to automatically build code')
|
||||||
.requiredOption('--language <language>', 'The language to build')
|
.requiredOption('--language <language>', 'The language to build')
|
||||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. Defaults to OS temp dir.')
|
.option('--temp-dir <dir>', 'Directory to use for temporary files. By default will use current working directory.')
|
||||||
.action(async (cmd: AutobuildArgs) => {
|
.action(async (cmd: AutobuildArgs) => {
|
||||||
try {
|
try {
|
||||||
const language = parseLanguage(cmd.language);
|
const language = parseLanguage(cmd.language);
|
||||||
|
|
@ -209,7 +212,7 @@ program
|
||||||
.option('--checkout-path <path>', 'Checkout path (default: current working directory)')
|
.option('--checkout-path <path>', 'Checkout path (default: current working directory)')
|
||||||
.option('--no-upload', 'Do not upload results after analysis', false)
|
.option('--no-upload', 'Do not upload results after analysis', false)
|
||||||
.option('--output-dir <dir>', 'Directory to output SARIF files to. By default will use temp directory.')
|
.option('--output-dir <dir>', 'Directory to output SARIF files to. By default will use temp directory.')
|
||||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. Defaults to OS temp dir.')
|
.option('--temp-dir <dir>', 'Directory to use for temporary files. By default will use current working directory.')
|
||||||
.action(async (cmd: AnalyzeArgs) => {
|
.action(async (cmd: AnalyzeArgs) => {
|
||||||
try {
|
try {
|
||||||
const tempDir = getTempDir(cmd.tempDir);
|
const tempDir = getTempDir(cmd.tempDir);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue