diff --git a/bin/brb.ml b/bin/brb.ml index 7b64bcf..3fc243a 100644 --- a/bin/brb.ml +++ b/bin/brb.ml @@ -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 @@ -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" @@ -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 diff --git a/src/barbra.ml b/src/barbra.ml index 94a19f2..c42533d 100644 --- a/src/barbra.ml +++ b/src/barbra.ml @@ -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 @@ -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; @@ -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 @@ -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)