Add clean subcommand (#89)

This commit is contained in:
Richard Davison 2017-05-26 06:32:32 -04:00 committed by Jérémie Dimino
parent 469e1ff744
commit 91d03de221
6 changed files with 34 additions and 2 deletions

View File

@ -22,7 +22,8 @@ all-supported-ocaml-versions:
$(BIN) build @install @runtest --workspace jbuild-workspace.dev --root .
clean:
rm -rf _build
-$(BIN) clean
-rm -f ./boot.exe
doc:
cd doc && sphinx-build . _build

View File

@ -426,6 +426,24 @@ let runtest =
$ Arg.(value & pos_all string ["."] name_))
, Term.info "runtest" ~doc ~man)
let clean =
let doc = "Clean the project." in
let man =
[ `S "DESCRIPTION"
; `P {|Removes files added by jbuilder such as _build, <package>.install, and .merlin|}
; `Blocks help_secs
]
in
let go common =
begin
set_common common ~targets:[];
Build_system.all_targets_ever_built () |> List.iter ~f:Path.unlink_no_err;
Path.(rm_rf (append root (of_string "_build")))
end
in
( Term.(const go $ common)
, Term.info "clean" ~doc ~man)
let format_external_libs libs =
String_map.bindings libs
|> List.map ~f:(fun (name, kind) ->
@ -776,6 +794,7 @@ let all =
; external_lib_deps
; build_targets
; runtest
; clean
; install
; uninstall
; exec

View File

@ -8,6 +8,7 @@ let commands =
; "install"
; "installed-libraries"
; "runtest"
; "clean"
; "uninstall"
; "exec"
; "subst"

View File

@ -561,6 +561,13 @@ module Trace = struct
trace
end
let all_targets_ever_built () =
if Sys.file_exists Trace.file then
let trace = Trace.load () in
Hashtbl.fold trace ~init:[] ~f:(fun ~key ~data:_ acc -> key :: acc)
else
[]
let create ~contexts ~file_tree ~rules =
let all_source_files =
File_tree.fold file_tree ~init:Pset.empty ~f:(fun dir acc ->

View File

@ -61,3 +61,7 @@ val build_rules
-> ?recursive:bool (* default false *)
-> Path.t list
-> Rule.t list Future.t
val all_targets_ever_built
: unit
-> Path.t list

View File

@ -1,6 +1,6 @@
open Import
(** In the current worksapce (anything under the current project root) *)
(** In the current workspace (anything under the current project root) *)
module Local : sig
type t