Skip to content

Commit

Permalink
Removed 'targets' -- now 'Build' should be a *complete* build command
Browse files Browse the repository at this point in the history
  • Loading branch information
superbobry committed Feb 21, 2012
1 parent ff5adad commit 9330505
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 64 deletions.
3 changes: 1 addition & 2 deletions brb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ Dep oasis remote "http://forge.ocamlcore.org/frs/download.php/501/oasis-0.2.0.ta
Patch "_patches/oasis-ounit-1.1.1.patch"

Dep cmdliner remote "http://erratique.ch/software/cmdliner/releases/cmdliner-0.9.0.tbz"
BuildCmd "./build"
Build "./build"
Install "./build install"

29 changes: 15 additions & 14 deletions src/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
open Common
open Types

type meta = [ `Make of string
type meta = [ `Build of string
| `Install of string
| `Flag of string
| `Patch of string
| `Install of string
| `BuildCmd of string
| `Requires of string list ]

type dep = (string * string * string * meta list)
Expand Down Expand Up @@ -68,20 +67,22 @@ let to_dep ((name, _source, _location, metas) as ast) =
(* Note(superbobry): fold an assorted list of meta fields into
three categories -- make targets, configure flags and patches;
the order is preserved. *)
let (buildcmd, targets, flags, patches, installcmd, requires) = List.fold_left metas
~init:("make", [], [], [], "make install", [])
~f:(fun (bc, ts, fs, ps, ins, rs) meta -> match meta with
| `BuildCmd x -> (x, ts, fs, ps, ins, rs)
| `Make t -> (bc, t::ts, fs, ps, ins, rs)
| `Flag f ->
(bc, ts, (String.nsplit f " ") @ fs, ps, ins, rs)
| `Patch p -> (bc, ts, fs, p :: ps, ins, rs)
| `Requires r -> (bc, ts, fs, ps, ins, rs @ r)
| `Install i -> (bc, ts, fs, ps, i, rs)
let (build_cmd, install_cmd, flags, patches, requires) =
List.fold_left metas
~init:("make", "make install", [], [], [])
~f:(fun (bc, ins, fs, ps, rs) meta -> match meta with
| `Build bc -> (bc, ins, fs, ps, rs)
| `Install ins -> (bc, ins, fs, ps, rs)
| `Flag f ->
(bc, ins, (String.nsplit f " ") @ fs, ps, rs)
| `Patch p -> (bc, ins, fs, p :: ps, rs)
| `Requires r -> (bc, ins, fs, ps, rs @ r)
)
in

{
name;
package = to_package ast;
targets; requires; flags; patches; installcmd; buildcmd
install_cmd; build_cmd;
requires; flags; patches;
}
16 changes: 7 additions & 9 deletions src/barbra.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let cleanup () =
let build_deps () =
let rec go = function
| [] -> Log.info "Dependencies built successfully!"
| ({ name; package; flags; targets; patches; _ } as dep) :: conf ->
| ({ name; package; _ } as dep) :: conf ->
let go_temp_dir project_path =
go & { dep with package = Temporary (`Directory, project_path) }
:: conf
Expand Down Expand Up @@ -71,11 +71,10 @@ let build_deps () =
let () = Res.exn_res &
Install.makefile#install
~source_dir:project_path
~flags
~targets
~patches
~buildcmd: dep.buildcmd
~installcmd: dep.installcmd
~build_cmd:dep.build_cmd
~install_cmd:dep.install_cmd
~flags:dep.flags
~patches:dep.patches
in

