Skip to content

Commit 3647256

Browse files
authored
Merge pull request #4831 from rescript-lang/mark_rescript
relative paths reloaded
2 parents 7a4507e + 76946df commit 3647256

27 files changed

+1484
-1292
lines changed

jscomp/bsb/bsb_config.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ let rev_lib_bs_prefix p = rev_lib_bs // p
6262

6363
let ocaml_bin_install_prefix p = lib_ocaml // p
6464

65-
let proj_rel path = Bsb_ninja_global_vars.lazy_src_root_dir // path
65+
let proj_rel path = rev_lib_bs // path
6666

6767
(** it may not be a bad idea to hard code the binary path
6868
of bsb in configuration time

jscomp/bsb/bsb_ninja_gen.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ let output_ninja_and_namespace_map
236236

237237
let oc = open_out_bin (cwd_lib_bs // Literals.build_ninja) in
238238
mark_rescript oc;
239-
Bsb_ninja_targets.output_kv
239+
(* Bsb_ninja_targets.output_kv
240240
Bsb_ninja_global_vars.src_root_dir per_proj_dir
241-
oc ;
241+
oc ; *)
242242
output_static_resources static_resources rules.copy_resources oc ;
243243
(** Generate build statement for each file *)
244244
Ext_list.iter bs_file_groups

jscomp/bsb/bsb_ninja_global_vars.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
to be "a" and "$a"
3131
*)
3232

33-
let src_root_dir = "g_root"
33+
(* let src_root_dir = "g_root"
3434
35-
let lazy_src_root_dir = "$g_root"
35+
let lazy_src_root_dir = "$g_root" *)
3636

3737

3838

jscomp/bsb/bsb_ninja_rule.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ let make_custom_rules
218218
);
219219

220220
Ext_buffer.add_char_string buf ' ' bsc_flags;
221-
Ext_buffer.add_string buf " -bs-ast -o $out $i";
221+
Ext_buffer.add_string buf " -absname -bs-ast -o $out $i";
222222
Ext_buffer.contents buf
223223
in
224224
let build_ast =

jscomp/core/config_util.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@ let find_opt file = find_in_path_uncap !Config.load_path file
4747

4848

4949

50+
let output_prefix name =
51+
match !Clflags.output_name with
52+
| None ->
53+
Ext_namespace_encode.make
54+
(Filename.remove_extension name)
55+
?ns:!Clflags.dont_record_crc_unit
56+
| Some oname ->
57+
Filename.remove_extension oname
5058

jscomp/core/config_util.mli

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,16 @@
3737
val find_opt : string -> string option
3838
(** [find filename] Input is a file name, output is absolute path *)
3939

40+
41+
(** given the input, calculate the output prefix
42+
43+
in: src/hello.ast
44+
out: src/hello
45+
46+
with namespace:
47+
in: src/hello.ast
48+
out: src/hello-Ns
49+
*)
50+
val output_prefix :
51+
string ->
52+
string

jscomp/core/js_implementation.ml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ let after_parsing_sig ppf outputprefix ast =
102102

103103

104104

105-
let interface ~parser ppf fname outputprefix =
105+
let interface ~parser ppf ?outputprefix fname =
106+
let outputprefix =
107+
match outputprefix with
108+
| None -> Config_util.output_prefix fname
109+
| Some x -> x in
106110
Res_compmisc.init_path ();
107111
parser fname
108112
|> Cmd_ppx_apply.apply_rewriters ~restore:false ~tool_name:Js_config.tool_name Mli
@@ -111,12 +115,12 @@ let interface ~parser ppf fname outputprefix =
111115
|> print_if_pipe ppf Clflags.dump_source Pprintast.signature
112116
|> after_parsing_sig ppf outputprefix
113117

114-
let interface_mliast ppf fname outputprefix setup =
118+
let interface_mliast ppf fname setup =
115119
Res_compmisc.init_path ();
116120
Binary_ast.read_ast_exn ~fname Mli setup
117121
|> print_if_pipe ppf Clflags.dump_parsetree Printast.interface
118122
|> print_if_pipe ppf Clflags.dump_source Pprintast.signature
119-
|> after_parsing_sig ppf outputprefix
123+
|> after_parsing_sig ppf (Config_util.output_prefix fname)
120124

