Skip to content

Commit f523b11

Browse files
jaredlybsansouci
andauthored
Report error for edge case for bsb-native. (#382)
* Report error for edge case for bsb-native. ... where .merlin has -backend but bsconfig's entries got updated and don't have that backend anymore. * merge in Co-authored-by: Benjamin San Souci <benjamin.sansouci@gmail.com>
1 parent 4cb1f7e commit f523b11

File tree

4 files changed

+54
-65
lines changed

4 files changed

+54
-65
lines changed

examples/example-react/package-lock.json

Lines changed: 12 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analyze/BuildCommand.re

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,41 @@ let rec getAffectedFiles = (root, lines) => switch lines {
3232
let runBuildCommand = (~reportDiagnostics, state, root, buildCommand) => {
3333
/** TODO check for a bsb.lock file & bail if it's there */
3434
/** TODO refactor so Dune projects don't get bsconfig.json handling below */
35-
let%opt_consume (buildCommand, commandDirectory) = buildCommand;
36-
Log.log(">> Build system running: " ++ buildCommand);
37-
let (stdout, stderr, _success) = Commands.execFull(~pwd=commandDirectory, buildCommand);
38-
Log.log(">>> stdout");
39-
Log.log(Utils.joinLines(stdout));
40-
Log.log(">>> stderr");
41-
Log.log(Utils.joinLines(stderr));
42-
let files = getAffectedFiles(commandDirectory, stdout @ stderr);
43-
Log.log("Affected files: " ++ String.concat(" ", files));
44-
let bsconfigJson = root /+ "bsconfig.json" |> Utils.toUri;
45-
let bsconfigClean = ref(true);
46-
files |. Belt.List.forEach(uri => {
47-
if (Utils.endsWith(uri, "bsconfig.json")) {
48-
bsconfigClean := false;
49-
Log.log("Bsconfig.json sending");
50-
reportDiagnostics(
51-
uri, `BuildFailed(stdout @ stderr)
52-
)
53-
};
54-
Hashtbl.remove(state.compiledDocuments, uri);
55-
Hashtbl.replace(state.documentTimers, uri, Unix.gettimeofday() -. 0.01)
56-
});
57-
if (bsconfigClean^) {
58-
Log.log("Cleaning bsconfig.json");
59-
reportDiagnostics(bsconfigJson, `BuildSucceeded)
35+
switch buildCommand {
36+
| None => Ok()
37+
| Some((buildCommand, commandDirectory)) =>
38+
Log.log(">> Build system running: " ++ buildCommand);
39+
let (stdout, stderr, _success) = Commands.execFull(~pwd=commandDirectory, buildCommand);
40+
Log.log(">>> stdout");
41+
Log.log(Utils.joinLines(stdout));
42+
Log.log(">>> stderr");
43+
let errors = Utils.joinLines(stderr);
44+
Log.log(errors);
45+
let%try _ = if (Utils.startsWith(errors, "Error: Could not find an item in the entries field to compile to ")) {
46+
Error("Bsb-native " ++ errors ++ "\nHint: check your bsconfig's \"entries\".")
47+
} else {
48+
Ok();
49+
};
50+
let files = getAffectedFiles(commandDirectory, stdout @ stderr);
51+
Log.log("Affected files: " ++ String.concat(" ", files));
52+
let bsconfigJson = root /+ "bsconfig.json" |> Utils.toUri;
53+
let bsconfigClean = ref(true);
54+
files |. Belt.List.forEach(uri => {
55+
if (Utils.endsWith(uri, "bsconfig.json")) {
56+
bsconfigClean := false;
57+
Log.log("Bsconfig.json sending");
58+
reportDiagnostics(
59+
uri, `BuildFailed(stdout @ stderr)
60+
)
61+
};
62+
Hashtbl.remove(state.compiledDocuments, uri);
63+
Hashtbl.replace(state.documentTimers, uri, Unix.gettimeofday() -. 0.01)
64+
});
65+
if (bsconfigClean^) {
66+
Log.log("Cleaning bsconfig.json");
67+
reportDiagnostics(bsconfigJson, `BuildSucceeded)
68+
};
69+
/* TODO report notifications here */
70+
Ok()
6071
}
61-
/* TODO report notifications here */
6272
};

src/analyze/Packages.re

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ let newBsPackage = (~overrideBuildSystem=?, ~reportDiagnostics, state, rootPath)
7070
Log.log("- buildSystem: " ++ BuildSystem.show(buildSystem));
7171
Log.log("- build command: " ++ buildCommand);
7272

73-
if (state.settings.autoRebuild) {
73+
let%try () = if (state.settings.autoRebuild) {
7474
BuildCommand.runBuildCommand(~reportDiagnostics, state, rootPath, Some((buildCommand, rootPath)));
75-
};
75+
} else { Ok() };
7676

7777
let compiledBase = BuildSystem.getCompiledBase(rootPath, buildSystem);
7878
let%try stdLibDirectories = BuildSystem.getStdlib(rootPath, buildSystem);
@@ -331,9 +331,9 @@ let newJbuilderPackage = (~overrideBuildSystem=?, ~reportDiagnostics, state, roo
331331
}
332332
};
333333

334-
if (state.settings.autoRebuild) {
334+
let%try () = if (state.settings.autoRebuild) {
335335
BuildCommand.runBuildCommand(~reportDiagnostics, state, rootPath, buildCommand);
336-
};
336+
} else { Ok() };
337337

338338
let%try compilerPath = BuildSystem.getCompiler(projectRoot, buildSystem);
339339
let%try compilerVersion = BuildSystem.getCompilerVersion(compilerPath);

src/lsp/NotificationHandlers.re

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ let checkPackageTimers = state => {
3636
Hashtbl.iter((_, package) => {
3737
if (package.rebuildTimer != 0. && package.rebuildTimer < Unix.gettimeofday()) {
3838
package.rebuildTimer = 0.;
39-
BuildCommand.runBuildCommand(~reportDiagnostics, state, package.basePath, package.buildCommand);
39+
// TODO report the error here
40+
ignore @@ BuildCommand.runBuildCommand(~reportDiagnostics, state, package.basePath, package.buildCommand);
4041
}
4142
}, state.packagesByRoot)
4243
};

0 commit comments

Comments
 (0)