Skip to content

Commit

Permalink
[fix] plugins: Install and searching
Browse files Browse the repository at this point in the history
	- Install all necessary files
	- Don't install unless files
	- Don't put absolute path on BslLoading object files
	- Search plugins on all compiler paths (especially install dir)
  • Loading branch information
BourgerieQuentin committed Oct 28, 2011
1 parent d7352df commit 8371716
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 16 deletions.
8 changes: 2 additions & 6 deletions Makefile
Expand Up @@ -86,12 +86,8 @@ endef
define install-plugin
@printf "Installing into $(STDLIB_DIR)/$*.opp^[[K\r"
@mkdir -p "$(STDLIB_DIR)/$*.opp"
@$(INSTALL) $(BUILD_DIR)/$*.opp/*.cmi "$(STDLIB_DIR)/$*.opp/";
@$(INSTALL) $(BUILD_DIR)/$*.opp/*.cmx "$(STDLIB_DIR)/$*.opp/";
@if [ -d "$(BUILD_DIR)/$*.opp/plugins/$*/" ]; then \
mkdir -p "$(STDLIB_DIR)/$*.opp/plugins/$*/" ; \
$(INSTALL) $(BUILD_DIR)/$*.opp/plugins/$*/*.js "$(STDLIB_DIR)/$*.opp/plugins/$*/" ; \
fi
@$(INSTALL) $(BUILD_DIR)/$*.opp/*.bypass "$(STDLIB_DIR)/$*.opp/";
@$(INSTALL) $(BUILD_DIR)/$*.opp/*MLRuntime.* "$(STDLIB_DIR)/$*.opp/";
endef


Expand Down
2 changes: 2 additions & 0 deletions compilerlib/objectFiles.ml
Expand Up @@ -1754,6 +1754,8 @@ let stdlib_package_names name =

let stdlib_packages (package_name,_pos) = stdlib_package_names package_name

let get_paths () = !extrapaths

module Arg =
struct
module Arg = Base.Arg
Expand Down
5 changes: 5 additions & 0 deletions compilerlib/objectFiles.mli
Expand Up @@ -88,6 +88,11 @@ val get_compilation_directory_or_current_dir : unit -> filename
*)
val set_extrapaths : no_stdlib:bool -> filename list -> unit

(**
Get all paths where the compiler should search its objects
*)
val get_paths : unit -> filename list

(**
Set plugins version, from the loaded plugins
*)
Expand Down
51 changes: 41 additions & 10 deletions opa/pass_BslLoading.ml
Expand Up @@ -221,17 +221,51 @@ let upgrade_options plugins options =
extrapath ;
}

let resolve_entry search_path entry =
let { S.plugin_name = basename ; extralib ; extrapath ; bypass } = entry in
match Filename.is_relative extrapath with
| false -> entry
| true ->
(* Searching plugin in extra path... *)
let candidates = List.filter_map
(fun p ->
let fullname = Filename.concat p extrapath in
#<If:BSL_LOADING>
OManager.verbose "Seraching %s on %s => %s : %b" extrapath p fullname (File.is_directory fullname);
#<End>;
if File.is_directory fullname then Some fullname else None
) search_path in
let aux extrapath =
OManager.verbose "Select %s" extrapath;
{S.plugin_name = basename; extralib; extrapath;
bypass = Filename.concat extrapath (Filename.basename bypass)} in
match candidates with
| [] -> entry
| [extrapath] -> aux extrapath
| extrapath::_ as places ->
OManager.warning ~wclass:WarningClass.bsl_loading
"@\nThe plugin @{<bright>%S@} is found in several places :\n(%s).@\nI will use @{<bright>%S@}"
basename
(String.concat "; " places)
extrapath ;
aux extrapath

let process
~options
~code
=
(* Pass *)
let plugins = options.O.bypass_plugin in
let back_end = options.O.back_end in
let js_back_end = options.O.js_back_end in
let cwd = Sys.getcwd () in
let search_path = cwd :: ObjectFiles.get_paths () in

(* Separated compilation: loading *)
let () =
let iter (package_name, _) entries =
let iter_entry entry =
let { S.plugin_name = basename ; extralib ; extrapath ; bypass } = entry in
let { S.plugin_name = basename ; extralib ; extrapath ; bypass } = resolve_entry search_path entry in
if not (Hashtbl.mem already_seen_plugin basename)
then (
BslLib.declare_visibility package_name basename ;
Expand All @@ -247,12 +281,6 @@ let process
in
let separation = Separation.create () in

(* Pass *)
let plugins = options.O.bypass_plugin in
let extrapath = options.O.extrapath in
let back_end = options.O.back_end in
let js_back_end = options.O.js_back_end in

let commandline = FilePos.nopos "command line" in
let plugins = List.map (fun p -> (p, commandline)) plugins in

Expand Down Expand Up @@ -307,8 +335,6 @@ let process
BslLib.declare_visibility package_name OpabslgenPlugin.Self.basename ;

(* Search additional plug-ins.*)
let cwd = Sys.getcwd () in
let search_path = cwd :: extrapath in
List.iter (
fun (bypass_plugin, pos) ->
(* the bypass_plugin is containing the extension opp *)
Expand Down Expand Up @@ -356,7 +382,8 @@ let process
let () =
if not (File.is_directory filename)
then
OManager.error "%a@\nI/O error: cannot find @{<bright>%S@}" FilePos.pp pos filename
OManager.error "%a@\nI/O error: cannot find @{<bright>%S@} on %s" FilePos.pp pos filename
(String.concat "; " search_path);
in

let inclusion = BslConvention.inclusion ~cwd filename in
Expand All @@ -366,6 +393,10 @@ let process
Hashtbl.add extralib_plugin basename extralib ;
Hashtbl.add extrapath_plugin basename extrapath ;
BslDynlink.load_bypass_plugin (BslDynlink.MarshalPlugin plugin) ;
let inclusion = BslConvention.inclusion ~cwd:"" bypass_plugin in
let extralib = inclusion.BslConvention.extralib in
let extrapath = inclusion.BslConvention.extrapath in
let plugin = inclusion.BslConvention.plugin in
Separation.add separation (S.make basename extralib extrapath plugin) ;
)
) plugins ;
Expand Down

0 comments on commit 8371716

Please sign in to comment.