Browse Source

Merge pull request #2384 from nadako/cs_subdir_resource_fix

[cs,java] fix embedding resources in subdirectories
Cauê Waneck 11 years ago
parent
commit
aff272b555
4 changed files with 30 additions and 16 deletions
  1. 14 0
      common.ml
  2. 1 14
      gencpp.ml
  3. 7 1
      gencs.ml
  4. 8 1
      genjava.ml

+ 14 - 0
common.ml

@@ -844,6 +844,20 @@ let normalize_path p =
 		| '\\' | '/' -> p
 		| _ -> p ^ "/"
 
+let rec mkdir_recursive base dir_list =
+	match dir_list with
+	| [] -> ()
+	| dir :: remaining ->
+		let path = match base with
+		           | "" ->  dir
+		           | "/" -> "/" ^ dir
+		           | _ -> base ^ "/" ^ dir
+		in
+		if not ( (path = "") || ( ((String.length path) = 2) && ((String.sub path 1 1) = ":") ) ) then
+			if not (Sys.file_exists path) then
+				Unix.mkdir path 0o755;
+		mkdir_recursive (if (path = "") then "/" else path) remaining
+
 let mem_size v =
 	Objsize.size_with_headers (Objsize.objsize v [] [])
 

+ 1 - 14
gencpp.ml

@@ -124,20 +124,7 @@ let cached_source_writer common_ctx filename =
 	with _ ->
 		file_source_writer common_ctx filename;;
 
-let rec make_class_directories base dir_list =
-	( match dir_list with
-	| [] -> ()
-	| dir :: remaining ->
-		let path = match base with
-                   | "" ->  dir
-                   | "/" -> "/" ^ dir
-                   | _ -> base ^ "/" ^ dir  in
-         if ( not ( (path="") ||
-           ( ((String.length path)=2) && ((String.sub path 1 1)=":") ) ) ) then
-		         if not (Sys.file_exists path) then
-			          Unix.mkdir path 0o755;
-		make_class_directories (if (path="") then "/" else path) remaining
-	);;
+let make_class_directories = Common.mkdir_recursive;;
 
 let make_base_directory dir =
 	make_class_directories "" ( ( Str.split_delim (Str.regexp "[\\/]+") dir ) );;

+ 7 - 1
gencs.ml

@@ -2411,7 +2411,13 @@ let configure gen =
     Hashtbl.iter (fun name v ->
       res := { eexpr = TConst(TString name); etype = gen.gcon.basic.tstring; epos = Ast.null_pos } :: !res;
 
-      let f = open_out (gen.gcon.file ^ "/src/Resources/" ^ name) in
+      let full_path = gen.gcon.file ^ "/src/Resources/" ^ name in
+      let parts = Str.split_delim (Str.regexp "[\\/]+") full_path in
+      let dir_list = List.rev (List.tl (List.rev parts)) in
+
+      Common.mkdir_recursive "" dir_list;
+
+      let f = open_out full_path in
       output_string f v;
       close_out f
     ) gen.gcon.resources;

+ 8 - 1
genjava.ml

@@ -2128,7 +2128,14 @@ let configure gen =
     let res = ref [] in
     Hashtbl.iter (fun name v ->
       res := { eexpr = TConst(TString name); etype = gen.gcon.basic.tstring; epos = Ast.null_pos } :: !res;
-      let f = open_out (gen.gcon.file ^ "/src/" ^ name) in
+
+      let full_path = gen.gcon.file ^ "/src/" ^ name in
+      let parts = Str.split_delim (Str.regexp "[\\/]+") full_path in
+      let dir_list = List.rev (List.tl (List.rev parts)) in
+
+      Common.mkdir_recursive "" dir_list;
+
+      let f = open_out full_path in
       output_string f v;
       close_out f
     ) gen.gcon.resources;