Skip to content

Commit b81ba05

Browse files
Fix GenType path test on CI
Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
1 parent a45573b commit b81ba05

3 files changed

Lines changed: 42 additions & 17 deletions

File tree

rewatch/src/build/parse.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,18 +436,11 @@ fn generate_ast(
436436
// generate the dir of the ast_path (it mirrors the source file dir)
437437
let ast_parent_path = package.get_build_path().join(ast_path.parent().unwrap());
438438
helpers::create_path(&ast_parent_path);
439-
// Keep absolute source locations in the AST in the same path form as the
440-
// canonical project root passed during compilation. This matters for
441-
// Windows paths that have both short and expanded representations.
442-
let parse_working_dir = build_path_abs
443-
.canonicalize()
444-
.map(helpers::StrippedVerbatimPath::to_stripped_verbatim_path)
445-
.unwrap_or_else(|_| build_path_abs.clone());
446439

447440
/* Create .ast */
448441
let result = match Some(
449442
Command::new(&build_state.compiler_info.bsc_path)
450-
.current_dir(&parse_working_dir)
443+
.current_dir(&build_path_abs)
451444
.args(parser_args)
452445
.output()
453446
.map_err(|e| {

rewatch/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ impl Config {
10291029
}
10301030

10311031
pub fn get_project_root_args(&self) -> Vec<String> {
1032-
// The parser records locations from a canonical working directory.
1032+
// Package discovery gives the parser a canonical working directory.
10331033
// Use the same representation here so GenType can strip this prefix,
10341034
// including when Windows supplied the project through an 8.3 path.
10351035
let root = self

rewatch/tests/gentype/project-root.mjs

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,44 @@ import {join} from "node:path";
66

77
const executable = process.env.REWATCH_EXECUTABLE;
88
assert(executable, "REWATCH_EXECUTABLE must be set");
9-
const executableForNode =
10-
process.platform === "win32" && existsSync(`${executable}.cmd`) ? `${executable}.cmd` : executable;
9+
10+
function runBuild(buildDirectory) {
11+
if (process.platform !== "win32") {
12+
return spawnSync(executable, ["build"], {
13+
cwd: buildDirectory,
14+
encoding: "utf8",
15+
env: process.env,
16+
timeout: 30_000,
17+
});
18+
}
19+
20+
const executablePath = executable.endsWith(".exe") ? executable : `${executable}.exe`;
21+
const commandShim = executable.endsWith(".cmd") ? executable : `${executable}.cmd`;
22+
const resolvedExecutable = existsSync(executablePath)
23+
? executablePath
24+
: existsSync(commandShim)
25+
? commandShim
26+
: executable;
27+
28+
return spawnSync(
29+
process.env.ComSpec ?? "cmd.exe",
30+
[
31+
"/d",
32+
"/s",
33+
"/c",
34+
'cd /d "%REWATCH_TEST_PROJECT%" && "%REWATCH_TEST_EXECUTABLE%" build',
35+
],
36+
{
37+
encoding: "utf8",
38+
env: {
39+
...process.env,
40+
REWATCH_TEST_EXECUTABLE: resolvedExecutable,
41+
REWATCH_TEST_PROJECT: buildDirectory,
42+
},
43+
timeout: 30_000,
44+
},
45+
);
46+
}
1147

1248
function getBuildDirectory(projectDir) {
1349
if (process.platform !== "win32") {
@@ -55,12 +91,8 @@ try {
5591
);
5692

5793
const buildDirectory = getBuildDirectory(projectDir);
58-
const result = spawnSync(executableForNode, ["build"], {
59-
cwd: buildDirectory,
60-
encoding: "utf8",
61-
env: process.env,
62-
timeout: 30_000,
63-
});
94+
assert(existsSync(buildDirectory), `Build directory does not exist: ${buildDirectory}`);
95+
const result = runBuild(buildDirectory);
6496

6597
assert.ifError(result.error);
6698
assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`);

0 commit comments

Comments
 (0)