Skip to content

Commit

Permalink
BuckleScript runs the PPX while in ./lib/bs
Browse files Browse the repository at this point in the history
Fixes #311.
  • Loading branch information
aantron committed Apr 19, 2020
1 parent 0787f20 commit 2d06cbc
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/ppx/exclusions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ let add s =
let patterns = List.map (fun x -> Regular_expression (Str.regexp x)) patterns in
excluded := patterns @ !excluded

let add_file filename =
let ch = open_in filename in
let add_from_channel filename ch =
let lexbuf = Lexing.from_channel ch in
try
let res = Exclude_parser.file Exclude_lexer.token lexbuf in
Expand All @@ -35,6 +34,21 @@ let add_file filename =
close_in_noerr ch;
raise e

let add_file filename =
(* BuckleScript runs the PPX from PROJECT_ROOT/lib/bs. *)
let cwd = Sys.getcwd () in
let parent = Filename.basename cwd in
let grandparent = Filename.(basename (dirname cwd)) in

let channel =
if grandparent = "lib" && parent = "bs" then
try open_in (Filename.(concat (dirname (dirname cwd))) filename)
with Sys_error _ -> open_in filename
else
open_in filename
in
add_from_channel filename channel

let match_pattern pattern name =
Str.string_match pattern name 0 && Str.match_end () = String.length name

Expand Down

0 comments on commit 2d06cbc

Please sign in to comment.