(* Helper functions for handling libguestfs. *) open Goaljobs open Printf open Config open Utils let package = "libguestfs" (* Helper object which stores everything about a version. *) type info = { version : string; (* The version as a normal string. *) major : int; (* Broken-out version fields. *) minor : int; release: int; is_stable : bool; (* is a stable version of libguestfs? *) branch : string; (* 'master' or 'stable-1.xx' *) package_version : string; (* package-version *) tarball : string; (* package-version.tar.gz *) python_tarball : string; (* guestfs-version.tar.gz *) urlpath : string; (* download/1.X-(stable|development)/tarball *) python_urlpath : string; (* download/python/python_tarball *) url : string; (* full download URL of tarball *) python_url : string; (* python sdist *) } let compare_versions { major = major1; minor = minor1; release = release1 } { major = major2; minor = minor2; release = release2 } = compare (major1, minor1, release1) (major2, minor2, release2) let string_of_libguestfs_version { version = version } = version (* Helper function to make a full 'info' object from a version * number. *) let vernames version = Scanf.sscanf version "%d.%d.%d" ( fun major minor release -> let is_stable = minor mod 2 = 0 in let branch = if is_stable then sprintf "stable-%d.%d" major minor else sprintf "master" in let package_version = sprintf "%s-%d.%d.%d" package major minor release in let tarball = sprintf "%s.tar.gz" package_version in let urlpath = if is_stable then sprintf "download/%d.%d-stable/%s" major minor tarball else sprintf "download/%d.%d-development/%s" major minor tarball in let url = "http://libguestfs.org/" ^ urlpath in let python_tarball = sprintf "guestfs-%d.%d.%d.tar.gz" major minor release in let python_urlpath = sprintf "download/python/" ^ python_tarball in let python_url = "http://libguestfs.org/" ^ python_urlpath in { version = version; major = major; minor = minor; release = release; is_stable = is_stable; branch = branch; package_version = package_version; tarball = tarball; python_tarball = python_tarball; urlpath = urlpath; python_urlpath = python_urlpath; url = url; python_url = python_url } ) (* For libguestfs <= 1.24, we need an old supermin 4 binary. *) let supermin = function | { major = 1; minor = i } when i <= 24 -> let home = Sys.getenv "HOME" in Some ( home // "d/supermin4/src/supermin", home // "d/supermin4/helper/supermin-helper" ) | _ -> None (* Clone or update a repo to the latest version on a branch, by force. * It is cached in name = $buildtmp/repos/- *) let git_force branch = let url = "https://github.com/libguestfs/libguestfs.git" in sh " cd %s/repos if [ ! -d %s-%s ]; then git clone %s %s-%s; fi cd %s-%s git checkout --force %s git pull # Copy or update gnulib git submodule init git submodule update " buildtmp package (quote branch) (quote url) package (quote branch) package (quote branch) (quote branch) (* Helper function to read the latest version in a repo and return * the version. *) let git_latest_version branch = let v = shout " cd %s/repos/%s-%s git describe --tags --abbrev=0 " buildtmp package (quote branch) in (* Branches <= 1.32 are tagged with "1.32.11", * branches >= 1.33 are tagged with "v1.33.11". *) let len = String.length v in let v = if len > 0 && v.[0] = 'v' then String.sub v 1 (len-1) else v in vernames v (* Get the latest commit. *) let git_latest_commit branch = shout " cd %s/repos/%s-%s git rev-parse HEAD " buildtmp package (quote branch) (* Find the latest website tarball version. Actually we use our local * CVS copy of the website rather than downloading from * http://libguestfs.org *) let website_latest_version = let rex = Str.regexp "libguestfs-\\(.*\\)\\.tar\\.gz" in fun branch -> let wdir = libguestfs_website_repo // "download" // branch in let files = Sys.readdir wdir in let files = Array.to_list files in if files = [] then None else ( let versions = filter_map ( fun name -> if not (Str.string_match rex name 0) then None else Some (vernames (Str.matched_group 1 name)) ) files in let versions = List.sort compare_versions versions in let versions = List.rev versions in Some (List.hd versions) )