The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #11198 from dra27/lib-layout-otherlibs

[1/3] Restructure LIBDIR: Move Dynlink, Str and Unix to sub-directories

authored by

David Allsopp and committed by
GitHub
c1b07c81 ab544472

+190 -54
+1
.depend
··· 6019 6019 utils/clflags.cmx \ 6020 6020 driver/compmisc.cmi 6021 6021 driver/compmisc.cmi : \ 6022 + utils/load_path.cmi \ 6022 6023 typing/env.cmi \ 6023 6024 utils/clflags.cmi 6024 6025 driver/errors.cmo : \
+6
Changes
··· 267 267 (Sébastien Hinderer, review by David Allsopp, Nicolás Ojeda Bär, 268 268 Xavier Leroy, Vincent Laviron and Antonin Décimo) 269 269 270 + * #11198: Install the Dynlink, Str and Unix libraries to individual 271 + subdirectories of LIBDIR. The compiler, debugger and toplevel automatically 272 + add `-I +lib` if required, but display an alert. 273 + (David Allsopp, review by Florian Angeletti, Nicolás Ojeda Bär, 274 + Valentin Gatien-Baron and Sébastien Hinderer) 275 + 270 276 - #11200: Install ocamlprof's Profiling runtime module to a +profiling, 271 277 removing it from the default namespace. 272 278 (David Allsopp, review by Sébastien Hinderer)
+2 -2
compilerlibs/Makefile.compilerlibs
··· 31 31 utils/identifiable.cmo \ 32 32 utils/numbers.cmo \ 33 33 utils/arg_helper.cmo \ 34 + utils/local_store.cmo \ 35 + utils/load_path.cmo \ 34 36 utils/clflags.cmo \ 35 37 utils/profile.cmo \ 36 - utils/local_store.cmo \ 37 - utils/load_path.cmo \ 38 38 utils/terminfo.cmo \ 39 39 utils/ccomp.cmo \ 40 40 utils/warnings.cmo \
+6
debugger/.depend
··· 72 72 debugger_lexer.cmi \ 73 73 debugger_config.cmi \ 74 74 debugcom.cmi \ 75 + ../driver/compmisc.cmi \ 75 76 checkpoints.cmi \ 76 77 breakpoints.cmi \ 77 78 command_line.cmi ··· 109 110 debugger_lexer.cmx \ 110 111 debugger_config.cmx \ 111 112 debugcom.cmx \ 113 + ../driver/compmisc.cmx \ 112 114 checkpoints.cmx \ 113 115 breakpoints.cmx \ 114 116 command_line.cmi ··· 323 325 exec.cmi \ 324 326 debugger_config.cmi \ 325 327 ../utils/config.cmi \ 328 + ../driver/compmisc.cmi \ 326 329 command_line.cmi \ 327 330 ../file_formats/cmi_format.cmi \ 328 331 ../utils/clflags.cmi \ ··· 345 348 exec.cmx \ 346 349 debugger_config.cmx \ 347 350 ../utils/config.cmx \ 351 + ../driver/compmisc.cmx \ 348 352 command_line.cmx \ 349 353 ../file_formats/cmi_format.cmx \ 350 354 ../utils/clflags.cmx \ ··· 470 474 history.cmi \ 471 475 ../typing/envaux.cmi \ 472 476 debugger_config.cmi \ 477 + ../driver/compmisc.cmi \ 473 478 breakpoints.cmi \ 474 479 program_management.cmi 475 480 program_management.cmx : \ ··· 487 492 history.cmx \ 488 493 ../typing/envaux.cmx \ 489 494 debugger_config.cmx \ 495 + ../driver/compmisc.cmx \ 490 496 breakpoints.cmx \ 491 497 program_management.cmi 492 498 program_management.cmi :
+1 -1
debugger/command_line.ml
··· 262 262 let new_directory = argument_list_eol argument lexbuf in 263 263 if new_directory = [] then begin 264 264 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; 266 266 Envaux.reset_cache (); 267 267 Hashtbl.clear Debugger_config.load_path_for; 268 268 flush_buffer_list ()
+1 -1
debugger/main.ml
··· 229 229 if !Parameters.version 230 230 then printf "\tOCaml Debugger version %s@.@." Config.version; 231 231 Loadprinter.init(); 232 - Load_path.init !default_load_path; 232 + Load_path.init ~auto_include:Compmisc.auto_include !default_load_path; 233 233 Clflags.recursive_types := true; (* Allow recursive types. *) 234 234 toplevel_loop (); (* Toplevel. *) 235 235 kill_program ();
+2 -1
debugger/program_management.ml
··· 128 128 end; 129 129 Symbols.clear_symbols (); 130 130 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; 132 133 Envaux.reset_cache (); 133 134 if !debug_loading then 134 135 prerr_endline "Opening a socket...";
+8 -1
driver/compmisc.ml
··· 13 13 (* *) 14 14 (**************************************************************************) 15 15 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 + 16 23 (* Initialize the search path. 17 24 [dir] (default: the current directory) 18 25 is always searched first unless -nocwd is specified, ··· 37 44 (if !Clflags.no_cwd then [] else [dir]) 38 45 @ List.rev_append exp_dirs (Clflags.std_include_dir ()) 39 46 in 40 - Load_path.init(dirs); 47 + Load_path.init ~auto_include dirs; 41 48 Env.reset_cache () 42 49 43 50 (* Return the initial environment in which compilation proceeds. *)
+6
driver/compmisc.mli
··· 21 21 val read_clflags_from_env : unit -> unit 22 22 23 23 val with_ppf_dump : file_prefix:string -> (Format.formatter -> 'a) -> 'a 24 + 25 + val auto_include : 26 + (Load_path.Dir.t -> string -> string option) -> string -> string 27 + (** [auto_include find_in_dir fn] is a callback function to be passed to 28 + {!Load_path.init} and automatically adds [-I +lib] to the load path after 29 + displaying an alert. *)
+13 -5
otherlibs/Makefile.otherlibs.common
··· 85 85 lib$(CLIBNAME).$(A): $(COBJS) 86 86 $(MKLIB_CMD) -oc $(CLIBNAME) $(COBJS) $(LDOPTS) 87 87 88 + INSTALL_LIBDIR_LIBNAME = $(INSTALL_LIBDIR)/$(LIBNAME) 89 + 88 90 install:: 89 91 if test -f dll$(CLIBNAME)$(EXT_DLL); then \ 90 92 $(INSTALL_PROG) \ ··· 93 95 ifneq "$(STUBSLIB)" "" 94 96 $(INSTALL_DATA) $(STUBSLIB) "$(INSTALL_LIBDIR)/" 95 97 endif 96 - 98 + # If installing over a previous OCaml version, ensure the library is removed 99 + # from the previous installation. 100 + rm -f $(addprefix "$(INSTALL_LIBDIR)"/, \ 101 + $(LIBNAME).cma $(CMIFILES) \ 102 + $(CMIFILES:.cmi=.mli) $(CMIFILES:.cmi=.cmti) \ 103 + $(CAMLOBJS_NAT) $(LIBNAME).cmxa $(LIBNAME).cmxs $(LIBNAME).$(A)) 104 + $(MKDIR) "$(INSTALL_LIBDIR_LIBNAME)" 97 105 $(INSTALL_DATA) \ 98 106 $(LIBNAME).cma $(CMIFILES) \ 99 - "$(INSTALL_LIBDIR)/" 107 + "$(INSTALL_LIBDIR_LIBNAME)/" 100 108 ifeq "$(INSTALL_SOURCE_ARTIFACTS)" "true" 101 109 $(INSTALL_DATA) \ 102 110 $(CMIFILES:.cmi=.mli) \ 103 111 $(CMIFILES:.cmi=.cmti) \ 104 - "$(INSTALL_LIBDIR)/" 112 + "$(INSTALL_LIBDIR_LIBNAME)/" 105 113 endif 106 114 if test -n "$(HEADERS)"; then \ 107 115 $(INSTALL_DATA) $(HEADERS) "$(INSTALL_INCDIR)/"; \ ··· 110 118 installopt: 111 119 $(INSTALL_DATA) \ 112 120 $(CAMLOBJS_NAT) $(LIBNAME).cmxa $(LIBNAME).$(A) \ 113 - "$(INSTALL_LIBDIR)/" 121 + "$(INSTALL_LIBDIR_LIBNAME)/" 114 122 if test -f $(LIBNAME).cmxs; then \ 115 - $(INSTALL_PROG) $(LIBNAME).cmxs "$(INSTALL_LIBDIR)"; \ 123 + $(INSTALL_PROG) $(LIBNAME).cmxs "$(INSTALL_LIBDIR_LIBNAME)"; \ 116 124 fi 117 125 118 126 partialclean:
+13 -5
otherlibs/dynlink/Makefile
··· 79 79 utils/identifiable.ml \ 80 80 utils/numbers.ml \ 81 81 utils/arg_helper.ml \ 82 + utils/local_store.ml \ 83 + utils/load_path.ml \ 82 84 utils/clflags.ml \ 83 85 utils/profile.ml \ 84 86 utils/consistbl.ml \ 85 87 utils/terminfo.ml \ 86 88 utils/warnings.ml \ 87 - utils/local_store.ml \ 88 - utils/load_path.ml \ 89 89 utils/int_replace_polymorphic_compare.ml \ 90 90 utils/lazy_backtrack.ml \ 91 91 parsing/location.ml \ ··· 242 242 $(extract_crc): dynlink.cma byte/dynlink_compilerlibs.cmo extract_crc.cmo 243 243 $(OCAMLC) -o $@ $^ 244 244 245 + INSTALL_LIBDIR_DYNLINK = $(INSTALL_LIBDIR)/dynlink 246 + 245 247 install: 248 + # If installing over a previous OCaml version, ensure dynlink is removed from 249 + # the previous installation. 250 + rm -f "$(INSTALL_LIBDIR)"/dynlink.cm* "$(INSTALL_LIBDIR)/dynlink.mli" \ 251 + "$(INSTALL_LIBDIR)/dynlink.$(A)" \ 252 + $(addprefix "$(INSTALL_LIBDIR)/", $(notdir $(NATOBJS))) 253 + $(MKDIR) "$(INSTALL_LIBDIR_DYNLINK)" 246 254 $(INSTALL_DATA) \ 247 255 dynlink.cmi dynlink.cma \ 248 - "$(INSTALL_LIBDIR)" 256 + "$(INSTALL_LIBDIR_DYNLINK)" 249 257 ifeq "$(INSTALL_SOURCE_ARTIFACTS)" "true" 250 258 $(INSTALL_DATA) \ 251 259 dynlink.cmti dynlink.mli \ 252 - "$(INSTALL_LIBDIR)" 260 + "$(INSTALL_LIBDIR_DYNLINK)" 253 261 endif 254 262 255 263 installopt: 256 264 ifeq "$(strip $(NATDYNLINK))" "true" 257 265 $(INSTALL_DATA) \ 258 266 $(NATOBJS) dynlink.cmxa dynlink.$(A) \ 259 - "$(INSTALL_LIBDIR)" 267 + "$(INSTALL_LIBDIR_DYNLINK)" 260 268 endif 261 269 262 270 partialclean:
+10 -1
parsing/ast_mapper.ml
··· 903 903 | "include_dirs" -> 904 904 Clflags.include_dirs := get_list get_string payload 905 905 | "load_path" -> 906 - Load_path.init (get_list get_string payload) 906 + (* Duplicates Compmisc.auto_include, since we can't reference Compmisc 907 + from this module. *) 908 + let auto_include find_in_dir fn = 909 + if !Clflags.no_std_include then 910 + raise Not_found 911 + else 912 + let alert = Location.auto_include_alert in 913 + Load_path.auto_include_otherlibs alert find_in_dir fn 914 + in 915 + Load_path.init ~auto_include (get_list get_string payload) 907 916 | "open_modules" -> 908 917 Clflags.open_modules := get_list get_string payload 909 918 | "for_package" ->
+14 -3
parsing/location.ml
··· 18 18 type t = Warnings.loc = 19 19 { loc_start: position; loc_end: position; loc_ghost: bool } 20 20 21 - let in_file name = 22 - let loc = { dummy_pos with pos_fname = name } in 23 - { loc_start = loc; loc_end = loc; loc_ghost = true } 21 + let in_file = Warnings.ghost_loc_in_file 24 22 25 23 let none = in_file "_none_" 26 24 let is_none l = (l = none) ··· 896 894 897 895 let deprecated ?def ?use loc message = 898 896 alert ?def ?use ~kind:"deprecated" loc message 897 + 898 + let auto_include_alert lib = 899 + let message = Printf.sprintf "\ 900 + OCaml's lib directory layout changed in 5.0. The %s subdirectory has been \ 901 + automatically added to the search path, but you should add -I +%s to the \ 902 + command-line to silence this alert (e.g. by adding %s to the list of \ 903 + libraries in your dune file, or adding use_%s to your _tags file for \ 904 + ocamlbuild, or using -package %s for ocamlfind)." lib lib lib lib lib in 905 + let alert = 906 + {Warnings.kind="ocaml_deprecated_auto_include"; use=none; def=none; 907 + message = Format.asprintf "@[@\n%a@]" Format.pp_print_text message} 908 + in 909 + prerr_alert none alert 899 910 900 911 (******************************************************************************) 901 912 (* Reporting errors on exceptions *)
+3
parsing/location.mli
··· 243 243 val alert: ?def:t -> ?use:t -> kind:string -> t -> string -> unit 244 244 (** Prints an arbitrary alert. *) 245 245 246 + val auto_include_alert: string -> unit 247 + (** Prints an alert that -I +lib has been automatically added ot the load 248 + path *) 246 249 247 250 (** {1 Reporting errors} *) 248 251
+6 -6
tools/Makefile
··· 84 84 # The profiler 85 85 86 86 OCAMLPROF=config.cmo build_path_prefix_map.cmo misc.cmo identifiable.cmo \ 87 - numbers.cmo arg_helper.cmo clflags.cmo terminfo.cmo \ 88 - warnings.cmo location.cmo longident.cmo docstrings.cmo \ 87 + numbers.cmo arg_helper.cmo local_store.cmo load_path.cmo clflags.cmo \ 88 + terminfo.cmo warnings.cmo location.cmo longident.cmo docstrings.cmo \ 89 89 syntaxerr.cmo ast_helper.cmo \ 90 90 camlinternalMenhirLib.cmo parser.cmo \ 91 91 pprintast.cmo \ ··· 98 98 99 99 OCAMLCP = config.cmo build_path_prefix_map.cmo misc.cmo profile.cmo \ 100 100 warnings.cmo identifiable.cmo numbers.cmo arg_helper.cmo \ 101 - clflags.cmo local_store.cmo \ 102 - terminfo.cmo location.cmo load_path.cmo ccomp.cmo compenv.cmo \ 101 + local_store.cmo load_path.cmo clflags.cmo \ 102 + terminfo.cmo location.cmo ccomp.cmo compenv.cmo \ 103 103 main_args.cmo ocamlcp_common.cmo 104 104 105 105 ocamlcp$(EXE): $(OCAMLCP) ocamlcp.cmo ··· 139 139 # To make custom toplevels 140 140 141 141 OCAMLMKTOP=config.cmo build_path_prefix_map.cmo misc.cmo \ 142 - identifiable.cmo numbers.cmo arg_helper.cmo clflags.cmo \ 143 - local_store.cmo load_path.cmo profile.cmo ccomp.cmo ocamlmktop.cmo 142 + identifiable.cmo numbers.cmo arg_helper.cmo local_store.cmo \ 143 + load_path.cmo clflags.cmo profile.cmo ccomp.cmo ocamlmktop.cmo 144 144 145 145 ocamlmktop$(EXE): $(OCAMLMKTOP) 146 146 ocamlmktop.opt$(EXE): $(call byte2native, $(OCAMLMKTOP))
+1 -1
toplevel/topcommon.ml
··· 274 274 [expand "+camlp4"]; 275 275 ] 276 276 in 277 - Load_path.init load_path; 277 + Load_path.init ~auto_include:Compmisc.auto_include load_path; 278 278 Dll.add_path load_path 279 279 280 280 let update_search_path_from_env () =
+60 -11
utils/load_path.ml
··· 31 31 let path t = t.path 32 32 let files t = t.files 33 33 34 + let find t fn = 35 + if List.mem fn t.files then 36 + Some (Filename.concat t.path fn) 37 + else 38 + None 39 + 40 + let find_uncap t fn = 41 + let fn = String.uncapitalize_ascii fn in 42 + let search base = 43 + if String.uncapitalize_ascii base = fn then 44 + Some (Filename.concat t.path base) 45 + else 46 + None 47 + in 48 + List.find_map search t.files 49 + 34 50 (* For backward compatibility reason, simulate the behavior of 35 51 [Misc.find_in_path]: silently ignore directories that don't exist 36 52 + treat [""] as the current directory. *) ··· 45 61 end 46 62 47 63 let dirs = s_ref [] 64 + let default_auto_include_callback _ _ = raise Not_found 65 + let auto_include_callback = ref default_auto_include_callback 48 66 49 67 let reset () = 50 68 assert (not Config.merlin || Local_store.is_bound ()); 51 69 STbl.clear !files; 52 70 STbl.clear !files_uncap; 53 - dirs := [] 71 + dirs := []; 72 + auto_include_callback := default_auto_include_callback 54 73 55 74 let get () = List.rev !dirs 56 75 let get_paths () = List.rev_map Dir.path !dirs ··· 66 85 STbl.replace !files_uncap (String.uncapitalize_ascii base) fn 67 86 ) dir.Dir.files 68 87 69 - let init l = 88 + let init ~auto_include l = 70 89 reset (); 71 90 dirs := List.rev_map Dir.create l; 72 - List.iter prepend_add !dirs 91 + List.iter prepend_add !dirs; 92 + auto_include_callback := auto_include 73 93 74 94 let remove_dir dir = 75 95 assert (not Config.merlin || Local_store.is_bound ()); ··· 109 129 110 130 let is_basename fn = Filename.basename fn = fn 111 131 132 + let auto_include_libs libs alert find_in_dir fn = 133 + let scan (lib, lazy dir) = 134 + let file = find_in_dir dir fn in 135 + let alert_and_add_dir _ = 136 + alert lib; 137 + append_dir dir 138 + in 139 + Option.iter alert_and_add_dir file; 140 + file 141 + in 142 + match List.find_map scan libs with 143 + | Some base -> base 144 + | None -> raise Not_found 145 + 146 + let auto_include_otherlibs = 147 + (* Ensure directories are only ever scanned once *) 148 + let expand = Misc.expand_directory Config.standard_library in 149 + let otherlibs = 150 + let read_lib lib = lazy (Dir.create (expand ("+" ^ lib))) in 151 + List.map (fun lib -> (lib, read_lib lib)) ["dynlink"; "str"; "unix"] in 152 + auto_include_libs otherlibs 153 + 112 154 let find fn = 113 155 assert (not Config.merlin || Local_store.is_bound ()); 114 - if is_basename fn && not !Sys.interactive then 115 - STbl.find !files fn 116 - else 117 - Misc.find_in_path (get_paths ()) fn 156 + try 157 + if is_basename fn && not !Sys.interactive then 158 + STbl.find !files fn 159 + else 160 + Misc.find_in_path (get_paths ()) fn 161 + with Not_found -> 162 + !auto_include_callback Dir.find fn 118 163 119 164 let find_uncap fn = 120 165 assert (not Config.merlin || Local_store.is_bound ()); 121 - if is_basename fn && not !Sys.interactive then 122 - STbl.find !files_uncap (String.uncapitalize_ascii fn) 123 - else 124 - Misc.find_in_path_uncap (get_paths ()) fn 166 + try 167 + if is_basename fn && not !Sys.interactive then 168 + STbl.find !files_uncap (String.uncapitalize_ascii fn) 169 + else 170 + Misc.find_in_path_uncap (get_paths ()) fn 171 + with Not_found -> 172 + let fn_uncap = String.uncapitalize_ascii fn in 173 + !auto_include_callback Dir.find_uncap fn_uncap
+29 -14
utils/load_path.mli
··· 31 31 val reset : unit -> unit 32 32 (** Remove all directories *) 33 33 34 - val init : string list -> unit 34 + module Dir : sig 35 + type t 36 + (** Represent one directory in the load path. *) 37 + 38 + val create : string -> t 39 + 40 + val path : t -> string 41 + 42 + val files : t -> string list 43 + (** All the files in that directory. This doesn't include files in 44 + sub-directories of this directory. *) 45 + 46 + val find : t -> string -> string option 47 + (** [find dir fn] returns the full path to [fn] in [dir]. *) 48 + 49 + val find_uncap : t -> string -> string option 50 + (** As {!find}, but search also for uncapitalized name, i.e. if name is 51 + Foo.ml, either /path/Foo.ml or /path/foo.ml may be returned. *) 52 + end 53 + 54 + val init : 55 + auto_include:((Dir.t -> string -> string option) -> string -> string) -> 56 + string list -> unit 35 57 (** [init l] is the same as [reset (); List.iter add_dir (List.rev l)] *) 58 + 59 + val auto_include_otherlibs : 60 + (string -> unit) -> (Dir.t -> string -> string option) -> string -> string 61 + (** [auto_include_otherlibs alert] is a callback function to be passed to 62 + {!Load_path.init} and automatically adds [-I +lib] to the load path after 63 + calling [alert lib]. *) 36 64 37 65 val get_paths : unit -> string list 38 66 (** Return the list of directories passed to [add_dir] so far. *) ··· 46 74 val find_uncap : string -> string 47 75 (** Same as [find], but search also for uncapitalized name, i.e. if 48 76 name is Foo.ml, allow /path/Foo.ml and /path/foo.ml to match. *) 49 - 50 - module Dir : sig 51 - type t 52 - (** Represent one directory in the load path. *) 53 - 54 - val create : string -> t 55 - 56 - val path : t -> string 57 - 58 - val files : t -> string list 59 - (** All the files in that directory. This doesn't include files in 60 - sub-directories of this directory. *) 61 - end 62 77 63 78 val[@deprecated] add : Dir.t -> unit 64 79 (** Old name for {!append_dir} *)
+5 -2
utils/warnings.ml
··· 686 686 | Letter of char * modifier option 687 687 | Num of int * int * modifier 688 688 689 + let ghost_loc_in_file name = 690 + let pos = { Lexing.dummy_pos with pos_fname = name } in 691 + { loc_start = pos; loc_end = pos; loc_ghost = true } 692 + 689 693 let letter_alert tokens = 690 694 let print_warning_char ppf c = 691 695 let lowercase = Char.lowercase_ascii c = c in ··· 724 728 match consecutive_letters with 725 729 | [] -> None 726 730 | example :: _ -> 727 - let pos = { Lexing.dummy_pos with pos_fname = "_none_" } in 728 - let nowhere = { loc_start=pos; loc_end=pos; loc_ghost=true } in 731 + let nowhere = ghost_loc_in_file "_none_" in 729 732 let spelling_hint ppf = 730 733 let max_seq_len = 731 734 List.fold_left (fun l x -> Int.max l (List.length x))
+3
utils/warnings.mli
··· 26 26 loc_ghost: bool; 27 27 } 28 28 29 + val ghost_loc_in_file : string -> loc 30 + (** Return an empty ghost range located in a given file *) 31 + 29 32 type field_usage_warning = 30 33 | Unused 31 34 | Not_read