2 * Copyright (C) 2019 Richard W.M. Jones
3 * Copyright (C) 2019 Red Hat Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 (* See comment in parser.mly. *)
26 Parser.lexer_read := Some Lexer.read;
27 Parser.eval_substitute := Some Eval.substitute
30 (* Handle the command line. *)
31 let anon_vars, targets = Cmdline.parse () in
33 (* Change directory (-C option). *)
34 Sys.chdir (Cmdline.directory ());
36 (* Create the initial environment, containing the system environment
37 * and a few other standard strings.
42 let k, v = split "=" environ in
43 Ast.Env.add k (Ast.EConstant (Ast.noloc, Ast.CString v)) env
44 ) Ast.Env.empty (Unix.environment ()) in
47 (Ast.EConstant (Ast.noloc, Ast.CString Cmdline.stdlibdir))
50 if Cmdline.debug_flag then Ast.Env.add "debug" (Ast.EConstant (noloc, Ast.CBool true)) env else env in *)
52 (* Parse the prelude. *)
54 if Cmdline.use_prelude () then
55 Parse.parse_goalfile env Cmdline.prelude_gl_file
58 (* Parse the input file. *)
59 let env = Parse.parse_goalfile env (Cmdline.input_file ()) in
61 (* Parse the command line assignments. *)
64 fun env (name, expr) ->
65 let expr = Parse.parse_expr "commandline" expr in
66 Ast.Env.add name expr env
69 (* Parse the target expressions. *)
70 let targets = List.map (Parse.parse_expr "commandline") targets in
72 (* If no target was set on the command line, use "all ()". *)
74 if targets <> [] then targets
75 else [Ast.ECall (Ast.noloc, "all", [])] in
77 if Cmdline.debug_flag () then
78 Ast.print_env stderr env;
80 (* Construct the dependency DAG with the root(s) being the targets. *)
81 let dag = Deps.create env targets in
84 let state = Deps.new_state dag Run.goal_runner Run.exists_runner in
85 let next_job () = Deps.next_job state in
86 let retire_job job = Deps.retire_job state job in
87 let string_of_job job = Deps.string_of_job job in
88 Jobs.run next_job retire_job string_of_job
93 | Failure msg | Sys_error msg ->
94 prerr_endline ("*** error: " ^ msg);