Skip to content

Commit

Permalink
Separate common from package ml generator
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahbeckford committed Jan 30, 2023
1 parent 22b9c89 commit 582b935
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 14 deletions.
52 changes: 52 additions & 0 deletions installer/ml-generator/common_main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
open Dkml_install_runner.Error_handling.Monad_syntax
module Arg = Cmdliner.Arg
module Cmd = Cmdliner.Cmd
module Term = Cmdliner.Term

let copy_as_is file =
let content =
match Code.read file with
| Some x -> x
| None -> failwith (Fmt.str "No %s in crunched common_code.ml" file)
in
Dkml_install_runner.Error_handling.continue_or_exit
@@ Dkml_install_runner.Error_handling.map_rresult_error_to_progress
@@ Dkml_install_runner.Error_handling.continue_or_exit
@@ Dkml_install_runner.Error_handling.map_rresult_error_to_progress
@@ Bos.OS.File.with_oc (Fpath.v file)
(fun oc () ->
let fmt = Format.formatter_of_out_channel oc in
Fmt.pf fmt "%s" content;
Format.pp_print_flush fmt ();
Ok ())
()

let main () =
let components = Common_installer_generator.ocamlfind () in

let copy ~target_abi ~components filename =
let content = Option.get (Code.read filename) in
Dkml_install_runner.Error_handling.continue_or_exit
@@ Dkml_install_runner.Error_handling.map_rresult_error_to_progress
@@ Ml_of_installer_generator_lib.copy_with_templates ~target_abi ~components
~output_file:(Fpath.v filename) content
in

Dkml_install_runner.Error_handling.continue_or_exit
(let* target_abi, _fl = Dkml_install_runner.Ocaml_abi.create_v2 () in
copy_as_is "discover.ml";
copy_as_is "entry-application.manifest";
copy ~target_abi ~components "entry_assembly_manifest.ml";
return ())

let main_t = Term.(const main $ const ())

let () =
let doc =
"Writes $(b,.ml) files that are used by dune-of-installer-generator.exe"
in
exit
(Dkml_install_runner.Error_handling.catch_and_exit_on_error ~id:"878ee300"
(fun () ->
Cmd.(
eval ~catch:false (v (info "common-ml-of-installer-generator" ~doc) main_t))))
37 changes: 28 additions & 9 deletions installer/ml-generator/dune
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
(rule
(deps
(glob_files code/*.ml)
(glob_files code/*.manifest))
(target code.ml)
(action
(run ocaml-crunch -m plain -e ml -e manifest -o %{target} code/)))

(library
(name code)
(modules code))

(executable
(package dkml-install-installer)
(name main)
(public_name ml-of-installer-generator)
(public_name common-ml-of-installer-generator)
(name common_main)
(modules common_main)
(libraries
bos
cmdliner
code
common_installer_generator
dkml-install-runner
ml_of_installer_generator_lib))

(rule
(deps
(glob_files code/*.ml)
(glob_files code/*.manifest))
(target code.ml)
(action
(run ocaml-crunch -m plain -e ml -e manifest -o %{target} code/)))
(executable
(package dkml-install-installer)
(public_name package-ml-of-installer-generator)
(name package_main)
(modules package_main)
(libraries
bos
cmdliner
code
common_installer_generator
dkml-install-runner
ml_of_installer_generator_lib))
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let copy_as_is file =
let content =
match Code.read file with
| Some x -> x
| None -> failwith (Fmt.str "No %s in crunched code.ml" file)
| None -> failwith (Fmt.str "No %s in crunched package_code.ml" file)
in
Dkml_install_runner.Error_handling.continue_or_exit
@@ Dkml_install_runner.Error_handling.map_rresult_error_to_progress
Expand All @@ -34,9 +34,6 @@ let main () =

Dkml_install_runner.Error_handling.continue_or_exit
(let* target_abi, _fl = Dkml_install_runner.Ocaml_abi.create_v2 () in
copy_as_is "discover.ml";
copy_as_is "entry-application.manifest";
copy ~target_abi ~components "entry_assembly_manifest.ml";
copy ~target_abi ~components "entry_install.ml";
copy ~target_abi ~components "entry_uninstall.ml";
copy ~target_abi ~components "create_installers.ml";
Expand All @@ -56,4 +53,4 @@ let () =
(Dkml_install_runner.Error_handling.catch_and_exit_on_error ~id:"878ee300"
(fun () ->
Cmd.(
eval ~catch:false (v (info "ml-of-installer-generator" ~doc) main_t))))
eval ~catch:false (v (info "package-ml-of-installer-generator" ~doc) main_t))))

0 comments on commit 582b935

Please sign in to comment.