Skip to content

Commit

Permalink
#17: Added specifing Build command and Install command
Browse files Browse the repository at this point in the history
  • Loading branch information
Kakadu committed Feb 21, 2012
1 parent ba63813 commit ff5adad
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 23 deletions.
5 changes: 5 additions & 0 deletions brb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ Dep ocamlgraph recipe "local"
Dep oasis remote "http://forge.ocamlcore.org/frs/download.php/501/oasis-0.2.0.tar.gz"
Requires extlib, fileutils, ocamlgraph, ocamlify, odn, pcre, ounit, expect
Patch "_patches/oasis-ounit-1.1.1.patch"

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

21 changes: 11 additions & 10 deletions src/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type meta = [ `Make 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 @@ -67,20 +68,20 @@ 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 (targets, flags, patches, installcmd, requires) = List.fold_left metas
~init:([], [], [], "make install", [])
~f:(fun (ts, fs, ps, ins, rs) meta -> match meta with
| `Make t -> (t :: ts, fs, ps, ins, rs)
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 ->
(ts, (String.nsplit f " ") @ fs, ps, ins, rs)
| `Patch p -> (ts, fs, p :: ps, ins, rs)
| `Requires r -> (ts, fs, ps, ins, rs @ r)
| `Install i -> (ts, fs, ps, i, rs)
(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)
)
in

{
name;
package = to_package ast;
requires; targets; flags; patches; installcmd
targets; requires; flags; patches; installcmd; buildcmd
}
2 changes: 2 additions & 0 deletions src/barbra.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ let build_deps () =
~flags
~targets
~patches
~buildcmd: dep.buildcmd
~installcmd: dep.installcmd
in

Expand All @@ -95,6 +96,7 @@ let build_project () = begin
~flags:[]
~targets:[]
~installcmd:"make install"
~buildcmd:"make"
~patches:[];
Log.info "Project built succesfully!"
end
Expand Down
26 changes: 16 additions & 10 deletions src/install.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ 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 ~installcmd = begin
method install ~source_dir ~flags ~targets ~patches ~buildcmd ~installcmd = begin
G.create_dirs ();
Env.write_env ();

Expand All @@ -22,9 +28,9 @@ let makefile : install_type = object
Log.debug "Applied patch %S" p;
);

Log.info "Starting Makefile build";
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 @@ -41,15 +47,15 @@ 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 make = getenv ~default:"make" "MAKE" in
exec (make :: targets) >>= fun () ->
let (cmd,args) =
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,"") in
let (cmd,args) = guess_command installcmd in
let cmd = if cmd = "make" then make else cmd in
exec [cmd; args]
end
Expand Down
3 changes: 2 additions & 1 deletion src/lexer.mll
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
open Parser

let keywords = Hashtbl.create 8
let keywords = Hashtbl.create 9
let () = List.iter (fun (kwd, token) -> Hashtbl.add keywords kwd token) [
("dep", DEP);
("make", MAKE);
("buildcmd", BUILDCMD);
("flag", FLAG);
("patch", PATCH);
("install", INSTALL);
Expand Down
3 changes: 2 additions & 1 deletion 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
%token MAKE FLAG PATCH REQUIRES INSTALL BUILDCMD
%token COMMA
%token EOF
%token <string> IDENT
Expand Down Expand Up @@ -41,6 +41,7 @@ meta_list:

meta:
| MAKE VALUE {`Make $2}
| BUILDCMD VALUE {`BuildCmd $2}
| FLAG VALUE {`Flag $2}
| PATCH VALUE {`Patch $2}
| INSTALL VALUE {`Install $2}
Expand Down
4 changes: 3 additions & 1 deletion src/types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ type dep =
name : string;
package : package;
requires : string list;
targets : string list;
targets : string list; (* targets for buildcmd *)
flags : string list;
patches : string list;
buildcmd : string;
installcmd : string
}

Expand Down Expand Up @@ -61,6 +62,7 @@ class type install_type = object
flags:string list ->
targets:string list ->
patches:string list ->
buildcmd:string ->
installcmd:string -> (unit, exn) res
(** Installs packages, located in [source_dir]. *)
end
Expand Down

0 comments on commit ff5adad

Please sign in to comment.