Skip to content

Commit e515442

Browse files
gretay-jsdra27ThomasRgl
authored
flambda-backend: Restructure LIBDIR: Move Dynlink, Str and Unix to sub-directories (port PR#11198) (#895)
* Install otherlibs to separate directories * Update dune install for otherlibs * Add Warnings.ghost_loc_in_file Factors out some common usage between Warnings and Location for zero-length ghost locations. * Add a hook for misses in Load_path Load_path.find{,_uncap} now invoke a hook before raising Not_found, which provides a mechanism for automatically adding directories to the Load_path if required. * Display an alert if -I +unix, etc is missing * flag -nocwd: do not implicitly add the current directory to the load path (port PR#11131) * native_toplevel auto_include path Co-authored-by: David Allsopp <[email protected]> Co-authored-by: thomasRgl <[email protected]>
1 parent 9307e7c commit e515442

29 files changed

+257
-104
lines changed

.depend

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6257,6 +6257,7 @@ driver/compmisc.cmx : \
62576257
utils/clflags.cmx \
62586258
driver/compmisc.cmi
62596259
driver/compmisc.cmi : \
6260+
utils/load_path.cmi \
62606261
typing/env.cmi \
62616262
utils/clflags.cmi
62626263
driver/errors.cmo : \

Makefile.common-jst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,12 @@ install_for_test: _install
202202
done; \
203203
ln -s . lex; ln -s . yacc; \
204204
ln -s _install/lib/ocaml/compiler-libs compilerlibs; \
205-
mkdir -p otherlibs/{unix,dynlink/native,str}; \
205+
mkdir -p otherlibs/{unix,dynlink/native,str,bigarray}; \
206206
ln -s ../stdlib/threads otherlibs/systhreads; \
207-
$(cpl) stdlib/{lib,}unix* otherlibs/unix; \
208-
$(cpl) stdlib/dynlink* otherlibs/dynlink; \
209-
$(cpl) stdlib/{lib,}str* otherlibs/str; \
207+
$(cpl) stdlib/unix/{lib,}unix* otherlibs/unix; \
208+
$(cpl) stdlib/dynlink/dynlink* otherlibs/dynlink; \
209+
$(cpl) stdlib/str/{lib,}str* otherlibs/str; \
210+
${cpl} stdlib/bigarray/bigarray* otherlibs/bigarray; \
210211
ln -s ../_build/main/$(ocamldir)/toplevel/byte/.ocamltoplevel.objs/byte toplevel; \
211212
)
212213

@@ -218,6 +219,7 @@ install_for_test: _install
218219
cp $(main_build)/$(ocamldir)/.ocamlcommon.objs/byte/*.cmo _runtest/utils
219220
rm -f _runtest/utils/{topdirs,opttopdirs}.cmi
220221
cp _install/lib/ocaml/*.{cmi,cma,a,cmxa} _runtest/utils
222+
cp _install/lib/ocaml/{unix,str,dynlink,bigarray}/*.{cmi,cma,a,cmxa} _runtest/utils
221223
cp $(main_build)/$(ocamldir)/.ocamlcommon.objs/native/config.o _runtest/utils
222224
# Needed for tests/warnings
223225
cp $(ocamldir)/utils/warnings.ml _runtest/utils

compilerlibs/Makefile.compilerlibs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ UTILS = \
3131
utils/identifiable.cmo \
3232
utils/numbers.cmo \
3333
utils/arg_helper.cmo \
34-
utils/clflags.cmo \
35-
utils/profile.cmo \
3634
utils/local_store.cmo \
3735
utils/load_path.cmo \
36+
utils/clflags.cmo \
37+
utils/profile.cmo \
3838
utils/terminfo.cmo \
3939
utils/ccomp.cmo \
4040
utils/warnings.cmo \

debugger/.depend

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ command_line.cmo : \
7272
debugger_lexer.cmi \
7373
debugger_config.cmi \
7474
debugcom.cmi \
75+
../driver/compmisc.cmi \
7576
checkpoints.cmi \
7677
breakpoints.cmi \
7778
command_line.cmi
@@ -109,6 +110,7 @@ command_line.cmx : \
109110
debugger_lexer.cmx \
110111
debugger_config.cmx \
111112
debugcom.cmx \
113+
../driver/compmisc.cmx \
112114
checkpoints.cmx \
113115
breakpoints.cmx \
114116
command_line.cmi
@@ -327,6 +329,7 @@ main.cmo : \
327329
exec.cmi \
328330
debugger_config.cmi \
329331
../utils/config.cmi \
332+
../driver/compmisc.cmi \
330333
command_line.cmi \
331334
../file_formats/cmi_format.cmi \
332335
../utils/clflags.cmi \
@@ -349,6 +352,7 @@ main.cmx : \
349352
exec.cmx \
350353
debugger_config.cmx \
351354
../utils/config.cmx \
355+
../driver/compmisc.cmx \
352356
command_line.cmx \
353357
../file_formats/cmi_format.cmx \
354358
../utils/clflags.cmx \
@@ -476,6 +480,7 @@ program_management.cmo : \
476480
history.cmi \
477481
../typing/envaux.cmi \
478482
debugger_config.cmi \
483+
../driver/compmisc.cmi \
479484
breakpoints.cmi \
480485
program_management.cmi
481486
program_management.cmx : \
@@ -493,6 +498,7 @@ program_management.cmx : \
493498
history.cmx \
494499
../typing/envaux.cmx \
495500
debugger_config.cmx \
501+
../driver/compmisc.cmx \
496502
breakpoints.cmx \
497503
program_management.cmi
498504
program_management.cmi :

debugger/command_line.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ let instr_dir ppf lexbuf =
262262
let new_directory = argument_list_eol argument lexbuf in
263263
if new_directory = [] then begin
264264
if yes_or_no "Reinitialize directory list" then begin
265-
Load_path.init !default_load_path;
265+
Load_path.init ~auto_include:Compmisc.auto_include !default_load_path;
266266
Envaux.reset_cache ~preserve_persistent_env:false;
267267
Hashtbl.clear Debugger_config.load_path_for;
268268
flush_buffer_list ()

debugger/main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ let main () =
230230
if !Parameters.version
231231
then printf "\tOCaml Debugger version %s@.@." Config.version;
232232
Loadprinter.init();
233-
Load_path.init !default_load_path;
233+
Load_path.init ~auto_include:Compmisc.auto_include !default_load_path;
234234
Clflags.recursive_types := true; (* Allow recursive types. *)
235235
toplevel_loop (); (* Toplevel. *)
236236
kill_program ();

debugger/program_management.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ let initialize_loading () =
128128
end;
129129
Symbols.clear_symbols ();
130130
Symbols.read_symbols 0 !program_name;
131-
Load_path.init (Load_path.get_paths () @ !Symbols.program_source_dirs);
131+
let dirs = Load_path.get_paths () @ !Symbols.program_source_dirs in
132+
Load_path.init ~auto_include:Compmisc.auto_include dirs;
132133
Envaux.reset_cache ~preserve_persistent_env:false;
133134
if !debug_loading then
134135
prerr_endline "Opening a socket...";

driver/compenv.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ let read_one_param ppf position name v =
261261
| "noassert" -> set "noassert" [ noassert ] v
262262
| "noautolink" -> set "noautolink" [ no_auto_link ] v
263263
| "nostdlib" -> set "nostdlib" [ no_std_include ] v
264+
| "nocwd" -> set "nocwd" [ no_cwd ] v
264265
| "linkall" -> set "linkall" [ link_everything ] v
265266
| "nolabels" -> set "nolabels" [ classic ] v
266267
| "principal" -> set "principal" [ principal ] v

driver/compmisc.ml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@
1313
(* *)
1414
(**************************************************************************)
1515

16+
let auto_include find_in_dir fn =
17+
if !Clflags.no_std_include then
18+
raise Not_found
19+
else
20+
let alert = Location.auto_include_alert in
21+
Load_path.auto_include_otherlibs alert find_in_dir fn
22+
1623
(* Initialize the search path.
17-
[dir] is always searched first (default: the current directory),
24+
[dir] (default: the current directory)
25+
is always searched first unless -nocwd is specified,
1826
then the directories specified with the -I option (in command-line order),
1927
then the standard library directory (unless the -nostdlib option is given).
2028
*)
@@ -30,8 +38,13 @@ let init_path ?(dir="") () =
3038
!Compenv.first_include_dirs
3139
in
3240
let exp_dirs =
33-
List.map (Misc.expand_directory Config.standard_library) dirs in
34-
Load_path.init (dir :: List.rev_append exp_dirs (Clflags.std_include_dir ()));
41+
List.map (Misc.expand_directory Config.standard_library) dirs
42+
in
43+
let dirs =
44+
(if !Clflags.no_cwd then [] else [dir])
45+
@ List.rev_append exp_dirs (Clflags.std_include_dir ())
46+
in
47+
Load_path.init ~auto_include dirs;
3548
Env.reset_cache ~preserve_persistent_env:false
3649

3750
(* Return the initial environment in which compilation proceeds. *)

driver/compmisc.mli

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ val read_clflags_from_env : unit -> unit
2222

2323
val with_ppf_dump : ?stdout:unit ->
2424
file_prefix:string -> (Format.formatter -> 'a) -> 'a
25+
26+
val auto_include :
27+
(Load_path.Dir.t -> string -> string option) -> string -> string
28+
(** [auto_include find_in_dir fn] is a callback function to be passed to
29+
{!Load_path.init} and automatically adds [-I +lib] to the load path after
30+
displaying an alert. *)
31+

driver/main_args.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,10 @@ let mk_nostdlib f =
421421
" Do not add default directory to the list of include directories"
422422
;;
423423

424+
let mk_nocwd f =
425+
"-nocwd", Arg.Unit f,
426+
" Do not implicitly add the current directory to the load path"
427+
424428
let mk_no_unbox_free_vars_of_closures f =
425429
"-no-unbox-free-vars-of-closures", Arg.Unit f,
426430
" Do not unbox variables that will appear inside function closures"
@@ -959,6 +963,7 @@ module type Common_options = sig
959963
val _noassert : unit -> unit
960964
val _nolabels : unit -> unit
961965
val _nostdlib : unit -> unit
966+
val _nocwd : unit -> unit
962967
val _open : string -> unit
963968
val _ppx : string -> unit
964969
val _principal : unit -> unit
@@ -1247,6 +1252,7 @@ struct
12471252
mk_noautolink_byt F._noautolink;
12481253
mk_nolabels F._nolabels;
12491254
mk_nostdlib F._nostdlib;
1255+
mk_nocwd F._nocwd;
12501256
mk_nopervasives F._nopervasives;
12511257
mk_o F._o;
12521258
mk_opaque F._opaque;
@@ -1335,6 +1341,7 @@ struct
13351341
mk_noprompt F._noprompt;
13361342
mk_nopromptcont F._nopromptcont;
13371343
mk_nostdlib F._nostdlib;
1344+
mk_nocwd F._nocwd;
13381345
mk_nopervasives F._nopervasives;
13391346
mk_open F._open;
13401347
mk_ppx F._ppx;
@@ -1448,6 +1455,7 @@ struct
14481455
mk_no_insn_sched F._no_insn_sched;
14491456
mk_nolabels F._nolabels;
14501457
mk_nostdlib F._nostdlib;
1458+
mk_nocwd F._nocwd;
14511459
mk_nopervasives F._nopervasives;
14521460
mk_no_unbox_free_vars_of_closures F._no_unbox_free_vars_of_closures;
14531461
mk_no_unbox_specialised_args F._no_unbox_specialised_args;
@@ -1582,6 +1590,7 @@ module Make_opttop_options (F : Opttop_options) = struct
15821590
mk_noprompt F._noprompt;
15831591
mk_nopromptcont F._nopromptcont;
15841592
mk_nostdlib F._nostdlib;
1593+
mk_nocwd F._nocwd;
15851594
mk_nopervasives F._nopervasives;
15861595
mk_no_unbox_free_vars_of_closures F._no_unbox_free_vars_of_closures;
15871596
mk_no_unbox_specialised_args F._no_unbox_specialised_args;
@@ -1672,6 +1681,7 @@ struct
16721681
mk_noassert F._noassert;
16731682
mk_nolabels F._nolabels;
16741683
mk_nostdlib F._nostdlib;
1684+
mk_nocwd F._nocwd;
16751685
mk_open F._open;
16761686
mk_pp F._pp;
16771687
mk_ppx F._ppx;
@@ -1768,6 +1778,7 @@ module Default = struct
17681778
let _noassert = set noassert
17691779
let _nolabels = set classic
17701780
let _nostdlib = set no_std_include
1781+
let _nocwd = set no_cwd
17711782
let _open s = open_modules := (s :: (!open_modules))
17721783
let _principal = set principal
17731784
let _rectypes = set recursive_types

driver/main_args.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module type Common_options = sig
3030
val _noassert : unit -> unit
3131
val _nolabels : unit -> unit
3232
val _nostdlib : unit -> unit
33+
val _nocwd : unit -> unit
3334
val _open : string -> unit
3435
val _ppx : string -> unit
3536
val _principal : unit -> unit

otherlibs/Makefile.otherlibs.common

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ $(LIBNAME).cmxs: $(LIBNAME).cmxa $(STUBSLIB)
8888
lib$(CLIBNAME).$(A): $(COBJS)
8989
$(MKLIB_CMD) -oc $(CLIBNAME) $(COBJS) $(LDOPTS)
9090

91+
INSTALL_LIBDIR_LIBNAME = $(INSTALL_LIBDIR)/$(LIBNAME)
92+
9193
install::
9294
if test -f dll$(CLIBNAME)$(EXT_DLL); then \
9395
$(INSTALL_PROG) \
@@ -96,15 +98,21 @@ install::
9698
ifneq "$(STUBSLIB)" ""
9799
$(INSTALL_DATA) $(STUBSLIB) "$(INSTALL_LIBDIR)/"
98100
endif
99-
101+
# If installing over a previous OCaml version, ensure the library is removed
102+
# from the previous installation.
103+
rm -f $(addprefix "$(INSTALL_LIBDIR)"/, \
104+
$(LIBNAME).cma $(CMIFILES) \
105+
$(CMIFILES:.cmi=.mli) $(CMIFILES:.cmi=.cmti) \
106+
$(CAMLOBJS_NAT) $(LIBNAME).cmxa $(LIBNAME).cmxs $(LIBNAME).$(A))
107+
$(MKDIR) "$(INSTALL_LIBDIR_LIBNAME)"
100108
$(INSTALL_DATA) \
101109
$(LIBNAME).cma $(CMIFILES) \
102-
"$(INSTALL_LIBDIR)/"
110+
"$(INSTALL_LIBDIR_LIBNAME)/"
103111
ifeq "$(INSTALL_SOURCE_ARTIFACTS)" "true"
104112
$(INSTALL_DATA) \
105113
$(CMIFILES:.cmi=.mli) \
106114
$(CMIFILES:.cmi=.cmti) \
107-
"$(INSTALL_LIBDIR)/"
115+
"$(INSTALL_LIBDIR_LIBNAME)/"
108116
endif
109117
if test -n "$(HEADERS)"; then \
110118
$(INSTALL_DATA) $(HEADERS) "$(INSTALL_LIBDIR)/caml/"; \
@@ -113,9 +121,9 @@ endif
113121
installopt:
114122
$(INSTALL_DATA) \
115123
$(CAMLOBJS_NAT) $(LIBNAME).cmxa $(LIBNAME).$(A) \
116-
"$(INSTALL_LIBDIR)/"
124+
"$(INSTALL_LIBDIR_LIBNAME)/"
117125
if test -f $(LIBNAME).cmxs; then \
118-
$(INSTALL_PROG) $(LIBNAME).cmxs "$(INSTALL_LIBDIR)"; \
126+
$(INSTALL_PROG) $(LIBNAME).cmxs "$(INSTALL_LIBDIR_LIBNAME)"; \
119127
fi
120128

121129
partialclean:

otherlibs/bigarray/dune

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525

2626
(install
2727
(files
28-
.bigarray.objs/native/bigarray.cmx
29-
bigarray.cmxa
30-
bigarray.a
31-
bigarray.cmxs
32-
bigarray.cma
33-
.bigarray.objs/byte/bigarray.cmi
34-
.bigarray.objs/byte/bigarray.cmti
35-
bigarray.mli
28+
(.bigarray.objs/native/bigarray.cmx as bigarray/bigarray.cmx)
29+
(bigarray.cmxa as bigarray/bigarray.cmxa)
30+
(bigarray.a as bigarray/bigarray.a)
31+
(bigarray.cmxs as bigarray/bigarray.cmxs)
32+
(bigarray.cma as bigarray/bigarray.cma)
33+
(.bigarray.objs/byte/bigarray.cmi as bigarray/bigarray.cmi)
34+
(.bigarray.objs/byte/bigarray.cmti as bigarray/bigarray.cmti)
35+
(bigarray.mli as bigarray/bigarray.mli)
3636
)
3737
(section lib)
3838
(package ocaml))

otherlibs/dynlink/Makefile

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ COMPILERLIBS_SOURCES=\
7777
utils/identifiable.ml \
7878
utils/numbers.ml \
7979
utils/arg_helper.ml \
80+
utils/local_store.ml \
81+
utils/load_path.ml \
8082
utils/clflags.ml \
8183
utils/profile.ml \
8284
utils/consistbl.ml \
8385
utils/terminfo.ml \
8486
utils/warnings.ml \
85-
utils/local_store.ml \
86-
utils/load_path.ml \
8787
utils/int_replace_polymorphic_compare.ml \
8888
typing/ident.ml \
8989
utils/compilation_unit.ml \
@@ -236,21 +236,29 @@ $(eval $(call PROGRAM_SYNONYM,extract_crc))
236236
$(extract_crc): dynlink.cma dynlink_compilerlibs.cmo extract_crc.cmo
237237
$(OCAMLC) -o $@ $^
238238

239+
INSTALL_LIBDIR_DYNLINK = $(INSTALL_LIBDIR)/dynlink
240+
239241
install:
242+
# If installing over a previous OCaml version, ensure dynlink is removed from
243+
# the previous installation.
244+
rm -f "$(INSTALL_LIBDIR)"/dynlink.cm* "$(INSTALL_LIBDIR)/dynlink.mli" \
245+
"$(INSTALL_LIBDIR)/dynlink.$(A)" \
246+
$(addprefix "$(INSTALL_LIBDIR)/", $(notdir $(NATOBJS)))
247+
$(MKDIR) "$(INSTALL_LIBDIR_DYNLINK)"
240248
$(INSTALL_DATA) \
241249
dynlink.cmi dynlink.cma \
242-
"$(INSTALL_LIBDIR)"
250+
"$(INSTALL_LIBDIR_DYNLINK)"
243251
ifeq "$(INSTALL_SOURCE_ARTIFACTS)" "true"
244252
$(INSTALL_DATA) \
245253
dynlink.cmti dynlink.mli \
246-
"$(INSTALL_LIBDIR)"
254+
"$(INSTALL_LIBDIR_DYNLINK)"
247255
endif
248256

249-
installopt:
257+
installopt:g
250258
ifeq "$(strip $(NATDYNLINK))" "true"
251259
$(INSTALL_DATA) \
252260
$(NATOBJS) dynlink.cmxa dynlink.$(A) \
253-
"$(INSTALL_LIBDIR)"
261+
"$(INSTALL_LIBDIR_DYNLINK)"
254262
endif
255263

256264
partialclean:

otherlibs/dynlink/dune

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -374,18 +374,18 @@
374374

375375
(install
376376
(files
377-
.dynlink_internal.objs/native/dynlink_common.cmx
378-
.dynlink_internal.objs/native/dynlink_platform_intf.cmx
379-
.dynlink_internal.objs/native/dynlink_types.cmx
380-
.dynlink_internal.objs/native/dynlink.cmx
381-
dynlink.cma
382-
dynlink.cmxa
383-
dynlink.a
384-
; dynlink.cmxs
385-
dynlink.mli
386-
dynlink.cmi
387-
(.dynlink_internal.objs/byte/dynlink.cmti as dynlink.cmti)
388-
(extract_crc.bc as extract_crc)
377+
(.dynlink_internal.objs/native/dynlink_common.cmx as dynlink/dynlink_common.cmx)
378+
(.dynlink_internal.objs/native/dynlink_platform_intf.cmx as dynlink/dynlink_platform_intf.cmx)
379+
(.dynlink_internal.objs/native/dynlink_types.cmx as dynlink/dynlink_types.cmx)
380+
(.dynlink_internal.objs/native/dynlink.cmx as dynlink/dynlink.cmx)
381+
(dynlink.cma as dynlink/dynlink.cma)
382+
(dynlink.cmxa as dynlink/dynlink.cmxa)
383+
(dynlink.a as dynlink/dynlink.a)
384+
; (dynlink.cmxs as dynlink/dynlink.cmxs)
385+
(dynlink.mli as dynlink/dynlink.mli)
386+
(dynlink.cmi as dynlink/dynlink.cmi)
387+
(.dynlink_internal.objs/byte/dynlink.cmti as dynlink/dynlink.cmti)
388+
(extract_crc.bc as dynlink/extract_crc)
389389

390390
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Misc.cmx
391391
)

0 commit comments

Comments
 (0)