From a50eae752674d24f6768d227d5a0f4dc0c0d5a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Ch=C3=A1varri?= Date: Tue, 25 Feb 2020 07:19:13 +0100 Subject: [PATCH] Fix flags for BuckleScript packages so that ppxs binaries can be found (#360) * Fix FLG from Merlin for BuckleScript ppx-flags to point to node_modules/.bin * Add example for bs 7.0.1 * Change ppx path to include package folder and remove node_modules/.bin prefixing * use jsx3 and latest reason-react to see if this fixes windows ppx issues * try building whole project before running bsc commands * Revert "try building whole project before running bsc commands" This reverts commit eea2b94dc937eec86efed07b8f5349a64bff20c6. * call npm install from outside ExampleTests + use script instead of bash in yaml template * ggggaahhhhh * try to debug some stuff * add npm build and logging * run * try yarn * revert changes and use node 12 * yarn * namespace * try different example * appveyor simple * remove more * node 12 * y * f * n * Revert "n" This reverts commit d25fcf97ba9037839c33c9e617ba5ca9e6c1a4a8. * 64 * 2019 * roll back changes * remove new example --- src/analyze/Packages.re | 7 +++++-- util/MerlinFile.re | 4 ++-- util/MerlinFile.rei | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/analyze/Packages.re b/src/analyze/Packages.re index d265fe01..ab4f4b6a 100644 --- a/src/analyze/Packages.re +++ b/src/analyze/Packages.re @@ -161,7 +161,7 @@ let newBsPackage = (~overrideBuildSystem=?, ~reportDiagnostics, state, rootPath) let ppxs = config |> Json.get("ppx-flags") |?> Json.array |?>> Utils.filterMap(Json.string) |? []; Log.log("Getting hte ppxs yall"); let flags = flags @ (Belt.List.map(ppxs, name => { - MerlinFile.fixPpx("-ppx " ++ Filename.quote(name), rootPath) + MerlinFile.fixPpxBsNative("-ppx " ++ Filename.quote(name), rootPath) })); let flags = switch (config |> Json.get("warnings") |?> Json.get("number") |?> Json.string) { | None => flags @@ -171,7 +171,10 @@ let newBsPackage = (~overrideBuildSystem=?, ~reportDiagnostics, state, rootPath) "-ppx " ++ bsPlatform /+ "lib" /+ "bsppx.exe" ], opens) | _ => { - let flags = MerlinFile.getFlags(rootPath) |> RResult.withDefault([""]) |> List.map(escapePreprocessingFlags); + let flags = + MerlinFile.getFlags(rootPath) + |> RResult.withDefault([""]) + |> List.map(escapePreprocessingFlags); let opens = List.fold_left((opens, item) => { let parts = Utils.split_on_char(' ', item); let rec loop = items => switch items { diff --git a/util/MerlinFile.re b/util/MerlinFile.re index 2e8535d6..3bce3a9c 100644 --- a/util/MerlinFile.re +++ b/util/MerlinFile.re @@ -5,7 +5,7 @@ let debug = ref(false); let maybeLog = message => if (debug^) { Log.log("[MerlinFile]: " ++ message) }; /** This is a dirty hack to get around the bug in bsb native that doesn't do the proper ppx flags for ppxs */ -let fixPpx = (flg, base) => { +let fixPpxBsNative = (flg, base) => { switch (Str.split(Str.regexp_string(" "), flg)) { | ["-ppx", ppx] when Str.string_match(Str.regexp("[a-zA-Z_]+"), ppx, 0) && !Str.string_match(Str.regexp("[a-zA-Z_]:"), ppx, 0) => { "-ppx " ++ (base /+ "lib" /+ "bs" /+ "native" /+ String.lowercase_ascii(ppx) ++ ".native") @@ -19,7 +19,7 @@ let parseMerlin = (base, text) => { List.fold_left( ((source, build, flags), line) => { if (Utils.startsWith(line, "FLG ")) { - (source, build, [fixPpx(Utils.chopPrefix(line, "FLG "), base), ...flags]) + (source, build, [Utils.chopPrefix(line, "FLG "), ...flags]) } else if (Utils.startsWith(line, "S ")) { ([Utils.chopPrefix(line, "S "), ...source], build, flags) } else if (Utils.startsWith(line, "B ")) { diff --git a/util/MerlinFile.rei b/util/MerlinFile.rei index 99e7eeaf..e3b48e6e 100644 --- a/util/MerlinFile.rei +++ b/util/MerlinFile.rei @@ -1,5 +1,5 @@ let debug: ref(bool); -let fixPpx: (string, string) => string; +let fixPpxBsNative: (string, string) => string; let parseMerlin: (string, string) => (list(string), list(string), list(string)); let isRelativePath: string => bool; @@ -45,4 +45,4 @@ let getModulesFromMerlin: list(string), ); let getFlags: string => RResult.result(list(string), string); -let getBackend: string => RResult.result(string, string); \ No newline at end of file +let getBackend: string => RResult.result(string, string);