Add a (mkdir ...) action

This commit is contained in:
Jeremie Dimino 2017-05-29 14:51:46 +01:00
parent 65a54f405b
commit 1d3341ed28
5 changed files with 25 additions and 4 deletions

View File

@ -135,6 +135,7 @@ struct
| Update_file (x, y) -> List [Atom "update-file"; path x; string y]
| Rename (x, y) -> List [Atom "rename"; path x; path y]
| Remove_tree x -> List [Atom "remove-tree"; path x]
| Mkdir x -> List [Atom "mkdir"; path x]
end
module type Ast = Action_intf.Ast
@ -186,7 +187,8 @@ module Unexpanded = struct
| Bash x -> f acc x
| Update_file (x, y) -> f (f acc x) y
| Rename (x, y) -> f (f acc x) y
| Remove_tree x -> f acc x
| Remove_tree x
| Mkdir x -> f acc x
let fold_vars t ~init ~f =
fold t ~init ~f:(fun acc pat ->
@ -224,6 +226,8 @@ module Unexpanded = struct
Rename (expand_path ~dir ~f x, expand_path ~dir ~f y)
| Remove_tree x ->
Remove_tree (expand_path ~dir ~f x)
| Mkdir x ->
Mkdir (expand_path ~dir ~f x)
end
let fold_one_step t ~init:acc ~f =
@ -244,7 +248,8 @@ let fold_one_step t ~init:acc ~f =
| Bash _
| Update_file _
| Rename _
| Remove_tree _ -> acc
| Remove_tree _
| Mkdir _ -> acc
let rec map t ~fs ~fp =
match t with
@ -272,6 +277,7 @@ let rec map t ~fs ~fp =
| Update_file (x, y) -> Update_file (fp x, fs y)
| Rename (x, y) -> Rename (fp x, fp y)
| Remove_tree x -> Remove_tree (fp x)
| Mkdir x -> Mkdir (fp x)
let updated_files =
let rec loop acc t =
@ -395,6 +401,16 @@ let rec exec t ~purpose ~dir ~env ~env_extra ~stdout_to ~stderr_to =
| Remove_tree path ->
Path.rm_rf path;
return ()
| Mkdir path ->
(match Path.kind path with
| External _ ->
(* CR-someday jdimino: we need to keep locations here *)
die "(mkdir ...) is not supported for paths outside of the workspace:\n\
\ %a\n"
Sexp.pp (List [Atom "mkdir"; Path.sexp_of_t path])
| Local path ->
Path.Local.mkdir_p path);
return ()
and redirect outputs fn t ~purpose ~dir ~env ~env_extra ~stdout_to ~stderr_to =
let fn = Path.to_string fn in
@ -485,6 +501,7 @@ module Infer = struct
{ acc with targets = S.filter acc.targets ~f:(fun fn ->
not (Path.is_descendant fn ~of_:dir))
}
| Mkdir _ -> acc
let infer t =
infer { deps = S.empty; targets = S.empty } t

View File

@ -27,5 +27,6 @@ module type Ast = sig
| Update_file of path * string
| Rename of path * path
| Remove_tree of path
| Mkdir of path
end

View File

@ -245,6 +245,9 @@ let create_file fn =
let remove_tree dir =
arr (fun _ -> Action.Remove_tree dir)
let mkdir dir =
arr (fun _ -> Action.Mkdir dir)
let progn ts =
all ts >>^ fun actions ->
Action.Progn actions

View File

@ -110,6 +110,7 @@ val symlink : src:Path.t -> dst:Path.t -> (unit, Action.t) t
val create_file : Path.t -> (_, Action.t) t
val remove_tree : Path.t -> (_, Action.t) t
val mkdir : Path.t -> (_, Action.t) t
(** Merge a list of actions *)
val progn : ('a, Action.t) t list -> ('a, Action.t) t

View File

@ -48,8 +48,7 @@ let to_html sctx (m : Module.t) odoc_file ~doc_dir ~odoc ~dir ~includes
>>>
Build.progn
[ Build.remove_tree html_dir
; Build.action (* CR-someday jdimino: this is a mkdir ... *)
(Chdir (html_dir, Progn [])) ~targets:[]
; Build.mkdir html_dir
; Build.run ~context ~dir odoc ~extra_targets:[html_file]
[ A "html"
; Dyn (fun x -> x)