From ff5adad2cf087fdaadf0819eeff2946ea86f473d Mon Sep 17 00:00:00 2001 From: kakadu Date: Tue, 21 Feb 2012 23:17:44 +0400 Subject: [PATCH] #17: Added specifing Build command and Install command --- brb.conf | 5 +++++ src/ast.ml | 21 +++++++++++---------- src/barbra.ml | 2 ++ src/install.ml | 26 ++++++++++++++++---------- src/lexer.mll | 3 ++- src/parser.mly | 3 ++- src/types.ml | 4 +++- 7 files changed, 41 insertions(+), 23 deletions(-) diff --git a/brb.conf b/brb.conf index 4365753..b49f745 100644 --- a/brb.conf +++ b/brb.conf @@ -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" + diff --git a/src/ast.ml b/src/ast.ml index 700c2f8..b4639e0 100644 --- a/src/ast.ml +++ b/src/ast.ml @@ -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) @@ -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 } diff --git a/src/barbra.ml b/src/barbra.ml index eac55ca..e791556 100644 --- a/src/barbra.ml +++ b/src/barbra.ml @@ -74,6 +74,7 @@ let build_deps () = ~flags ~targets ~patches + ~buildcmd: dep.buildcmd ~installcmd: dep.installcmd in @@ -95,6 +96,7 @@ let build_project () = begin ~flags:[] ~targets:[] ~installcmd:"make install" + ~buildcmd:"make" ~patches:[]; Log.info "Project built succesfully!" end diff --git a/src/install.ml b/src/install.ml index c687743..4b33cd3 100644 --- a/src/install.ml +++ b/src/install.ml @@ -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 (); @@ -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" @@ -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 diff --git a/src/lexer.mll b/src/lexer.mll index c0158a0..2dbc5f0 100644 --- a/src/lexer.mll +++ b/src/lexer.mll @@ -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); diff --git a/src/parser.mly b/src/parser.mly index cf25d88..d6b2223 100644 --- a/src/parser.mly +++ b/src/parser.mly @@ -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 IDENT @@ -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} diff --git a/src/types.ml b/src/types.ml index 045b542..dbe9a03 100644 --- a/src/types.ml +++ b/src/types.ml @@ -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 } @@ -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