Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a version selector (option, in config file), to use for MSI that … #21

Merged
merged 2 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ Configuration
binary-path, binary
These are the same as their respective arguments.

wix_version, version
The version to use to generate the MSI, in a dot separated number
format.

embedded
A list of files paths to include in the installation directory.
Each element in this list should be a list of two elements: the
Expand Down
8 changes: 7 additions & 1 deletion src/file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ let conf_default = OpamFilename.of_string "opam-wix.conf"

module Syntax = struct
let internal = "conf"
let format_version = OpamVersion.of_string "0.1"
let format_version = OpamVersion.of_string "0.2"
type images = { ico: string option; dlg: string option; ban: string option }
type t = {
c_version: OpamVersion.t;
c_images: images;
c_binary_path: string option;
c_binary: string option;
c_wix_version: Wix.Version.t option;
c_embedded : (string * string) list;
c_envvar: (string * string) list;
}
Expand All @@ -36,6 +37,7 @@ module Syntax = struct
};
c_binary_path = None;
c_binary = None;
c_wix_version = None;
c_embedded = [];
c_envvar = [];
}
Expand Down Expand Up @@ -63,6 +65,10 @@ module Syntax = struct
"binary", OpamPp.ppacc_opt
(fun binary t -> { t with c_binary = Some binary }) (fun t -> t.c_binary)
OpamFormat.V.string;
"wix-version", OpamPp.ppacc_opt
(fun c_wix_version t -> { t with c_wix_version = Some c_wix_version })
(fun t -> t.c_wix_version)
(OpamFormat.V.string -| OpamPp.of_module "wix_version" (module Wix.Version));
"embedded", OpamPp.ppacc
(fun file t -> { t with c_embedded = file }) (fun t -> t.c_embedded)
(OpamFormat.V.map_list ~depth:2
Expand Down
1 change: 1 addition & 0 deletions src/file.mli
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module Conf: sig
c_images: images; (* Images files that are treated not as other embedded files *)
c_binary_path: string option; (* Path to binary to install *)
c_binary: string option; (* Binary name to install *)
c_wix_version: Wix.Version.t option; (* Wix compatible version to use for install *)
c_embedded : (string * string) list; (* Files/directories to embed in installation directory *)
c_envvar: (string * string) list; (* Environement variables to set in Windows Terminal on installation *)
}
Expand Down
60 changes: 52 additions & 8 deletions src/opamWixMain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type config = {
package : OpamPackage.Name.t;
path : filename option;
binary: string option;
wix_version: Wix.Version.t option;
output_dir : dirname;
wix_path : string;
package_guid: string option;
Expand Down Expand Up @@ -54,6 +55,14 @@ end
module Args = struct
open Arg

let wix_version_conv =
let parse str =
try `Ok (Wix.Version.of_string str)
with Failure s -> `Error s
in
let print ppf wxv = Format.pp_print_string ppf (Wix.Version.to_string wxv) in
parse, print

module Section = struct
let package_arg = "PACKAGE ARGUMENT"
let bin_args = "BINARY ARGUMENT"
Expand All @@ -75,6 +84,10 @@ module Args = struct
value & opt (some string) None & info ["binary";"b"] ~docs:Section.bin_args ~docv:"NAME" ~doc:
"The binary name to handle. Specified package should contain the binary with the same name."

let wix_version =
value & opt (some wix_version_conv) None & info ["with-version"] ~docv:"VERSION"
~doc:"The version to use for the installer, in an msi format, i.e. numbers and dots, [0-9.]+"

let output_dir =
value & opt OpamArg.dirname (OpamFilename.Dir.of_string ".") & info ["o";"output"] ~docv:"DIR" ~doc:
"The output directory where bundle will be stored"
Expand Down Expand Up @@ -106,10 +119,10 @@ module Args = struct
value & flag & info ["keep-wxs"] ~doc:"Keep Wix source files."

let term =
let apply conf package path binary output_dir wix_path package_guid icon_file dlg_bmp ban_bmp keep_wxs =
{ conf; package; path; binary; output_dir; wix_path; package_guid; icon_file; dlg_bmp; ban_bmp; keep_wxs }
let apply conf package path binary wix_version output_dir wix_path package_guid icon_file dlg_bmp ban_bmp keep_wxs =
{ conf; package; path; binary; wix_version; output_dir; wix_path; package_guid; icon_file; dlg_bmp; ban_bmp; keep_wxs }
in
Term.(const apply $ conffile $ package $ path $ binary $ output_dir $ wix_path $ package_guid $ icon_file $
Term.(const apply $ conffile $ package $ path $ binary $ wix_version $ output_dir $ wix_path $ package_guid $ icon_file $
dlg_bmp $ ban_bmp $ keep_wxs)

end
Expand Down Expand Up @@ -171,6 +184,7 @@ let normalize_conf env conf file =
{
conf with
binary = merge_opt conf.binary file.c_binary;
wix_version = merge_opt conf.wix_version file.c_wix_version;
path = merge_opt conf.path
(Option.map (resolve_path env (module File_impl)) file.c_binary_path);
icon_file = merge_opt conf.icon_file
Expand Down Expand Up @@ -201,6 +215,39 @@ let create_bundle cli =
(OpamConsole.colorise `bold (OpamPackage.Name.to_string conf.package))
(OpamConsole.colorise `bold ("opam install " ^ (OpamPackage.Name.to_string conf.package)))
in
let package_version =
match conf.wix_version with
| Some v -> v
| None ->
let pkg_version =
OpamPackage.Version.to_string (OpamPackage.version package)
in
try Wix.Version.of_string pkg_version
with Failure _ ->
(OpamConsole.warning
"Package version %s contains characters not accepted by MSI."
(OpamConsole.colorise `underline pkg_version);
let use = "use config file to set it or option --with-version" in
let version =
let n =
OpamStd.String.find_from (function '0'..'9' | '.' -> false | _ -> true)
pkg_version 0
in
if n = 0 then
OpamConsole.error_and_exit `Not_found
"No version can be retrieved from '%s', %s."
pkg_version use
else
String.sub pkg_version 0 n
in
OpamConsole.msg
"It must be only dot separated numbers. You can %s.\n" use;
if
OpamConsole.confirm "Do you want to use simplified version %s?"
(OpamConsole.colorise `underline version)
then version
else OpamStd.Sys.exit_because `Aborted)
in
let opam = OpamSwitchState.opam st package in
let bin_path = OpamPath.Switch.bin gt.root st.switch st.switch_config in
let changes =
Expand Down Expand Up @@ -333,11 +380,7 @@ let create_bundle cli =
Filename.basename @@ OpamFilename.Dir.to_string bundle_dir
let package_name =
OpamPackage.Name.to_string (OpamPackage.name package)
let package_version =
let version = OpamPackage.Version.to_string (OpamPackage.version package) in
match String.index_opt version '~' with
| None -> version
| Some i -> String.sub version 0 i
let package_version = package_version
let description =
(OpamFile.OPAM.synopsis opam)
++ (OpamFile.OPAM.descr_body opam)
Expand Down Expand Up @@ -535,6 +578,7 @@ let create_bundle cli =
`I ("$(i,opamwix-version)","The version of the config file. The current version is $(b,0.1).");
`I ("$(i,ico, bng, ban)","These are the same as their respective arguments.");
`I ("$(i,binary-path, binary)","These are the same as their respective arguments.");
`I ("$(i,wix_version)","The version to use to generate the MSI, in a dot separated number format.");
`I ("$(i,embedded)", "A list of files or directories paths to include in the installation directory. \
Each element in this list should be a list of two elements: the first being the destination \
basename (the name of the file in the installation directory), and the second being the \
Expand Down
14 changes: 14 additions & 0 deletions src/wix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ type component_group = string

type directory_ref = string

module Version = struct
type t = string
let to_string s = s
let of_string s =
String.iter (function
| '0'..'9' | '.' -> ()
| c ->
failwith
(Printf.sprintf "Invalid character '%c' in WIX version %S" c s))
s;
s
end


let xml_declaration = {
version = "1.0";
encoding = Some "windows-1252";
Expand Down
7 changes: 7 additions & 0 deletions src/wix.mli
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ type component_group = string
(** Directory id reference *)
type directory_ref = string

(** Version in the form [0-9.]+, i.e dot separated numbers *)
module Version: sig
type t = string
val to_string : t -> string
val of_string : string -> t
end

(** Information module used to generated main wxs document. *)
module type INFO = sig
(** Path to the bundle containing all required files. Every relative file path will be concatenated to this path *)
Expand Down
43 changes: 43 additions & 0 deletions tests/basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,46 @@ Testing config file that embeds directory and file and set environment variables
<UIRef />
</Product>
</Wix>

================== Test 6 ====================
Version testing
$ mkdir bar
$ cp compile bar/compile
$ cat > bar/bar-with-plus.opam << EOF
> opam-version: "2.0"
> version: "0.1+23"
> name: "bar-with-plus"
> install: [ "cp" "compile" "%{bin}%/%{name}%" ]
> EOF
$ cat > bar/bar-beg-alpha << EOF
> opam-version: "2.0"
> version: "v012"
> name: "bar-with-plus"
> install: [ "cp" "compile" "%{bin}%/%{name}%" ]
> EOF
$ cat > bar/bar-only-alpha.opam << EOF
> opam-version: "2.0"
> version: "aversion"
> name: "bar-with-plus"
> install: [ "cp" "compile" "%{bin}%/%{name}%" ]
> EOF
$ opam pin ./bar -y
$ opam-wix --wix-path=$WIX_PATH bar-with-plus
$ opam-wix --wix-path=$WIX_PATH bar-with-plus -y
$ opam-wix --wix-path=$WIX_PATH bar-beg-alpha
$ opam-wix --wix-path=$WIX_PATH bar-only-alpha
$ opam-wix --wix-path=$WIX_PATH bar-only-alpha --with-version 4.2
$ cat > conf << EOF
> opamwix-version: "0.1"
> wix_version: "3.2+3"
> EOF
$ opam-wix --wix-path=$WIX_PATH --conf conf bar-only-alpha
$ cat > conf << EOF
> opamwix-version: "0.1"
> wix_version: "3.2"
> EOF
$ opam-wix --wix-path=$WIX_PATH --conf conf bar-only-alpha