Skip to content

Commit

Permalink
Fix bug with cd for input directories
Browse files Browse the repository at this point in the history
  • Loading branch information
mdales committed May 21, 2024
1 parent cef12b7 commit 497adfa
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/lib/md.ml
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,36 @@ let process_run_block ?(env_override = []) ~fs ~build_cache ~pool store ast
]
@ List.map (fun (k, v) -> Obuilder_spec.env k v) environment
@ target_dirs leaf
(* @ links *)
@ [ Obuilder_spec.run ~network:[ "host" ] ~rom "%s" cmdstr ])
in
let process pool (_outputs, build_hash, workdir, env) leaf cmdstr =

let process pool (_outputs, build_hash, workdir, env) leaf file_subs_map
cmdstr =
Eio.Pool.use pool @@ fun () ->
let command = Leaf.command leaf in
Logs.debug (fun f -> f "Processing command: %a" Command.pp command);
match Command.name command with
| "cd" ->
(* If a command block is a call to `cd` we treat this similarly to Docker's
WORKDIR command which changes the working directory of the context *)

(* If the dir is in the inputs we should substitute it, otherwise we assume it's a new dir in this
current image. *)
let path =
Fpath.to_string (List.nth (Command.file_args command) 0)
in
let inspected_path =
match List.assoc_opt path file_subs_map with
| None -> path
| Some pl -> List.nth pl 0
in

let cmd_result = CommandResult.v ~build_hash cmdstr in
{
cmd_result;
build_hash;
success = true;
workdir = Fpath.to_string (List.nth (Command.file_args command) 0);
workdir = inspected_path;
env;
}
| "export" ->
Expand Down Expand Up @@ -321,7 +334,9 @@ let process_run_block ?(env_override = []) ~fs ~build_cache ~pool store ast
[] paths
in
let inputs = Leaf.to_string_for_inputs leaf l in
let processed_blocks = Fiber.List.map (process pool acc leaf) inputs in
let processed_blocks =
Fiber.List.map (process pool acc leaf l) inputs
in
let results, _hash, _pwd, _env = acc in
let { build_hash; workdir; env; _ } = List.hd processed_blocks in
(processed_blocks :: results, build_hash, workdir, env)
Expand Down

0 comments on commit 497adfa

Please sign in to comment.