Jelajahi Sumber

Revert "[cli] add --jvm"

This reverts commit 0abd794725663d1697bddfc38e1061fa69165b2b.
Aleksandr Kuzmenko 5 tahun lalu
induk
melakukan
09003faccc
5 mengubah file dengan 32 tambahan dan 53 penghapusan
  1. 0 4
      extra/CHANGES.txt
  2. 4 12
      src/compiler/haxe.ml
  3. 6 11
      src/core/path.ml
  4. 20 25
      src/generators/genjvm.ml
  5. 2 1
      tests/unit/compile-jvm.hxml

+ 0 - 4
extra/CHANGES.txt

@@ -1,9 +1,5 @@
 2020-XX-XX: 4.1.1
 
-	New features:
-
-	jvm : added `--jvm path/to.jar` CLI argument instead of `-D jvm --java path`
-
 	Bugfixes:
 
 	all : fixed arguments ordering for @:structInit constructors (#9418)

+ 4 - 12
src/compiler/haxe.ml

@@ -280,7 +280,7 @@ module Initialize = struct
 				"eval"
 end
 
-let generate tctx ext interp jvm_flag swf_header =
+let generate tctx ext interp swf_header =
 	let com = tctx.Typecore.com in
 	(* check file extension. In case of wrong commandline, we don't want
 		to accidentaly delete a source file. *)
@@ -299,8 +299,7 @@ let generate tctx ext interp jvm_flag swf_header =
 	begin match com.platform with
 		| Neko | Hl | Eval when interp -> ()
 		| Cpp when Common.defined com Define.Cppia -> ()
-		| Cpp | Cs | Php -> Path.mkdir_from_path (com.file ^ "/.")
-		| Java when not jvm_flag -> Path.mkdir_from_path (com.file ^ "/.")
+		| Cpp | Cs | Java | Php -> Path.mkdir_from_path (com.file ^ "/.")
 		| _ -> Path.mkdir_from_path com.file
 	end;
 	if interp then
@@ -325,7 +324,7 @@ let generate tctx ext interp jvm_flag swf_header =
 			Gencs.generate,"cs"
 		| Java ->
 			if Common.defined com Jvm then
-				Genjvm.generate jvm_flag,"java"
+				Genjvm.generate,"java"
 			else
 				Genjava.generate,"java"
 		| Python ->
@@ -697,7 +696,6 @@ try
 	let force_typing = ref false in
 	let pre_compilation = ref [] in
 	let interp = ref false in
-	let jvm_flag = ref false in
 	let swf_version = ref false in
 	let native_libs = ref [] in
 	let add_native_lib file extern = native_libs := (file,extern) :: !native_libs in
@@ -738,12 +736,6 @@ try
 			cp_libs := "hxjava" :: !cp_libs;
 			Initialize.set_platform com Java dir;
 		),"<directory>","generate Java code into target directory");
-		("Target",["--jvm"],["-jvm"],Arg.String (fun dir ->
-			cp_libs := "hxjava" :: !cp_libs;
-			Common.define com Define.Jvm;
-			jvm_flag := true;
-			Initialize.set_platform com Java dir;
-		),"<directory>","generate JVM bytecode into target file");
 		("Target",["--python"],["-python"],Arg.String (fun dir ->
 			Initialize.set_platform com Python dir;
 		),"<file>","generate Python code as target file");
@@ -1065,7 +1057,7 @@ try
 		if ctx.has_error then raise Abort;
 		check_auxiliary_output com !xml_out !json_out;
 		com.stage <- CGenerationStart;
-		if not !no_output then generate tctx ext !interp !jvm_flag !swf_header;
+		if not !no_output then generate tctx ext !interp !swf_header;
 		com.stage <- CGenerationDone;
 	end;
 	Sys.catch_break false;

+ 6 - 11
src/core/path.ml

@@ -272,18 +272,13 @@ module FilePath = struct
 			in
 			let file,ext = if String.length path = 0 then
 				None,None
-			else begin try
+			else begin
 				let cp = String.rindex path '.' in