121125
let all_module_alias (ast : Parsetree.structure)=
122126
Ext_list.for_all ast (fun {pstr_desc} ->
@@ -196,7 +200,11 @@ let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) =
196200
end;
197201
process_with_gentype (outputprefix ^ ".cmt")
198202
end
199-
let implementation ~parser ppf fname outputprefix =
203+
let implementation ~parser ppf ?outputprefix fname =
204+
let outputprefix =
205+
match outputprefix with
206+
| None -> Config_util.output_prefix fname
207+
| Some x -> x in
200208
Res_compmisc.init_path ();
201209
parser fname
202210
|> Cmd_ppx_apply.apply_rewriters ~restore:false ~tool_name:Js_config.tool_name Ml
@@ -205,12 +213,13 @@ let implementation ~parser ppf fname outputprefix =
205213
|> print_if_pipe ppf Clflags.dump_source Pprintast.structure
206214
|> after_parsing_impl ppf outputprefix
207215

208-
let implementation_mlast ppf fname outputprefix setup =
216+
let implementation_mlast ppf fname setup =
217+
209218
Res_compmisc.init_path ();
210219
Binary_ast.read_ast_exn ~fname Ml setup
211220
|> print_if_pipe ppf Clflags.dump_parsetree Printast.implementation
212221
|> print_if_pipe ppf Clflags.dump_source Pprintast.structure
213-
|> after_parsing_impl ppf outputprefix
222+
|> after_parsing_impl ppf (Config_util.output_prefix fname )
214223

215224

216225

@@ -232,7 +241,7 @@ let make_structure_item ~ns cunit : Parsetree.structure_item =
232241
(** decoding [.mlmap]
233242
keep in sync {!Bsb_namespace_map_gen.output}
234243
*)
235-
let implementation_map ppf sourcefile outputprefix =
244+
let implementation_map ppf sourcefile =
236245
let () = Js_config.cmj_only := true in
237246
let ichan = open_in_bin sourcefile in
238247
seek_in ichan (Ext_digest.length +1);
@@ -247,5 +256,5 @@ let implementation_map ppf sourcefile outputprefix =
247256
ml_ast
248257
|> print_if_pipe ppf Clflags.dump_parsetree Printast.implementation
249258
|> print_if_pipe ppf Clflags.dump_source Pprintast.structure
250-
|> after_parsing_impl ppf outputprefix
259+
|> after_parsing_impl ppf (Config_util.output_prefix sourcefile)
251260

jscomp/core/js_implementation.mli

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@
3838
val interface :
3939
parser:(string -> Parsetree.signature) ->
4040
Format.formatter ->
41-
string ->
41+
?outputprefix:string ->
4242
string ->
4343
unit
4444

4545
val interface_mliast :
4646
Format.formatter ->
47-
string ->
4847
string ->
4948
([`ml | `rescript | `reason ] -> unit) ->
5049
unit
@@ -64,16 +63,16 @@ val interface_mliast :
6463
val implementation :
6564
parser:(string -> Parsetree.structure) ->
6665
Format.formatter ->
67-
string ->
66+
?outputprefix:string ->
6867
string ->
6968
unit
7069
(** [implementation ppf sourcefile outprefix] compiles to JS directly *)
7170

7271
val implementation_mlast :
7372
Format.formatter ->
7473
string ->
75-
string ->
7674
([`ml | `rescript | `reason ] -> unit) ->
7775
unit
7876

79-
val implementation_map : Format.formatter -> string -> string -> unit
77+
val implementation_map :
78+
Format.formatter -> string -> unit

jscomp/main/js_main.ml

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@
1010
(* *)
1111
(***********************************************************************)
1212

13-
let output_prefix name =
14-
match !Clflags.output_name with
15-
| None ->
16-
Ext_namespace_encode.make
17-
(Filename.remove_extension name)
18-
?ns:!Clflags.dont_record_crc_unit
19-
| Some oname ->
20-
Filename.remove_extension oname
21-
2213

14+
let set_abs_input_name sourcefile =
15+
let sourcefile =
16+
if !Location.absname && Filename.is_relative sourcefile then
17+
Ext_path.absolute_cwd_path sourcefile
18+
else sourcefile in
19+
Location.set_input_name sourcefile;
20+
sourcefile
2321

2422

2523
let setup_error_printer (syntax_kind : [ `ml | `reason | `rescript ])=
@@ -36,9 +34,10 @@ let setup_error_printer (syntax_kind : [ `ml | `reason | `rescript ])=
3634

3735

3836

