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 urlpath : string; (* download/1.X-(stable|development)/tarball *)
23 url : string; (* full download URL of tarball *)
26 let compare_versions { major = major1; minor = minor1; release = release1 }
27 { major = major2; minor = minor2; release = release2 } =
28 compare (major1, minor1, release1) (major2, minor2, release2)
30 let string_of_libguestfs_version { version = version } = version
32 (* Helper function to make a full 'info' object from a version
35 let vernames version =
36 Scanf.sscanf version "%d.%d.%d" (
37 fun major minor release ->
38 let is_stable = minor mod 2 = 0 in
41 sprintf "stable-%d.%d" major minor
44 let package_version = sprintf "%s-%d.%d.%d" package major minor release in
45 let tarball = sprintf "%s.tar.gz" package_version in
48 sprintf "download/%d.%d-stable/%s" major minor tarball
50 sprintf "download/%d.%d-development/%s" major minor tarball in
51 let url = "http://libguestfs.org/" ^ urlpath in
53 major = major; minor = minor; release = release;
54 is_stable = is_stable;
56 package_version = package_version;
62 (* Clone or update a repo to the latest version on a branch, by force.
63 * It is cached in name = $buildtmp/repos/<package>-<branch>
65 let git_force branch =
66 let url = "https://github.com/libguestfs/libguestfs.git" in
69 if [ ! -d %s-%s ]; then git clone %s %s-%s; fi
71 git checkout --force %s
73 # Copy or update gnulib
77 package (quote branch) (quote url) package (quote branch)
78 package (quote branch)
81 (* Helper function to read the latest version in a repo and return
84 let git_latest_version branch =
87 git describe --tags --abbrev=0
88 " buildtmp package (quote branch) in
91 (* Get the latest commit. *)
92 let git_latest_commit branch =
96 " buildtmp package (quote branch)
98 (* Find the latest website tarball version. Actually we use our local
99 * CVS copy of the website rather than downloading from
100 * http://libguestfs.org
102 let website_latest_version =
103 let rex = Str.regexp "libguestfs-\\(.*\\)\\.tar\\.gz" in
105 let wdir = libguestfs_website_repo // "download" // branch in
106 let files = Sys.readdir wdir in
107 let files = Array.to_list files in
108 if files = [] then None
110 let versions = filter_map (
112 if not (Str.string_match rex name 0) then None
113 else Some (vernames (Str.matched_group 1 name))
115 let versions = List.sort compare_versions versions in
116 let versions = List.rev versions in
117 Some (List.hd versions)