Commits

ccorrodi committed 52d2fab

replace command variables later

The last commit mad all tests fail, because command variable were replaced when
building the ast. Now, we only replace it during the "generate_commands"
function, meaning that functions like printing the ast or printing the database
still show the variable names. Printing the database with the variable names
fixes the failing tests.

Comments (0)

Files changed (2)

 
 (** Represent a rule as found in the "implicit rules" and "files" section.
 
-    TODO 2012-10-29: Do we need to store r_next?
-    *)
+    TODO 2012-10-29: Do we need to store r_next? *)
 type rule = {
   r_next : rule option;
   r_targets : string list;
 let s_of_rule_commands (r : rule) : string =
   String.concat "" (L.map s_of_command r.r_commands)
 
+(** Get a string list of commands to be executed by sh. *)
+let s_list_of_rule_commands (r : rule) : string list =
+  L.map s_of_command r.r_commands
+
 (** Convert the rule targets to a string. *)
 let s_of_rule_targets (r : rule) : string =
   String.concat " " r.r_targets
   S.global_replace (S.regexp "^.*$") (String.make i '\t' ^ "\\0") s
 
 (** Create a list of commands based on our own data structures, not the data
-from the head of the database file. *)
+    from the head of the database file. *)
 let generate_commands (d : database) (ts : target list) : string =
   (* header / footer *)
   let head = Printf.sprintf "# Generating commands for targets \"%s\"\n"
           else before in
 
         (* return commands *)
-        let commands = s_of_rule_commands rule in
+        let commands = s_list_of_rule_commands rule in
+        let commands = replace_variables d.d_variables commands in
+        let commands = String.concat "\n" commands in
         let commands = U.re_replace "\n+$" "\n" commands in
 
         before ^ commands
   let process_rule (d : A.database) (cur : A.rule) (next : A.rule) : A.rule =
     let targets = cur.A.r_targets in
     let prereqs = cur.A.r_deps in
-    let commands = A.replace_variables d.A.d_variables (cur.A.r_commands) in
+    let commands = cur.A.r_commands in
     let terminal = cur.A.r_terminal in
     let in_use = cur.A.r_in_use in
     let rule =