Browse Source

expand env vars in commands

Nicolas Cannasse 16 years ago
parent
commit
1069711cc2
5 changed files with 16 additions and 7 deletions
  1. 2 2
      Makefile
  2. 1 1
      Makefile.win
  3. 1 0
      doc/CHANGES.txt
  4. 2 1
      doc/install.ml
  5. 10 3
      main.ml

+ 2 - 2
Makefile

@@ -5,7 +5,7 @@ NEKO=../neko
 XML=../../mtcvs/xml-light
 LIBS_SRC=$(EXTLIB)/*.ml* -n $(EXTLIB)/install.ml $(SWFLIB)/*.ml* $(EXTC)/extc.ml*
 SRC=$(NEKO)/libs/include/ocaml/*.ml* *.ml*
-LIBS=unix.cmxa $(XML)/xml-light.cmxa
+LIBS=unix.cmxa str.cmxa $(XML)/xml-light.cmxa
 FLAGS=-o haxe -pp camlp4o -P $(XML)/dtd.mli -lp "-cclib extc_stubs.o -cclib -lz"
 LFLAGS=
 
@@ -20,7 +20,7 @@ all: xml
 xml:
 	(cd ${XML} && make clean xml-light.cmxa)
 
-mode_ppc:	
+mode_ppc:
 	sudo ln -sfh /usr/local/bin/ocamlopt.ppc /usr/local/bin/ocamlopt
 	sudo ln -sfh /usr/local/lib/ocaml_ppc /usr/local/lib/ocaml
 

+ 1 - 1
Makefile.win

@@ -3,7 +3,7 @@
 .SUFFIXES : .ml .mli .cmo .cmi .cmx .mll .mly
 
 CFLAGS=-g -I ../neko/libs/include/ocaml
-LIBS=extLib.cmxa extc.cmxa swfLib.cmxa unix.cmxa xml-light.cmxa
+LIBS=extLib.cmxa extc.cmxa swfLib.cmxa unix.cmxa xml-light.cmxa str.cmxa
 LFLAGS=-g -o haxe.exe -I ../neko/libs/include/ocaml
 OUTPUT=sed 's/File "\([^"]\+\)", line \([0-9]\+\), \(.*\)/\1(\2): \3/' tmp.cmi
 

+ 1 - 0
doc/CHANGES.txt

@@ -1,6 +1,7 @@
 2009-??-??: 2.03
 	optimized Type.enumEq : use index instead of tag comparison for neko/flash9/php
 	bugfix for flash.display.BitmapDataChannel and GraphicsPathCommand (allow inline static)
+	resolve environment variable in -cmd commands
 
 2008-11-23: 2.02
 	Std.is(MyInterface, Class) now returns true (haXe/PHP)

+ 2 - 1
doc/install.ml

@@ -135,7 +135,8 @@ let compile() =
 		"../ocaml/extc/extc";
 		"../ocaml/swflib/swflib";
 		"../ocaml/xml-light/xml-light";
-		"unix"
+		"unix";
+		"str"
 	] in
 	let neko = "../neko/libs/include/ocaml" in
 	let paths = [

+ 10 - 3
main.ml

@@ -130,6 +130,10 @@ let read_type_path com p =
 
 let delete_file f = try Sys.remove f with _ -> ()
 
+let expand_env path =
+	let r = Str.regexp "%\\([^%]+\\)%" in
+	Str.global_substitute r (fun s -> try Sys.getenv (Str.matched_group 1 s) with Not_found -> "") path
+
 let parse_hxml file =
 	let ch = (try open_in file with _ -> failwith ("File not found " ^ file)) in
 	let lines = Std.input_list ch in
@@ -207,7 +211,8 @@ try
 			| l ->
 				l
 		in
-		com.class_path <- List.map normalize_path (loop (ExtString.String.nsplit p ":"))
+		let parts = "" :: Str.split_delim (Str.regexp "[;:]") p in
+		com.class_path <- List.map normalize_path (loop parts)
 	with
 		Not_found ->
 			if Sys.os_type = "Unix" then
@@ -222,6 +227,8 @@ try
 		let forbid acc p = if p = name || PMap.mem p acc then acc else PMap.add p Forbidden acc in
 		com.package_rules <- List.fold_left forbid com.package_rules root_packages;
 		Common.define com name; (* define platform name *)
+		Unix.putenv "__file__" file;
+		Unix.putenv "__platform__" file;
 	in
 	let define f = Arg.Unit (fun () -> Common.define com f) in
 	let args_spec = [
@@ -324,8 +331,8 @@ try
 		),": turn on verbose mode");
 		("-debug", Arg.Unit (fun() -> Common.define com "debug"; com.debug <- true), ": add debug informations to the compiled code");
 		("-prompt", Arg.Unit (fun() -> prompt := true),": prompt on error");
-		("-cmd", Arg.String (fun cmd ->
-			cmds := cmd :: !cmds
+		("-cmd", Arg.String (fun cmd ->			
+			cmds := expand_env cmd :: !cmds
 		),": run the specified command after successful compilation");
 		("--flash-strict", define "flash_strict", ": more type strict flash API");
 		("--no-traces", define "no_traces", ": don't compile trace calls in the program");