Skip to content

Commit

Permalink
Merge pull request #46 from microsoft/fix-redirect-code-traces
Browse files Browse the repository at this point in the history
[dexnode] Always use a temp file for `--redirect-code-traces-to`
  • Loading branch information
rbuckton authored Sep 21, 2023
2 parents 4e6df0e + 72e9d68 commit 769bcf5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 34 deletions.
2 changes: 1 addition & 1 deletion tools/dexnode/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dexnode",
"version": "1.2.1",
"version": "1.2.2",
"description": "Run NodeJS with logging options needed by Deopt Explorer",
"type": "module",
"bin": {
Expand Down
16 changes: 0 additions & 16 deletions tools/dexnode/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,6 @@ export function canAccess(file: string, mode: "write" | "exec") {
}
}

export function canAppend(file: string) {
try {
const fd = fs.openSync(file, "a");
try {
const stat = fs.fstatSync(fd);
return !!(stat.mode & fs.constants.S_IFREG);
}
finally {
fs.closeSync(fd);
}
}
catch {
return false;
}
}

export async function regQuery(hive: string, key: string, valueName: string = Registry.DEFAULT_VALUE) {
const reg = new Registry({ hive, key });
const keyExists = await new Promise<boolean>((res, rej) => reg.keyExists((err, exists) => err ? rej(err) : res(exists)));
Expand Down
23 changes: 6 additions & 17 deletions tools/dexnode/src/v8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import path from "path";
import semver from "semver";
import { Options } from "./args.js";
import { HostFlags } from "./hostFlags.js";
import { canAppend } from "./util.js";

const NULL_DEVICE =
process.platform === "win32" ? "\\\\.\\NUL" :
canAppend("/dev/null") ? "/dev/null" :
null;

export type CleanupCallback = () => Promise<void> | void;

Expand All @@ -31,18 +25,13 @@ function prepareDeopts(argv: Options, version: V8Version, flags: string[], clean

if (!argv._.includes("--redirect-code-traces")) {
flags.push("--redirect-code-traces");
if (NULL_DEVICE) {
flags.push(`--redirect-code-traces-to=${NULL_DEVICE}`);
try {
const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), "dexnode-"));
const asmfile = path.join(tmpdir, "code.asm");
flags.push(`--redirect-code-traces-to=${asmfile}`);
cleanupSteps.push(() => fs.promises.rm(tmpdir, { recursive: true, force: true }));
}
else {
try {
const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), "dexnode-"));
const asmfile = path.join(tmpdir, "code.asm");
flags.push(`--redirect-code-traces-to=${asmfile}`);
cleanupSteps.push(() => fs.promises.rm(tmpdir, { recursive: true, force: true }));
}
catch {
}
catch {
}
}
}
Expand Down

0 comments on commit 769bcf5

Please sign in to comment.