From 6e500a198e34070e8079f962a5816d9a11b3c7e1 Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Sat, 13 Jul 2024 21:29:10 +0200 Subject: [PATCH] Update the installation test for enable-relative --- Makefile | 2 +- driver/compmisc.ml | 10 ++-- driver/compmisc.mli | 4 +- tools/test_install.ml | 129 +++++++++++++++++++++++++++++++----------- utils/ccomp.ml | 4 +- utils/ccomp.mli | 3 +- utils/clflags.ml | 8 +-- utils/clflags.mli | 4 +- 8 files changed, 114 insertions(+), 50 deletions(-) diff --git a/Makefile b/Makefile index 14eeac8d6271..9462df3a8832 100644 --- a/Makefile +++ b/Makefile @@ -952,7 +952,7 @@ tools/test_install.opt$(EXE): -o test_install.opt$(EXE) test_install.mli test_install.ml test-installation: tools/test_install.opt$(EXE) - @$^ "$(BINDIR)" "$(LIBDIR)" $(ALL_OTHERLIBS) + @$^ "$(BINDIR)" "$(LIBDIR)" "$(RELOCATABLE)" $(ALL_OTHERLIBS) else test-installation: $(error The test-installation target must be invoked as \ diff --git a/driver/compmisc.ml b/driver/compmisc.ml index d4100900380c..596a11e06b39 100644 --- a/driver/compmisc.ml +++ b/driver/compmisc.ml @@ -28,7 +28,9 @@ let auto_include find_in_dir fn = then the directories specified with the -H option (in command line order). *) -let init_path ?(auto_include=auto_include) ?(dir="") () = +let init_path ?(auto_include=auto_include) + ?(standard_library=Config.standard_library) + ?(dir="") () = let visible = if !Clflags.use_threads then "+threads" :: !Clflags.include_dirs else @@ -44,14 +46,14 @@ let init_path ?(auto_include=auto_include) ?(dir="") () = !Compenv.first_include_dirs] in let visible = - List.map (Misc.expand_directory Config.standard_library) visible + List.map (Misc.expand_directory standard_library) visible in let visible = (if !Clflags.no_cwd then [] else [dir]) - @ List.rev_append visible (Clflags.std_include_dir ()) + @ List.rev_append visible (Clflags.std_include_dir ~standard_library ()) in let hidden = - List.rev_map (Misc.expand_directory Config.standard_library) + List.rev_map (Misc.expand_directory standard_library) !Clflags.hidden_include_dirs in Load_path.init ~auto_include ~visible ~hidden; diff --git a/driver/compmisc.mli b/driver/compmisc.mli index 7b5e1808f0ca..9c7fa1644eca 100644 --- a/driver/compmisc.mli +++ b/driver/compmisc.mli @@ -13,8 +13,8 @@ (* *) (**************************************************************************) -val init_path : - ?auto_include:Load_path.auto_include_callback -> ?dir:string -> unit -> unit +val init_path : ?auto_include:Load_path.auto_include_callback + -> ?standard_library:string -> ?dir:string -> unit -> unit val initial_env : unit -> Env.t (* Support for flags that can also be set from an environment variable *) diff --git a/tools/test_install.ml b/tools/test_install.ml index cae49935d310..f3c49052b2c0 100644 --- a/tools/test_install.ml +++ b/tools/test_install.ml @@ -242,7 +242,8 @@ let compile_with_options env compiler ~native options List.iter Sys.remove files; Some (f test_program) -let compile_obj env compiler ~native runtime test_program description f = +let compile_obj env standard_library compiler ~native + runtime test_program description f = Printf.printf " Compiling %s\n%!" description; Out_channel.with_open_text "test_install_script.ml" (fun oc -> Printf.fprintf oc @@ -277,7 +278,7 @@ let compile_obj env compiler ~native runtime test_program description f = \ caml_startup(argv);\n\ \ caml_shutdown();\n\ }\n"); - if Ccomp.compile_file "test_install_main.c" <> 0 then begin + if Ccomp.compile_file ~standard_library "test_install_main.c" <> 0 then begin print_endline "Unexpected C compiler error"; exit 1 end; @@ -342,95 +343,155 @@ let run_program env test_program = exit 1 end -let compile_with_options ?(unix_only=false) env +let compile_with_options ?(unix_only=false) ?(full_only=false) ~full env compiler ~native options test_program description = - if unix_only && Sys.win32 then + if unix_only && Sys.win32 || full_only && not full then None else - let cont test_program () = - run_program env test_program; - Some test_program + let cont test_program = + if full_only then + fun () -> + run_program env test_program; + Sys.remove test_program; + None + else + fun () -> + run_program env test_program; + Some test_program in compile_with_options env compiler ~native options test_program description cont -let compile_obj ?(unix_only=false) env +let compile_obj ?(unix_only=false) ?(full_only=false) ~full env standard_library compiler ~native runtime test_program description = - if unix_only && Sys.win32 then + if unix_only && Sys.win32 || full_only && not full then None else - let cont test_program () = - run_program env test_program; - Some test_program + let cont test_program = + if full_only then + fun () -> + run_program env test_program; + Sys.remove test_program; + None + else + fun () -> + run_program env test_program; + Some test_program in - compile_obj env compiler ~native runtime test_program description cont + compile_obj env standard_library compiler ~native + runtime test_program description cont -let test_standard_library_location env bindir libdir ocamlc ocamlopt = +let test_standard_library_location ~full env bindir libdir ocamlc ocamlopt = Printf.printf "\nTesting compilation mechanisms for %s\n%!" bindir; let ocamlc_where = compiler_where env ocamlc in let ocamlopt_where = compiler_where env ocamlopt in Printf.printf " ocamlc -where: %s\n ocamlopt -where: %s\n%!" ocamlc_where ocamlopt_where; let unix_only = true in + let full_only = true in let programs = List.filter_map Fun.id [ - compile_with_options env ocamlc ~native:false + compile_with_options ~full_only ~full env ocamlc ~native:false [] "test_bytecode" "Bytecode (with tender)"; - compile_with_options env ocamlc ~native:false + compile_with_options ~full env ocamlc ~native:false ["-custom"] "test_custom_static" "Bytecode (-custom static runtime)"; - compile_with_options ~unix_only env ocamlc ~native:false + compile_with_options ~unix_only ~full env ocamlc ~native:false ["-custom"; "-runtime-variant"; "_shared"] "test_custom_shared" "Bytecode (-custom shared runtime)"; - compile_obj env ocamlc ~native:false + compile_obj ~full env libdir ocamlc ~native:false "-lcamlrun" "test_output_obj_static" "Bytecode (-output-obj static runtime)"; - compile_obj ~unix_only env ocamlc ~native:false + compile_obj ~unix_only ~full env libdir ocamlc ~native:false "-lcamlrun_shared" "test_output_obj_shared" "Bytecode (-output-obj shared runtime)"; - compile_with_options env ocamlc ~native:false + compile_with_options ~full env ocamlc ~native:false ["-output-complete-exe"] "test_output_complete_exe_static" "Bytecode (-output-complete-exe static runtime)"; - compile_with_options ~unix_only env ocamlc ~native:false + compile_with_options ~unix_only ~full env ocamlc ~native:false ["-output-complete-exe"; "-runtime-variant"; "_shared"] "test_output_complete_exe_shared" "Bytecode (-output-complete-exe shared runtime)"; - compile_with_options env ocamlopt ~native:true + compile_with_options ~full env ocamlopt ~native:true [] "test_native_static" "Native (static runtime)"; - compile_obj env ocamlopt ~native:true + compile_obj ~full env libdir ocamlopt ~native:true "-lasmrun" "test_native_output_obj_static" "Native (-output-obj static runtime)"; - compile_obj ~unix_only env ocamlopt ~native:true + compile_obj ~unix_only ~full env libdir ocamlopt ~native:true "-lasmrun_shared" "test_native_output_obj_shared" "Native (-output-obj shared runtime)"; ] in Printf.printf "Running programs\n%!"; List.filter_map (fun f -> f ()) programs -let run_tests env bindir libdir libraries = +let run_tests ~full env bindir libdir libraries = let libraries = sort_libraries libraries in let ocaml = exe (Filename.concat bindir "ocaml") in let ocamlnat = exe (Filename.concat bindir "ocamlnat") in let ocamlc = exe (Filename.concat bindir "ocamlc") in let ocamlopt = exe (Filename.concat bindir "ocamlopt") in - load_libraries_in_toplevel env ocaml "cma" libraries; + if full then + load_libraries_in_toplevel env ocaml "cma" libraries; load_libraries_in_toplevel env ocamlnat "cmxa" libraries; - load_libraries_in_prog env libdir ocamlc ~native:false libraries; + if full then + load_libraries_in_prog env libdir ocamlc ~native:false libraries; load_libraries_in_prog env libdir ocamlopt ~native:true libraries; - test_bytecode_binaries env bindir; - test_standard_library_location env bindir libdir ocamlc ocamlopt + if full then + test_bytecode_binaries env bindir; + test_standard_library_location ~full env bindir libdir ocamlc ocamlopt + +let rec split_dir acc dir = + let dirname = Filename.dirname dir in + if dirname = dir then + dir::acc + else + split_dir (Filename.basename dir :: acc) dirname + +let join_dir = function +| dir::dirs -> List.fold_left Filename.concat dir dirs +| [] -> assert false + +let rec split_to_prefix prefix bindir libdir = + match bindir, libdir with + | (dir1::bindir'), (dir2::libdir') -> + if dir1 = dir2 then + split_to_prefix (dir1::prefix) bindir' libdir' + else + join_dir (List.rev prefix), join_dir bindir, join_dir libdir + | [], _ + | _, [] -> + assert false let () = Compmisc.init_path (); - if Array.length Sys.argv < 3 then begin - Printf.eprintf "Usage: test_install [ ...]\n"; + if Array.length Sys.argv < 4 then begin + Printf.eprintf + "Usage: test_install [ ...]\n"; exit 2 end else let libraries = - Array.to_list (Array.sub Sys.argv 3 (Array.length Sys.argv - 3)) in + Array.to_list (Array.sub Sys.argv 4 (Array.length Sys.argv - 4)) in let bindir = Sys.argv.(1) in let libdir = Sys.argv.(2) in let env = make_env bindir libdir in - let programs = run_tests env bindir libdir libraries in - List.iter Sys.remove programs + let programs = run_tests ~full:true env bindir libdir libraries in + if Sys.argv.(3) = "yes" then + let prefix, bindir_suffix, libdir_suffix = + split_to_prefix [] (split_dir [] bindir) (split_dir [] libdir) in + let new_prefix = prefix ^ ".new" in + let bindir = Filename.concat new_prefix bindir_suffix in + let libdir = Filename.concat new_prefix libdir_suffix in + Printf.printf "\nRenaming %s to %s\n\n%!" prefix new_prefix; + Sys.rename prefix new_prefix; + at_exit (fun () -> + flush stderr; + flush stdout; + Printf.printf "\nRestoring %s to %s\n" new_prefix prefix; + Sys.rename new_prefix prefix); + Printf.printf "Re-running test programs\n%!"; + let env = make_env bindir libdir in + List.iter (run_program env) programs; + List.iter Sys.remove programs; + Compmisc.init_path ~standard_library:libdir (); + List.iter Sys.remove (run_tests ~full:false env bindir libdir libraries) diff --git a/utils/ccomp.ml b/utils/ccomp.ml index defe4d2a4b92..7fd40b232514 100644 --- a/utils/ccomp.ml +++ b/utils/ccomp.ml @@ -77,7 +77,7 @@ let display_msvc_output file name = close_in c; Sys.remove file -let compile_file ?output ?(opt="") ?stable_name name = +let compile_file ?standard_library ?output ?(opt="") ?stable_name name = let (pipe, file) = if Config.ccomp_type = "msvc" && not !Clflags.verbose then try @@ -116,7 +116,7 @@ let compile_file ?output ?(opt="") ?stable_name name = (List.map (Misc.expand_directory Config.standard_library) (List.rev ( !Clflags.hidden_include_dirs @ !Clflags.include_dirs)))) - (Clflags.std_include_flag "-I") + (Clflags.std_include_flag ?standard_library "-I") (Filename.quote name) (* cl tediously includes the name of the C file as the first thing it outputs (in fairness, the tedious thing is that there's no switch to diff --git a/utils/ccomp.mli b/utils/ccomp.mli index 38dfd5486f37..fe76dc0bb30f 100644 --- a/utils/ccomp.mli +++ b/utils/ccomp.mli @@ -23,7 +23,8 @@ val command: string -> int val run_command: string -> unit val compile_file: - ?output:string -> ?opt:string -> ?stable_name:string -> string -> int + ?standard_library:string -> ?output:string -> ?opt:string + -> ?stable_name:string -> string -> int val create_archive: string -> string list -> int val quote_files: response_files:bool -> string list -> string val quote_optfile: string option -> string diff --git a/utils/clflags.ml b/utils/clflags.ml index c822c2d05c68..20a95f25d097 100644 --- a/utils/clflags.ml +++ b/utils/clflags.ml @@ -156,12 +156,12 @@ let dont_write_files = ref false (* set to true under ocamldoc *) let insn_sched_default = true let insn_sched = ref insn_sched_default (* -[no-]insn-sched *) -let std_include_flag prefix = +let std_include_flag ?(standard_library=Config.standard_library) prefix = if !no_std_include then "" - else (prefix ^ (Filename.quote Config.standard_library)) + else (prefix ^ (Filename.quote standard_library)) -let std_include_dir () = - if !no_std_include then [] else [Config.standard_library] +let std_include_dir ?(standard_library=Config.standard_library) () = + if !no_std_include then [] else [standard_library] let shared = ref false (* -shared *) let dlcode = ref true (* not -nodynlink *) diff --git a/utils/clflags.mli b/utils/clflags.mli index 9de00e1ab659..3859aeb7429d 100644 --- a/utils/clflags.mli +++ b/utils/clflags.mli @@ -188,8 +188,8 @@ val inline_lifting_benefit : Int_arg_helper.parsed ref val default_inline_branch_factor : float val inline_branch_factor : Float_arg_helper.parsed ref val dont_write_files : bool ref -val std_include_flag : string -> string -val std_include_dir : unit -> string list +val std_include_flag : ?standard_library:string -> string -> string +val std_include_dir : ?standard_library:string -> unit -> string list val shared : bool ref val dlcode : bool ref val pic_code : bool ref