From 0296d022e125cd7eef4a79011b88f180104d2948 Mon Sep 17 00:00:00 2001 From: Damien Doligez Date: Fri, 16 Jan 2015 22:45:06 +0000 Subject: [PATCH] PR#6081: ocaml should add script's directory to search path, not current directory git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@15779 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02 --- Changes | 2 ++ driver/compmisc.ml | 6 +++--- driver/compmisc.mli | 2 +- toplevel/opttoploop.ml | 11 +++++++++-- toplevel/toploop.ml | 11 +++++++++-- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Changes b/Changes index 27771cc4c..53354413a 100644 --- a/Changes +++ b/Changes @@ -61,6 +61,8 @@ Bug fixes: - PR#5887: move the byterun/*.h headers to byterun/caml/*.h to avoid header name clashes (Jérôme Vouillon and Adrien Nader and Peter Zotov) +- PR#6081: ocaml should add script's directory to search path, not current directory + (Thomas Leonard and Damien Doligez) - PR#6560: Wrong failure message for {Int32,Int64,NativeInt}.of_string (Maxime Dénès and Gabriel Scherer) - PR#6648: show_module should indicate its elision diff --git a/driver/compmisc.ml b/driver/compmisc.ml index a2bc4b83a..608683bbc 100644 --- a/driver/compmisc.ml +++ b/driver/compmisc.ml @@ -13,12 +13,12 @@ open Compenv (* Initialize the search path. - The current directory is always searched first, + [dir] is always searched first (default: the current directory), then the directories specified with the -I option (in command-line order), then the standard library directory (unless the -nostdlib option is given). *) -let init_path native = +let init_path ?(dir="") native = let dirs = if !Clflags.use_threads then "+threads" :: !Clflags.include_dirs else if !Clflags.use_vmthreads && not native then @@ -30,7 +30,7 @@ let init_path native = in let exp_dirs = List.map (Misc.expand_directory Config.standard_library) dirs in - Config.load_path := "" :: + Config.load_path := dir :: List.rev_append exp_dirs (Clflags.std_include_dir ()); Env.reset_cache () diff --git a/driver/compmisc.mli b/driver/compmisc.mli index 032e9fe4a..3087d544d 100644 --- a/driver/compmisc.mli +++ b/driver/compmisc.mli @@ -10,5 +10,5 @@ (* *) (***********************************************************************) -val init_path : bool -> unit +val init_path : ?dir:string -> bool -> unit val initial_env : unit -> Env.t diff --git a/toplevel/opttoploop.ml b/toplevel/opttoploop.ml index d21860a87..709012978 100644 --- a/toplevel/opttoploop.ml +++ b/toplevel/opttoploop.ml @@ -451,7 +451,14 @@ let run_script ppf name args = Array.blit args 0 Sys.argv 0 len; Obj.truncate (Obj.repr Sys.argv) len; Arg.current := 0; - Compmisc.init_path true; + Compmisc.init_path ~dir:(Filename.dirname name) true; + (* Note: would use [Filename.abspath] here, if we had it. *) toplevel_env := Compmisc.initial_env(); Sys.interactive := false; - use_silently ppf name + let explicit_name = + (* Prevent use_silently from searching in the path. *) + if Filename.is_implicit name + then Filename.concat Filename.current_dir_name name + else name + in + use_silently ppf explicit_name diff --git a/toplevel/toploop.ml b/toplevel/toploop.ml index eea10004c..72ddba25d 100644 --- a/toplevel/toploop.ml +++ b/toplevel/toploop.ml @@ -471,7 +471,14 @@ let run_script ppf name args = Array.blit args 0 Sys.argv 0 len; Obj.truncate (Obj.repr Sys.argv) len; Arg.current := 0; - Compmisc.init_path false; + Compmisc.init_path ~dir:(Filename.dirname name) true; + (* Note: would use [Filename.abspath] here, if we had it. *) toplevel_env := Compmisc.initial_env(); Sys.interactive := false; - use_silently ppf name + let explicit_name = + (* Prevent use_silently from searching in the path. *) + if Filename.is_implicit name + then Filename.concat Filename.current_dir_name name + else name + in + use_silently ppf explicit_name