Skip to content

Commit

Permalink
[enhance] passes: fill plugin pass stub.
Browse files Browse the repository at this point in the history
  • Loading branch information
arthuraa committed Jul 24, 2012
1 parent 0b57ade commit 7f4d822
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 7 deletions.
1 change: 1 addition & 0 deletions compiler/opa/_tags
Expand Up @@ -23,6 +23,7 @@
<opa_ResolveJsIdent.{ml,mli}>: use_libqmlcompil, use_opalib, use_qml2js
<opa_Roots.{ml,mli}>: use_libqmlcompil, use_opalib, use_opalang, use_opapasses

<pass_PluginCompilation.{ml,mli}>: use_libbsl, use_passlib, use_opalib, use_jslang
<pass_EnrichMagic.{ml,mli}>:use_libqmlcompil, use_opalang, use_qmlslicer, use_qmlpasses
<pass_InitializeBslValues.{ml,mli}>: use_libqmlcompil, use_opalang
<pass_Retyping.{ml,mli}>: use_libqmlcompil
Expand Down
99 changes: 98 additions & 1 deletion compiler/opa/pass_PluginCompilation.ml
Expand Up @@ -16,4 +16,101 @@
along with Opa. If not, see <http://www.gnu.org/licenses/>.
*)

let process () = ()
(** Generate plugin files from JS given to the opa compiler. Mostly
copied from bslregister.ml.
@author Arthur Azevedo de Amorim
*)

module BR = BslRegisterLib
module BI = BslInterface
module PH = PassHandler
module O = OpaEnv
module List = BaseList

let handle_open_out file =
try open_out_bin file
with
| Sys_error s ->
OManager.error
"@[<2>@{<bright>bslregister@}: cannot open_out @{<bright>%s@}:@\n%s@]"
file s

let handle_close_out file oc =
try close_out oc
with
| Sys_error s ->
OManager.error
"@[<2>@{<bright>bslregister@}: cannot close_out @{<bright>%s@}:@\n%s@]"
file s

let output filename pp a =
OManager.verbose "writing file @{<bright>%S@}..." filename ;
let oc = handle_open_out filename in
pp oc a ;
handle_close_out filename oc ;
()

let process env =
let plugin_name =
Filename.basename (File.chop_extension env.PH.options.O.target) in
let js_files = env.PH.options.O.client_plugin_files in
let nodejs_files = env.PH.options.O.server_plugin_files in
let modular_plugins = env.PH.options.O.modular_plugins in
let nodejs_package = plugin_name ^
BslConvention.Suffix.nodejspackage ^ ".js" in
if List.is_empty js_files && List.is_empty nodejs_files then env else
let package_version = env.PH.options.O.package_version in
let opp_dir = File.from_pattern "%.opp" env.PH.options.O.target in
if not (File.check_create_path opp_dir) then
OManager.error "cannot create plugin directory %s" opp_dir;
let plugin_file =
Filename.concat opp_dir
(plugin_name ^ BslConvention.Suffix.plugin ^ ".ml") in
let runtime_file =
Filename.concat opp_dir
(plugin_name ^ BslConvention.Suffix.mlruntime ^ ".ml") in
let package_json_file = Filename.concat opp_dir "package.json" in
let marshalplugin_file = Filename.concat opp_dir
(BslConvention.Suffix.marshalplugin ^ "." ^
BslConvention.Extension.bypass) in

let options = {
BI.
(* Use minimal options for now *)
basename = plugin_name;
bypass_plugins = [];
check_style = false;
js_files;
nodejs_files;
js_validator = None;
ml_plugin_filename = plugin_file;
ml_runtime_filename = runtime_file;
modular_plugins;
unsafe_js = true;
unsafe_opa = true;
} in

(* Ignore PP for now *)
let session = BR.create ~options in

let finalized = BR.finalize session in

(* Generate files *)
let package_desc = JsUtils.basic_package_json ~version:package_version
opp_dir nodejs_package in
begin
match
File.pp_output plugin_file Format.pp_print_string package_desc
with
| None -> ()
| Some error -> OManager.error "Couldn't write package.json: %s\n" error
end;
output marshalplugin_file BR.out_ml_marshal_plugin finalized;
output nodejs_package BR.out_nodejs_package finalized;
let out_package_json oc _ =
let package_desc = JsUtils.basic_package_json ~version:package_version
(Filename.basename opp_dir) nodejs_package in
Printf.fprintf oc "%s" package_desc in
output package_json_file out_package_json finalized;
env
3 changes: 2 additions & 1 deletion compiler/opa/pass_PluginCompilation.mli
Expand Up @@ -16,4 +16,5 @@
along with Opa. If not, see <http://www.gnu.org/licenses/>.
*)

val process : unit -> unit
val process : (OpaEnv.opa_options, 'a) PassHandler.one_env ->
(OpaEnv.opa_options, 'a) PassHandler.one_env
6 changes: 1 addition & 5 deletions compiler/opa/s3Passes.ml
Expand Up @@ -553,11 +553,7 @@ let pass_DbEngineImportation =
)

let pass_PluginCompilation =
PassHandler.make_pass
(fun e ->
let _ = Pass_PluginCompilation.process () in
e
)
PassHandler.make_pass Pass_PluginCompilation.process

let pass_BslLoading =
PassHandler.make_pass
Expand Down

0 comments on commit 7f4d822

Please sign in to comment.