From 7c8405972520d732b8f662dc4a55eec95364b92d Mon Sep 17 00:00:00 2001 From: Leonardo Date: Tue, 31 Jan 2017 20:27:09 +0100 Subject: [PATCH] Adds command line option to dump a list of all the files necessary to compile the given input files. --- src/core/typesVult.ml | 2 ++ src/loader.ml | 5 ++++- src/vult_main.ml | 16 ++++++++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/core/typesVult.ml b/src/core/typesVult.ml index fa9cc514..42bae3af 100644 --- a/src/core/typesVult.ml +++ b/src/core/typesVult.ml @@ -212,6 +212,7 @@ type arguments = mutable template : string; mutable show_version : bool; mutable includes : string list; + mutable deps : bool; } let default_arguments = @@ -227,6 +228,7 @@ let default_arguments = template = "default"; show_version = false; includes = []; + deps = false; } let makeAttr (loc:Loc.t) : attr = diff --git a/src/loader.ml b/src/loader.ml index fe591603..5b121797 100644 --- a/src/loader.ml +++ b/src/loader.ml @@ -66,7 +66,10 @@ let rec loadFiles_loop (includes:string list) dependencies parsed (files:string |> List.map List.hd in (* finds all the files for the used modules *) - let h_dep_files = List.map (findModule includes) h_deps in + let h_dep_files = + List.map (findModule includes) h_deps + |> List.filter (fun a -> a<>h) + in (* updates the tables *) let () = Hashtbl.add dependencies h_module h_deps in let () = Hashtbl.add parsed h_module h_parsed in diff --git a/src/vult_main.ml b/src/vult_main.ml index 24d2d15c..90545b2c 100644 --- a/src/vult_main.ml +++ b/src/vult_main.ml @@ -28,6 +28,7 @@ let processArguments () : arguments = let result = { default_arguments with files = [] } in let opts = [ "-dparse", (Arg.Unit (fun () -> result.dparse <-true)), " Dumps the parse tree (default: off)"; + "-deps", (Arg.Unit (fun () -> result.deps <-true)), " Prints all file dependencies"; "-ccode", (Arg.Unit (fun () -> result.ccode <-true)), " Converts the code to c (default: off)"; "-jscode", (Arg.Unit (fun () -> result.jscode <-true)), " Converts the code to javascript (default: off)"; "-luacode", (Arg.Unit (fun () -> result.luacode <-true)), " Converts the code to lua (default: off)"; @@ -65,7 +66,14 @@ let main () = print_endline "no input files" | _ -> let parser_results = parseFiles args args.files in - (* Prints the parsed files if -dparse was passed as argument *) - Driver.dumpParsedFiles args parser_results; - Driver.generateCode args parser_results |> ignore; - Driver.runFiles args parser_results |> ignore + if args.deps then + List.map (fun r -> r.file) parser_results + |> String.concat " " + |> print_endline + else + begin + (* Prints the parsed files if -dparse was passed as argument *) + Driver.dumpParsedFiles args parser_results; + Driver.generateCode args parser_results |> ignore; + Driver.runFiles args parser_results |> ignore + end