-
-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
217 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
open Globals | ||
open Json | ||
open Json.Reader | ||
|
||
type writer_target_config = { | ||
mutable generate : bool; | ||
mutable exclude : string list list; | ||
mutable include' : string list list; | ||
mutable hxb_version : int; | ||
} | ||
|
||
type t = { | ||
mutable archive_path : string; | ||
target_config : writer_target_config; | ||
macro_config : writer_target_config; | ||
} | ||
|
||
let create_target_config () = { | ||
generate = true; | ||
exclude = []; | ||
include'= []; | ||
hxb_version = HxbData.hxb_version; | ||
} | ||
|
||
let create () = { | ||
archive_path = ""; | ||
target_config = create_target_config (); | ||
macro_config = create_target_config () | ||
} | ||
|
||
let error s = | ||
Error.raise_typing_error s null_pos | ||
|
||
let process_json config target_name json = | ||
let read_string = function | ||
| JString s -> s | ||
| json -> error (Printf.sprintf "Invalid JSON where string was expected: %s" (string_of_json json)) | ||
in | ||
let read_int = function | ||
| JInt i -> i | ||
| json -> error (Printf.sprintf "Invalid JSON where integer was expected: %s" (string_of_json json)) | ||
in | ||
let read_bool = function | ||
| JBool b -> b | ||
| json -> error (Printf.sprintf "Invalid JSON where bool was expected: %s" (string_of_json json)) | ||
in | ||
let read_array_or_null f json = match json with | ||
| JNull -> | ||
[] | ||
| JArray jl -> | ||
List.map f jl | ||
| _ -> | ||
error (Printf.sprintf "Invalid JSON where array was expected: %s" (string_of_json json)) | ||
in | ||
let read_object_or_null f json = match json with | ||
| JNull -> | ||
() | ||
| JObject fl -> | ||
f fl | ||
| _ -> | ||
error (Printf.sprintf "Invalid JSON where object was expected: %s" (string_of_json json)) | ||
in | ||
let read_target_config config fl = | ||
List.iter (fun (s,json) -> match s with | ||
| "generate" -> | ||
config.generate <- read_bool json; | ||
| "exclude" -> | ||
config.exclude <- read_array_or_null (fun json -> ExtString.String.nsplit (read_string json) ".") json | ||
| "include" -> | ||
config.include' <- read_array_or_null (fun json -> ExtString.String.nsplit (read_string json) ".") json | ||
| "hxbVersion" -> | ||
config.hxb_version <- read_int json | ||
| s -> | ||
error (Printf.sprintf "Unknown key for target config: %s" s) | ||
) fl; | ||
in | ||
let read_writer_config fl = | ||
List.iter (fun (s,json) -> | ||
match s with | ||
| "archivePath" -> | ||
let path = read_string json in | ||
let path = Str.global_replace (Str.regexp "\\$target") target_name path in | ||
config.archive_path <- path; | ||
| "targetConfig" -> | ||
read_object_or_null (read_target_config config.target_config) json | ||
| "macroConfig" -> | ||
read_object_or_null (read_target_config config.macro_config) json | ||
| s -> | ||
error (Printf.sprintf "Unknown key for writer config: %s" s) | ||
) fl; | ||
in | ||
read_object_or_null read_writer_config json | ||
|
||
let parse config target_name input = | ||
let lexbuf = Sedlexing.Utf8.from_string input in | ||
let json = read_json lexbuf in | ||
process_json config target_name json | ||
|
||
let process_argument target_name file = | ||
let config = create () in | ||
begin match Path.file_extension file with | ||
| "json" -> | ||
let file = try | ||
open_in file | ||
with exc -> | ||
error (Printf.sprintf "Could not open file %s: %s" file (Printexc.to_string exc)) | ||
in | ||
let data = Std.input_all file in | ||
close_in file; | ||
parse config target_name data; | ||
| _ -> | ||
config.archive_path <- file; | ||
end; | ||
Some config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package haxe.hxb; | ||
|
||
typedef WriterTargetConfig = { | ||
/** | ||
If `false`, this target is ignored by the writer. | ||
**/ | ||
var generate:Null<Bool>; | ||
|
||
/** | ||
Dot paths of modules or packages to be exluded from the archive. | ||
**/ | ||
var exclude:Null<Array<String>>; | ||
|
||
/** | ||
Dot paths of modules or packages to be included in the archive. This takes priority | ||
over exclude. By default, all modules that aren't explicitly excluded are | ||
included. | ||
**/ | ||
var include:Null<Array<String>>; | ||
|
||
/** | ||
The hxb version to target. By default, the version of the Haxe compiler itself | ||
is targeted. See https://github.com/HaxeFoundation/haxe/issues/11505 | ||
**/ | ||
var hxbVersion:Null<Int>; | ||
} | ||
|
||
typedef WriterConfig = { | ||
/** | ||
The file path for the archive. Occurrences of `$target` are replaced | ||
by the name of the current target (js, hl, etc.). | ||
**/ | ||
var archivePath:String; | ||
|
||
/** | ||
The configuration for the current target context. If it is `null`, all data | ||
for the target context is generated. | ||
**/ | ||
var targetConfig:Null<WriterTargetConfig>; | ||
|
||
/** | ||
The configuration for the macro context. If it is `null`, all data for the | ||
macro context is generated. | ||
**/ | ||
var macroConfig:Null<WriterTargetConfig>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
compile-jvm-only.hxml | ||
--hxb bin/hxb/jvm.zip | ||
--hxb hxb-config/jvm.json | ||
|
||
--next | ||
|
||
compile-jvm-only.hxml | ||
--hxb-lib bin/hxb/jvm.zip | ||
--hxb-lib bin/hxb/unit.java.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"archivePath": "bin/hxb/unit.$target.zip", | ||
"targetConfig": { | ||
"exclude": ["unit.TestMainNow"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package unit; | ||
|
||
class TestMainNow { | ||
static public function printNow() { | ||
#if !macro | ||
trace("Generated at: " + HelperMacros.getCompilationDate()); | ||
#end | ||
} | ||
} |