-				let file,ext = split path cp in
-				Some file,Some ext
-			with Not_found ->
-				Some path,None
+				if cp <> -1 then begin
+					let file,ext = split path cp in
+					Some file,Some ext
+				end else
+					Some path,None
 			end in
 			create dir file ext backslash
-
-	let name_and_extension path = match path.file_name with
-		| None -> failwith "File path has no name"
-		| Some name -> match path.extension with
-			| None -> name
-			| Some ext -> name ^ "." ^ ext
 end

+ 20 - 25
src/generators/genjvm.ml

@@ -2789,30 +2789,25 @@ module Preprocessor = struct
 		) gctx.com.types
 end
 
-let generate jvm_flag com =
-	let path = FilePath.parse com.file in
-	let jar_name,entry_point = match get_entry_point com with
-		| Some (jarname,cl,expr) -> jarname, Some (cl,expr)
-		| None -> "jar",None
+let file_name_and_extension file =
+	match List.rev (ExtString.String.nsplit file "/") with
+	| e1 :: _ -> e1
+	| _ -> die "" __LOC__
+
+let generate com =
+	mkdir_from_path com.file;
+	let jar_name,manifest_suffix,entry_point = match get_entry_point com with
+		| Some (jarname,cl,expr) ->
+			let pack = match fst cl.cl_path with
+				| [] -> ["haxe";"root"]
+				| pack -> pack
+			in
+			jarname,"\nMain-Class: " ^ (s_type_path (pack,snd cl.cl_path)), Some (cl,expr)
+		| None -> "jar","",None
 	in
-	let jar_dir,jar_path = if jvm_flag then begin
-		match path.file_name with
-		| Some _ ->
-			begin match path.directory with
-				| None ->
-					"./","./" ^ com.file
-				| Some dir ->
-					mkdir_from_path dir;
-					add_trailing_slash dir,com.file
-			end
-		| None ->
-			failwith "Please specify an output file name"
-	end else begin
-		let jar_name = if com.debug then jar_name ^ "-Debug" else jar_name in
-		let jar_dir = add_trailing_slash com.file in
-		let jar_path = Printf.sprintf "%s%s.jar" jar_dir jar_name in
-		jar_dir,jar_path
-	end in
+	let jar_name = if com.debug then jar_name ^ "-Debug" else jar_name in
+	let jar_dir = add_trailing_slash com.file in
+	let jar_path = Printf.sprintf "%s%s.jar" jar_dir jar_name in
 	let anon_identification = new tanon_identification haxe_dynamic_object_path in
 	let gctx = {
 		com = com;
@@ -2840,7 +2835,7 @@ let generate jvm_flag com =
 		else begin
 			let dir = Printf.sprintf "%slib/" jar_dir in
 			Path.mkdir_from_path dir;
-			let name = FilePath.name_and_extension (FilePath.parse java_lib#get_file_path) in
+			let name = file_name_and_extension java_lib#get_file_path in
 			let ch_in = open_in_bin java_lib#get_file_path in
 			let ch_out = open_out_bin (Printf.sprintf "%s%s" dir name) in
 			let b = IO.read_all (IO.input_channel ch_in) in
@@ -2854,7 +2849,7 @@ let generate jvm_flag com =
 		"Manifest-Version: 1.0\n" ^
 		(match class_paths with [] -> "" | _ -> "Class-Path: " ^ (String.concat " " class_paths ^ "\n")) ^
 		"Created-By: Haxe (Haxe Foundation)" ^
-		(Option.map_default (fun (cl,_) -> "\nMain-Class: " ^ (s_type_path cl.cl_path)) "" entry_point) ^
+		manifest_suffix ^
 		"\n\n"
 	in
 	Zip.add_entry manifest_content gctx.jar "META-INF/MANIFEST.MF";

+ 2 - 1
tests/unit/compile-jvm.hxml

@@ -6,4 +6,5 @@
 compile-each.hxml
 --main unit.TestMain
 --java-lib native_java/native.jar
--jvm bin/jvm/TestMain-debug.jar
+-java bin/jvm
+-D jvm