39-
let handle_reason (type a) (kind : a Ml_binary.kind) sourcefile ppf opref =
37+
let handle_reason (type a) (kind : a Ml_binary.kind) sourcefile ppf =
4038
setup_error_printer `reason;
4139
let tmpfile = Ast_reason_pp.pp sourcefile in
40+
let outputprefix = Config_util.output_prefix sourcefile in
4241
(match kind with
4342
| Ml_binary.Ml ->
4443
Js_implementation.implementation
@@ -47,7 +46,7 @@ let handle_reason (type a) (kind : a Ml_binary.kind) sourcefile ppf opref =
4746
let ast = Ml_binary.read_ast Ml in_chan in
4847
close_in in_chan; ast
4948
)
50-
ppf tmpfile opref
49+
ppf tmpfile ~outputprefix
5150

5251
| Ml_binary.Mli ->
5352
Js_implementation.interface
@@ -56,55 +55,61 @@ let handle_reason (type a) (kind : a Ml_binary.kind) sourcefile ppf opref =
5655
let ast = Ml_binary.read_ast Mli in_chan in
5756
close_in in_chan; ast
5857
)
59-
ppf tmpfile opref ; );
58+
ppf tmpfile ~outputprefix );
6059
Ast_reason_pp.clean tmpfile
6160

62-
6361

6462
let process_file sourcefile
6563
?(kind ) ppf =
6664
(* This is a better default then "", it will be changed later
6765
The {!Location.input_name} relies on that we write the binary ast
6866
properly
6967
*)
70-
Location.set_input_name sourcefile;
71-
let opref = output_prefix sourcefile in
7268
let kind =
7369
match kind with
7470
| None -> Ext_file_extensions.classify_input (Ext_filename.get_extension_maybe sourcefile)
7571
| Some kind -> kind in
7672
match kind with
77-
| Re -> handle_reason Ml sourcefile ppf opref
73+
| Re ->
74+
let sourcefile = set_abs_input_name sourcefile in
75+
handle_reason Ml sourcefile ppf
7876
| Rei ->
79-
handle_reason Mli sourcefile ppf opref
77+
let sourcefile = set_abs_input_name sourcefile in
78+
handle_reason Mli sourcefile ppf
8079
| Ml ->
80+
let sourcefile = set_abs_input_name sourcefile in
8181
Js_implementation.implementation
8282
~parser:Pparse_driver.parse_implementation
83-
ppf sourcefile opref
83+
ppf sourcefile
8484
| Mli ->
85+
let sourcefile = set_abs_input_name sourcefile in
8586
Js_implementation.interface
8687
~parser:Pparse_driver.parse_interface
87-
ppf sourcefile opref
88+
ppf sourcefile
8889
| Res ->
90+
let sourcefile = set_abs_input_name sourcefile in
8991
setup_error_printer `rescript;
9092
Js_implementation.implementation
9193
~parser:Res_driver.parse_implementation
92-
ppf sourcefile opref
94+
ppf sourcefile
9395
| Resi ->
96+
let sourcefile = set_abs_input_name sourcefile in
9497
setup_error_printer `rescript;
9598
Js_implementation.interface
9699
~parser:Res_driver.parse_interface
97-
ppf sourcefile opref
100+
ppf sourcefile
98101
| Intf_ast
99102
->
100-
Js_implementation.interface_mliast ppf sourcefile opref
103+
Js_implementation.interface_mliast ppf sourcefile
101104
setup_error_printer ;
102105
| Impl_ast
103106
->
104-
Js_implementation.implementation_mlast ppf sourcefile opref
107+
Js_implementation.implementation_mlast ppf sourcefile
105108
setup_error_printer;
106109
| Mlmap
107-
-> Js_implementation.implementation_map ppf sourcefile opref
110+
->
111+
Location.set_input_name sourcefile;
112+
Js_implementation.implementation_map ppf sourcefile
108113
| Cmi
109114
->
110115
let cmi_sign = (Cmi_format.read_cmi sourcefile).cmi_sign in

jscomp/others/release.ninja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
bsc_flags = -no-keep-locs -absname -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -nopervasives -unsafe -w +50 -warn-error A -open Bs_stdlib_mini -I ./runtime
2+
bsc_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -nopervasives -unsafe -w +50 -warn-error A -open Bs_stdlib_mini -I ./runtime
33

44
rule cc
55
command = $bsc -bs-cmi -bs-cmj $bsc_flags -I others $in

0 commit comments

Comments
 (0)