Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file dkml_package_console_setup.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162openBosopenDkml_install_registeropenDkml_install_api(* Load dkml-install-api module so that Dynlink access control
does not prohibit plugins (components) from loading it by
raising a Dynlink.Unavailable_unit error.
Confer:
https://ocaml.org/api/Dynlink.html#1_Accesscontrol "set_allowed_units" *)let(_:stringlist)=Default_component_config.install_depends_on(* Create command line options for dkml-install-{user,admin}-runner.exe *)(* Entry point of CLI.
Logging is configured just before this function is called through Cmdliner
Term evaluation of `log_config`. If you don't see log statement, make
sure the log statements are created inside (or after) `setup ...`. *)letsetuptarget_abiprogram_versionorganizationprogram_nameprogram_assetsprogram_infopackage_args:unit=letopenDkml_install_runner.Error_handling.Monad_syntaxin(* deconstruct *)let(prefix_opt,component_selector,static_files_source,staging_files_source,log_config)=(package_args.Dkml_package_console_common.prefix_opt,package_args.component_selector,package_args.static_files_source,package_args.staging_files_source,package_args.log_config)inLogs.debug(funl->l"Starting setup");(* Get all the available components. Logging has already been setup. *)letreg=Component_registry.get()in(* Only install what was specified, if specified *)letselector=Dkml_install_runner.Cmdliner_runner.to_selectorcomponent_selectorinletinstall_sequence_fl:unitForward_progress.t=letopenDkml_package_console_commoninletmap_string_error_to_progress,map_rresult_error_to_progress=(Dkml_install_runner.Error_handling.map_string_error_to_progress,Dkml_install_runner.Error_handling.map_rresult_error_to_progress)inlet*prefix,_fl=Dkml_package_console_common.get_user_installation_prefix~program_name~target_abi~prefix_optinletargs=Dkml_install_runner.Cmdliner_runner.common_runner_args~log_config~prefix~staging_files_sourceinlet*archivedir,_fl=Dkml_install_runner.Cmdliner_runner.enduser_archive_dir()inletexe_cmds=Cmd.vFpath.(to_string(archivedir/"bin"/s))inletspawn_admin_if_needed()=letopenDkml_package_console_commoninlet*needs,_fl=needs_install_admin~reg~target_abi~selector~log_config~prefix~staging_files_sourceinlet*ec,fl=elevated_cmd~target_abi~staging_files_sourceCmd.(exe_cmd"dkml-install-admin-runner.exe"%"install-adminall"%%args)inifneedsthenspawnecelseForward_progress.return((),fl)in(* Validate *)Component_registry.validatereg;(* Diagnostics *)let*(_:unitlist),_fl=Component_registry.install_evalreg~selector~fl:Dkml_install_runner.Error_handling.runner_fatal_log~f:(funcfg->letmoduleCfg=(valcfg:Component_config)inLogs.debug(funm->m"Will install component %s"Cfg.component_name);return())in(* The uninstaller may or may not be embedded. *)letuninstall_exe=Fpath.(archivedir/"bin"/"dkml-package-uninstall.exe")inlet*is_uninstall_embedded,_fl=map_rresult_error_to_progress(Bos.OS.File.existsuninstall_exe)inlet*(),_fl=ifis_uninstall_embeddedthen(* Copy uninstaller into <prefix> *)let*(),_fl=map_string_error_to_progress(Diskuvbox.copy_file~err:box_err~src:uninstall_exe~dst:Fpath.(prefix/"uninstall.exe")())in(* Write uninstaller into Windows registry *)let*(),_fl=Windows_registry.write_program_entry~installation_prefix:prefix~organization~program_name~program_assets~program_version~program_infoinreturn()elsereturn()in(* Run admin-runner.exe commands *)let*(),_fl=spawn_admin_if_needed()in(* Copy <static>/<component> into <prefix>, if present *)let*(_:unitlist),_fl=Component_registry.install_evalreg~selector~fl:Dkml_install_runner.Error_handling.runner_fatal_log~f:(funcfg->letopenDkml_install_runner.Error_handling.Monad_syntaxinletmoduleCfg=(valcfg:Component_config)inletstatic_dir_fp=Dkml_install_runner.Path_location.absdir_static_files~component_name:Cfg.component_namestatic_files_sourceinlet*exists,_fl=Dkml_install_runner.Error_handling.map_msg_error_to_progress@@OS.File.existsstatic_dir_fpinlet+()=ifexiststhenmap_string_error_to_progress(Diskuvbox.copy_dir~err:box_err~src:static_dir_fp~dst:prefix())elsereturn()in())in(* Run user-runner.exe *)let*(_:unitlist),fl=Component_registry.install_evalreg~selector~fl:Dkml_install_runner.Error_handling.runner_fatal_log~f:(funcfg->letmoduleCfg=(valcfg:Component_config)inDkml_package_console_common.spawnCmd.(exe_cmd"dkml-install-user-runner.exe"%("install-user-"^Cfg.component_name)%%args))inForward_progress.return((),fl)inmatchForward_progress.catch_exceptions~id:"7a222f5c"Dkml_install_runner.Error_handling.runner_fatal_loginstall_sequencewith|Forward_progress.Completed|Continue_progress((),_)->Logs.debug(funl->l"Finished setup");()|Halted_progressec->Logs.debug(funl->l"Finished setup in error");exit(Forward_progress.Exit_code.to_int_exitcodeec)