Skip to content

Instantly share code, notes, and snippets.

@hcarty
Created April 28, 2016 20:01
Show Gist options
  • Save hcarty/7d2c7710ab85a618134ea3401d9d4cb1 to your computer and use it in GitHub Desktop.
Save hcarty/7d2c7710ab85a618134ea3401d9d4cb1 to your computer and use it in GitHub Desktop.
Simple/stupid _oasis -> .merlin
let get_findlib = function
| OASISTypes.FindlibPackage (findlib, _) -> Some findlib
| OASISTypes.InternalLibrary _ -> None
let get_build_deps { OASISTypes.bs_build_depends; _ } =
List.map get_findlib bs_build_depends
let get_build = function
| OASISTypes.Library (_, build, _)
| OASISTypes.Object (_, build, _)
| OASISTypes.Executable (_, build, _) -> Some build
| OASISTypes.Flag _
| OASISTypes.SrcRepo _
| OASISTypes.Test _
| OASISTypes.Doc _ -> None
let pkgs_of_section section =
match get_build section with
| Some build ->
List.fold_left (
fun accu opt ->
match opt with
| None -> accu
| Some x -> x :: accu
) [] (get_build_deps build)
| None -> []
let paths_of_section section =
match get_build section with
| Some { OASISTypes.bs_path; _ } -> Some bs_path
| None -> None
let () =
let file = Sys.argv.(1) in
let ctxt = { OASISContext.quiet with OASISContext.ignore_plugins = true } in
let package = OASISParse.from_file ~ctxt file in
let sections = package.OASISTypes.sections in
let findlibs =
List.map pkgs_of_section sections
|> List.concat
|> List.sort_uniq String.compare
in
let paths =
List.map paths_of_section sections
|> List.fold_left (fun accu o -> match o with Some x -> x :: accu | None -> accu) []
|> List.sort_uniq String.compare
in
Printf.printf "PKG %s\n" (String.concat ", " findlibs);
List.iter (
fun path ->
Printf.printf "S %s\n" path;
Printf.printf "B _build/%s\n" path
) paths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment