Skip to content

Commit

Permalink
bugfix: No use Str since needs escaped strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahbeckford committed Nov 22, 2023
1 parent 5abb468 commit 6988698
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions package/console/create/installer_archive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@
open Bos
open Dkml_install_runner.Error_handling.Monad_syntax

let build_bundle_sh ~installer_basename_with_direction_and_ver ~buildhost_abi
~archive_dir =
let template = Option.get (Shell_scripts.read "bundle.sh") in
let archive_dir = Fpath.to_string archive_dir in
let replace_placeholder exact_match repl s =
let open Astring.String in
concat ~sep:repl (cuts ~empty:true ~sep:exact_match s)
in
let translate s =
s
|> replace_placeholder "__PLACEHOLDER_BASENAME__"
installer_basename_with_direction_and_ver
|> replace_placeholder "__PLACEHOLDER_BUILDHOST_ABI__" buildhost_abi
|> replace_placeholder "__PLACEHOLDER_ARCHIVE_DIR__" archive_dir
in
translate template

let generate ~(install_direction : Dkml_install_register.install_direction)
~archive_dir ~target_dir ~abi_selector ~program_name ~program_version =
let abi_name =
Expand All @@ -32,22 +49,12 @@ let generate ~(install_direction : Dkml_install_register.install_direction)
let buildhost_abi =
Dkml_install_api.Context.Abi_v2.to_canonical_string buildhost_abi'
in
let translate s =
Str.(
s
|> global_replace
(regexp_string "__PLACEHOLDER_BASENAME__")
installer_basename_with_direction_and_ver
|> global_replace
(regexp_string "__PLACEHOLDER_BUILDHOST_ABI__")
buildhost_abi
|> global_replace
(regexp_string "__PLACEHOLDER_ARCHIVE_DIR__")
(Fpath.to_string archive_dir))
let bundle_sh =
build_bundle_sh ~installer_basename_with_direction_and_ver ~buildhost_abi
~archive_dir
in
Logs.info (fun l ->
l "Generating script %a that can produce %s.tar.gz (etc.) archives"
Fpath.pp installer_create_sh installer_basename_with_direction_and_ver);
Dkml_install_runner.Error_handling.map_rresult_error_to_progress
(OS.File.write ~mode:0o750 installer_create_sh
(translate (Option.get (Shell_scripts.read "bundle.sh"))))
(OS.File.write ~mode:0o750 installer_create_sh bundle_sh)

0 comments on commit 6988698

Please sign in to comment.