Skip to content

Instantly share code, notes, and snippets.

@superbobry
Created October 26, 2011 14:39
Show Gist options
  • Save superbobry/1316541 to your computer and use it in GitHub Desktop.
Save superbobry/1316541 to your computer and use it in GitHub Desktop.
fetch a list of depends from _oasis file
#use "topfind"
#require "oasis.base"
open OASISTypes
open OASISVersion
let (|>) x f = f x
let find_all_depends =
let rec inner acc = function
| [] -> acc
| Library (_, { bs_build_depends; _ }, _) :: sections
| Executable (_, { bs_build_depends; _ }, _) :: sections ->
let findlib_depends = List.fold_left
(fun acc -> function
| FindlibPackage (name, Some v) ->
Printf.sprintf "%s(%s)" name (string_of_comparator v) :: acc
| FindlibPackage (name, None) ->
name :: acc
| _ -> acc
) [] bs_build_depends
in inner (acc @ findlib_depends) sections
| _ :: sections -> inner acc sections
in inner []
let is_library =
List.exists (function Library _ -> true | _ -> false)
let is_executable =
List.exists (function Executable _ -> true | _ -> false)
let () =
let oasis_fn = Sys.argv.(1) in
let { sections; _ } = OASISParse.from_file
~ctxt:{!BaseContext.default with OASISContext.ignore_plugins = true}
oasis_fn
in
List.iter (fun name -> print_endline name) (find_all_depends sections);
print_endline (if is_executable sections then "is executable" else "is not executable");
print_endline (if is_library sections then "is library" else "is not library")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment