Skip to content

Commit

Permalink
Added a 'brb install' stub -- #23
Browse files Browse the repository at this point in the history
  • Loading branch information
superbobry committed Mar 10, 2012
1 parent 569e9ff commit c4ca20c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
17 changes: 13 additions & 4 deletions bin/brb.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ open Common


let () =
let specs = [("--only-deps", Arg.Set Barbra.only_deps,
let only_deps = ref false and force_build = ref false in
let specs = [("--only-deps", Arg.Set only_deps,
"Act on dependencies only, ignoring project sources");
("--force", Arg.Set Barbra.force_build,
("--force", Arg.Set force_build,
"Force build, even if the '_dep' directory already exists")]
in

Expand All @@ -13,8 +14,8 @@ let () =
~synopsis:"Build the project in the current directory"
~help:("Assumes that '_dep' directory doesn't exist or contains\n" ^
"*already* built dependencies, listed in 'brb.conf'.")
Barbra.build
in SubCommand.register ({ scmd with SubCommand.specs = specs })
(fun () -> Barbra.build ~only_deps:!only_deps ~force_build:!force_build)
in SubCommand.(register { scmd with specs = specs })
and () = SubCommand.register & SubCommand.make
~name:"clean"
~synopsis:"Remove '_dep' directory with built dependencies"
Expand All @@ -24,6 +25,14 @@ and () = SubCommand.register & SubCommand.make
~synopsis:"Fetch the latest 'purse' full of fresh recipes!"
~help:"Clones or updates 'purse' repository in $HOME/.brb/recipes."
Barbra.update
and () =
let arg = ref "" in
let cmd = SubCommand.make
~name:"install"
~synopsis:"Install a single recipe to the '_dep' directory"
~usage:"recipe"
(fun () -> Barbra.install !arg)
in SubCommand.(register { cmd with anon = (:=) arg })
and () =
let args = ref [] in
let cmd = SubCommand.make
Expand Down
39 changes: 18 additions & 21 deletions src/barbra.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,11 @@ open Common

include Global

let only_deps = ref false
let force_build = ref false
(* Internal. *)

(** [with_config f] Executes a given function, passing parsed config
file as an argument. *)
let with_config f =
let conf = base_dir </> brb_conf in
if Sys.file_exists conf then
f (Config.from_file conf)
else
Log.error "can't find brb.conf in %S" base_dir

(* assuming we are in project's root dir *)
let rec build_deps () =
let rec go = function
| [] -> Log.info "Dependencies built successfully!"
| ({ name; package; _ } as dep) :: conf ->
let build_deps = let rec go = function
| [] -> Log.info "Dependencies built successfully!"
| ({ name; package; _ } as dep) :: conf ->
let go_temp_dir project_path =
go & { dep with package = Temporary (`Directory, project_path) }
:: conf
Expand Down Expand Up @@ -81,7 +69,7 @@ let rec build_deps () =
| Installed | Recipe _ ->
go conf
end
in with_config go
in go

and build_project () = begin
Log.info "Building the project (from %S)" base_dir;
Expand All @@ -94,11 +82,17 @@ and build_project () = begin
Log.info "Project built successfully!"
end

and build () =
if not (Filew.is_directory dep_dir) || !force_build then begin
(* Public API. *)

let rec build ~only_deps ~force_build =
let conf_path = base_dir </> brb_conf in
if not (Filew.is_file conf_path) then
Log.error "can't find %s in %S" brb_conf base_dir;

if not (Filew.is_directory dep_dir) || force_build then begin
cleanup ();
build_deps ();
if not !only_deps then
build_deps (Config.from_file conf_path);
if not only_deps then
build_project ()
end

Expand All @@ -118,5 +112,8 @@ and update () =
exec_exn ["git"; "clone"; "https://github.com/camlunity/purse.git";
recipe_dir]

and install _recipe =
()

and run_with_env cmd =
Res.exn_res (Env.exec_with_env cmd)

0 comments on commit c4ca20c

Please sign in to comment.