1 (* Helper functions for handling libguestfs. *)
10 let package = "libguestfs"
12 (* Helper object which stores everything about a version. *)
14 version : string; (* The version as a normal string. *)
15 major : int; (* Broken-out version fields. *)
18 is_stable : bool; (* is a stable version of libguestfs? *)
19 branch : string; (* 'master' or 'stable-1.xx' *)
20 package_version : string; (* package-version *)
21 tarball : string; (* package-version.tar.gz *)
22 python_tarball : string; (* guestfs-version.tar.gz *)
23 urlpath : string; (* libguestfs-download/1.X-(stable|development)/tarball *)
24 python_urlpath : string; (* libguestfs-download/python/python_tarball *)
25 url : string; (* full download URL of tarball *)
26 python_url : string; (* python sdist *)
29 let compare_versions { major = major1; minor = minor1; release = release1 }
30 { major = major2; minor = minor2; release = release2 } =
31 compare (major1, minor1, release1) (major2, minor2, release2)
33 let string_of_libguestfs_version { version = version } = version
35 (* Helper function to make a full 'info' object from a version
38 let vernames version =
39 Scanf.sscanf version "%d.%d.%d" (
40 fun major minor release ->
41 let is_stable = minor mod 2 = 0 in
44 sprintf "stable-%d.%d" major minor
47 let package_version = sprintf "%s-%d.%d.%d" package major minor release in
48 let tarball = sprintf "%s.tar.gz" package_version in
51 sprintf "%d.%d-stable/%s" major minor tarball
53 sprintf "%d.%d-development/%s" major minor tarball in
54 let url = "http://download.libguestfs.org/" ^ urlpath in
56 sprintf "guestfs-%d.%d.%d.tar.gz" major minor release in
57 let python_urlpath = sprintf "python/" ^ python_tarball in
58 let python_url = "http://download.libguestfs.org/" ^ python_urlpath in
61 major = major; minor = minor; release = release;
62 is_stable = is_stable;
64 package_version = package_version;
66 python_tarball = python_tarball;
68 python_urlpath = python_urlpath;
70 python_url = python_url }
73 (* For libguestfs <= 1.24, we need an old supermin 4 binary. *)
74 let supermin = function
75 | { major = 1; minor = i } when i <= 24 ->
76 let home = Sys.getenv "HOME" in
77 Some ( home // "d/supermin4/src/supermin",
78 home // "d/supermin4/helper/supermin-helper" )
81 (* Clone or update a repo to the latest version on a branch, by force.
82 * It is cached in name = $buildtmp/repos/<package>-<branch>
84 let git_force branch =
85 let url = "https://github.com/libguestfs/libguestfs.git" in
88 if [ ! -d %s-%s ]; then git clone %s %s-%s; fi
90 git checkout --force %s
92 # Copy or update gnulib
96 package (quote branch) (quote url) package (quote branch)
97 package (quote branch)
100 (* Helper function to read the latest version in a repo and return
103 let git_latest_version branch =
106 git describe --tags --abbrev=0
107 " buildtmp package (quote branch) in
108 (* Branches <= 1.32 are tagged with "1.32.11",
109 * branches >= 1.33 are tagged with "v1.33.11".
111 let len = String.length v in
113 if len > 0 && v.[0] = 'v' then
114 String.sub v 1 (len-1)
119 (* Get the latest commit. *)
120 let git_latest_commit branch =
124 " buildtmp package (quote branch)
126 (* Find the latest website tarball version. Actually we use our local
127 * CVS copy of the website rather than downloading from
128 * http://libguestfs.org
130 let website_latest_version =
131 let rex = Str.regexp "libguestfs-\\(.*\\)\\.tar\\.gz" in
133 let wdir = libguestfs_download_repo // branch in
134 let files = Sys.readdir wdir in
135 let files = Array.to_list files in
136 if files = [] then None
138 let versions = filter_map (
140 if not (Str.string_match rex name 0) then None
141 else Some (vernames (Str.matched_group 1 name))
143 let versions = List.sort compare_versions versions in
144 let versions = List.rev versions in
145 Some (List.hd versions)