Skip to content

Commit

Permalink
Update the installation test for enable-relative
Browse files Browse the repository at this point in the history
  • Loading branch information
dra27 committed Sep 25, 2024
1 parent 9be9df2 commit 6e500a1
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
10 changes: 6 additions & 4 deletions driver/compmisc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions driver/compmisc.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down
129 changes: 95 additions & 34 deletions tools/test_install.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 <bindir> <libdir> [<library1> ...]\n";
if Array.length Sys.argv < 4 then begin
Printf.eprintf
"Usage: test_install <bindir> <libdir> <yes|no> [<library1> ...]\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)
4 changes: 2 additions & 2 deletions utils/ccomp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion utils/ccomp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions utils/clflags.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down
4 changes: 2 additions & 2 deletions utils/clflags.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6e500a1

Please sign in to comment.