Log.info "Removing successfully built %S" project_path;
Expand All @@ -93,10 +92,9 @@ let build_project () = begin
Log.info "Building the project (from %S)" base_dir;
Res.exn_res & Install.makefile#install
~source_dir:base_dir
~build_cmd:"make"
~install_cmd:"make install"
~flags:[]
~targets:[]
~installcmd:"make install"
~buildcmd:"make"
~patches:[];
Log.info "Project built succesfully!"
end
Expand Down
5 changes: 3 additions & 2 deletions src/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ and from_lexbuf lexbuf =
let deps = List.map deps ~f:(fun ast ->
let dep = Ast.to_dep ast in match dep.package with
| Recipe location ->
let ({ targets; patches; flags; _ } as resolved) =
let ({ patches; flags; _ } as resolved) =
world#resolve ~repository:location ~recipe:dep.name
in

(* FIXME(superbobry): what if both 'recipe' and 'brb.conf'
have build or install commands? *)
{ resolved with
targets = targets @ dep.targets;
patches = patches @ dep.patches;
flags = flags @ dep.flags
}
Expand Down
28 changes: 8 additions & 20 deletions src/install.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,8 @@ module G = Global

let (>>=) = Res.(>>=)

let guess_command installcmd =
try
let (i,l) = String.index installcmd ' ', String.length installcmd in
(String.sub installcmd 0 i, String.sub installcmd (i+1) (l-i-1) )
with
| Not_found -> (installcmd,"")

let makefile : install_type = object
method install ~source_dir ~flags ~targets ~patches ~buildcmd ~installcmd = begin
method install ~source_dir ~build_cmd ~install_cmd ~flags ~patches = begin
G.create_dirs ();
Env.write_env ();

Expand All @@ -30,7 +23,6 @@ let makefile : install_type = object

WithRes.bindres WithRes.with_sys_chdir source_dir & fun _old_path ->
Env.with_env & fun () ->
let make = getenv ~default:"make" "MAKE" in
(if Sys.file_exists "configure" then
let flags =
if Sys.file_exists "_oasis"
Expand All @@ -47,16 +39,12 @@ let makefile : install_type = object
exec (["sh" ; "./configure"] @ flags)
else
Res.return ()
) >>= fun () -> (
match buildcmd with
| "make" ->
let () = Log.info "Starting Makefile build" in
exec (make :: targets)
| _ ->
exec (buildcmd :: targets)
) >>= fun () ->
let (cmd,args) = guess_command installcmd in
let cmd = if cmd = "make" then make else cmd in
exec [cmd; args]
) >>= fun () -> exec (String.nsplit build_cmd " ") >>= fun () ->
(* FIXME(superbobry): use $MAKE as default command and resolve
env variables with a special function. *)
match String.nsplit install_cmd " " with
| "make" :: args ->
exec (getenv ~default:"make" "MAKE" :: args)
| cmd -> exec cmd
end
end
3 changes: 1 addition & 2 deletions src/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
let keywords = Hashtbl.create 9
let () = List.iter (fun (kwd, token) -> Hashtbl.add keywords kwd token) [
("dep", DEP);
("make", MAKE);
("buildcmd", BUILDCMD);
("build", BUILD);
("flag", FLAG);
("patch", PATCH);
("install", INSTALL);
Expand Down
5 changes: 2 additions & 3 deletions src/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

%token VERSION
%token REPOSITORY DEP
%token MAKE FLAG PATCH REQUIRES INSTALL BUILDCMD
%token MAKE FLAG PATCH REQUIRES INSTALL BUILD
%token COMMA
%token EOF
%token <string> IDENT
Expand Down Expand Up @@ -40,8 +40,7 @@ meta_list:
;

meta:
| MAKE VALUE {`Make $2}
| BUILDCMD VALUE {`BuildCmd $2}
| BUILD VALUE {`Build $2}
| FLAG VALUE {`Flag $2}
| PATCH VALUE {`Patch $2}
| INSTALL VALUE {`Install $2}
Expand Down
22 changes: 10 additions & 12 deletions src/types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ type package =

type dep =
{
name : string;
package : package;
requires : string list;
targets : string list; (* targets for buildcmd *)
flags : string list;
patches : string list;
buildcmd : string;
installcmd : string
name : string;
package : package;
requires : string list;
flags : string list;
patches : string list;
build_cmd : string;
install_cmd : string
}

let vcs_type_of_string s = match String.lowercase s with
Expand Down Expand Up @@ -59,11 +58,10 @@ end

class type install_type = object
method install : source_dir:string ->
build_cmd:string ->
install_cmd:string ->
flags:string list ->
targets:string list ->
patches:string list ->
buildcmd:string ->
installcmd:string -> (unit, exn) res
patches:string list -> (unit, exn) res
(** Installs packages, located in [source_dir]. *)
end

Expand Down

0 comments on commit 9330505

Please sign in to comment.