diff --git a/.gitignore b/.gitignore index ab9beacbf23..a2da242d6a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ -*.swp _build/ -setup.data -setup.log -setup.bin +*.install +.merlin + +*.orig +*.rej +xcp_inventory_config.ml diff --git a/.travis.yml b/.travis.yml index 5aac240607a..056afaf1ef4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,10 @@ install: wget https://raw.githubusercontent.com/ocaml/ocaml-travisci-skeleton/ma script: bash -ex .travis-opam.sh sudo: true env: - - OCAML_VERSION=4.02 PACKAGE=xapi-inventory EXTRA_REMOTES=git://github.com/xapi-project/opam-repo-dev + global: + - OCAML_VERSION=4.04 + - PACKAGE=xapi-inventory + - PINS="xcp-inventory:. xapi-inventory:." + matrix: + - BASE_REMOTE=git://github.com/xapi-project/xs-opam + - EXTRA_REMOTES=git://github.com/xapi-project/xs-opam diff --git a/Makefile b/Makefile index 2706492cc76..6c6ffd8076b 100644 --- a/Makefile +++ b/Makefile @@ -1,51 +1,22 @@ -.PHONY: all clean install build distclean -all: build doc +.PHONY: build clean release test reindent install uninstall -NAME=xcp-inventory -J=4 +build: + jbuilder build @install --dev -export OCAMLRUNPARAM=b - -setup.ml: - oasis setup - -setup.bin: setup.ml lib/xcp_inventory_config.ml - @ocamlopt.opt -o $@ $< || ocamlopt -o $@ $< || ocamlc -o $@ $< - @rm -f setup.cmx setup.cmi setup.o setup.cmo - -setup.data: setup.bin - @./setup.bin -configure --enable-tests - -build: setup.data setup.bin - @./setup.bin -build -j $(J) - -doc: setup.data setup.bin - @./setup.bin -doc -j $(J) - -install: setup.bin - @./setup.bin -install - -uninstall: - @ocamlfind remove $(NAME) || true - -test: setup.bin build - @./setup.bin -test +clean: + jbuilder clean -reinstall: setup.bin - @ocamlfind remove $(NAME) || true - @./setup.bin -reinstall +release: + jbuilder build @install -clean: - @ocamlbuild -clean - @rm -f setup.data setup.log setup.bin +test: + jbuilder runtest --no-buffer -lib/xcp_inventory_config.ml: - @echo "You need to run configure first" - @exit 1 +reindent: + git ls-files '*.ml*' | xargs ocp-indent --syntax cstruct -i -real-configure: configure.ml - ocamlfind ocamlc -linkpkg -package findlib,cmdliner -o real-configure configure.ml - @rm -f configure.cm* +#requires odoc +doc: + jbuilder build @doc -distclean: clean - rm -f lib/xcp_inventory_config.ml +.DEFAULT_GOAL := release diff --git a/_oasis b/_oasis deleted file mode 100644 index f5e8bfa8188..00000000000 --- a/_oasis +++ /dev/null @@ -1,14 +0,0 @@ -OASISFormat: 0.3 -Name: xcp-inventory -Version: 1.0.2 -Synopsis: XCP inventory library -Authors: Various -License: LGPL-2.1 with OCaml linking exception -Plugins: META (0.3) -BuildTools: ocamlbuild - -Library "xcp-inventory" - CompiledObject: best - Modules: Inventory, Xcp_inventory_config - Path: lib - BuildDepends: uuidm, stdext, threads diff --git a/configure b/configure index d0c55f1df7d..52ff42ee68d 100755 --- a/configure +++ b/configure @@ -1,4 +1,12 @@ -#!/bin/sh +#!/bin/bash -make real-configure -./real-configure $* +D=$(mktemp -d /tmp/configure.XXXXX) +function cleanup { + cd / + rm -rf $D +} +trap cleanup EXIT + +cp configure.ml $D +(cd $D; ocamlfind ocamlc -linkpkg -package findlib,cmdliner -o configure configure.ml) +$D/configure $* diff --git a/configure.ml b/configure.ml old mode 100755 new mode 100644 index 9d9c71840f6..2c26d46edd2 --- a/configure.ml +++ b/configure.ml @@ -1,5 +1,5 @@ -let config_ml = "lib/xcp_inventory_config.ml" +let config_ml= "lib/xcp_inventory_config.ml" (* Configure script *) open Cmdliner @@ -10,7 +10,7 @@ let default_inventory = let info = let doc = "Configures a package" in - Term.info "configure" ~version:"0.1" ~doc + Term.info "configure" ~version:"0.1" ~doc let output_file filename lines = let oc = open_out filename in @@ -19,21 +19,19 @@ let output_file filename lines = close_out oc let configure inventory = - Printf.printf "Configuring with default_inventory=%s\n" inventory; - - (* Write config.ml *) - let lines = - [ "(* Warning - this file is autogenerated by the configure script *)"; - "(* Do not edit *)"; - Printf.sprintf "let default_inventory=\"%s\"" inventory; + let lines = + [ + "default_inventory", inventory; ] in - output_file config_ml lines + print_endline "Configuring with:"; + lines |> List.map (fun (x,y) -> Printf.sprintf "\t%s=%s" x y) |> List.iter print_endline; + lines |> List.map (fun (x,y) -> Printf.sprintf "let %s=\"%s\"" x y) |> output_file config_ml let configure_t = Term.(pure configure $ default_inventory) -let () = - match - Term.eval (configure_t, info) +let () = + match + Term.eval (configure_t, info) with - | `Error _ -> exit 1 + | `Error _ -> exit 1 | _ -> exit 0 diff --git a/jbuild b/jbuild new file mode 100644 index 00000000000..5e0ae1705b2 --- /dev/null +++ b/jbuild @@ -0,0 +1 @@ +(jbuild_version 1) diff --git a/lib/inventory.ml b/lib/inventory.ml index 64f5c8be36d..c6dc1697b6e 100644 --- a/lib/inventory.ml +++ b/lib/inventory.ml @@ -13,10 +13,8 @@ *) (* Code to parse the XenSource inventory file *) -open Stdext -open Pervasiveext -open Xstringext -open Threadext +open Xapi_stdext_unix +open Xapi_stdext_threads.Threadext let inventory_filename = ref Xcp_inventory_config.default_inventory @@ -42,81 +40,81 @@ let inventory = Hashtbl.create 10 let inventory_m = Mutex.create () (* Compute the minimum necessary inventory file contents *) -let minimum_default_entries () = - let host_uuid = Uuidm.to_string (Uuidm.create `V4) in - let dom0_uuid = Uuidm.to_string (Uuidm.create `V4) in - [ - _installation_uuid, host_uuid; - _control_domain_uuid, dom0_uuid; - _management_interface, ""; - _management_address_type, "IPv4"; - _build_number, "0" - ] +let minimum_default_entries () = + let host_uuid = Uuidm.to_string (Uuidm.create `V4) in + let dom0_uuid = Uuidm.to_string (Uuidm.create `V4) in + [ + _installation_uuid, host_uuid; + _control_domain_uuid, dom0_uuid; + _management_interface, ""; + _management_address_type, "IPv4"; + _build_number, "0" + ] (* trim any quotes off the ends *) let strip_quotes v = - if String.length v >= 2 - && v.[0] = '\'' - && v.[String.length v - 1] = '\'' - then String.sub v 1 (String.length v - 2) - else v + if String.length v >= 2 + && v.[0] = '\'' + && v.[String.length v - 1] = '\'' + then String.sub v 1 (String.length v - 2) + else v let parse_inventory_entry line = - match String.split ~limit:2 '=' line with - | [k; v] -> - (* trim whitespace *) - Some (k, strip_quotes ++ String.strip String.isspace $ v) - | _ -> None + match Astring.String.cuts ~empty:false ~sep:"=" line with + | [k; v] -> + (* trim whitespace *) + Some (k, v |> strip_quotes |> String.trim) + | _ -> None -let string_of_table h = - let lines = List.fold_left (fun acc (k, v) -> - Printf.sprintf "%s='%s'\n" k v :: acc) [] h in - String.concat "" lines +let string_of_table h = + let lines = List.fold_left (fun acc (k, v) -> + Printf.sprintf "%s='%s'\n" k v :: acc) [] h in + String.concat "" lines let read_inventory_contents () = - if not (Sys.file_exists !inventory_filename) then begin - Unixext.write_string_to_file !inventory_filename ( - string_of_table (minimum_default_entries ())) - end; - (* Perhaps we should blank the old inventory before we read the new one? - What is the desired behaviour? *) - Unixext.file_lines_iter (fun line -> - match parse_inventory_entry line with - | Some (k, v) -> Hashtbl.add inventory k v - | None -> ()) - !inventory_filename; - loaded_inventory := true + if not (Sys.file_exists !inventory_filename) then begin + Unixext.write_string_to_file !inventory_filename ( + string_of_table (minimum_default_entries ())) + end; + (* Perhaps we should blank the old inventory before we read the new one? + What is the desired behaviour? *) + Unixext.file_lines_iter (fun line -> + match parse_inventory_entry line with + | Some (k, v) -> Hashtbl.add inventory k v + | None -> ()) + !inventory_filename; + loaded_inventory := true let read_inventory () = Mutex.execute inventory_m read_inventory_contents let reread_inventory () = Mutex.execute inventory_m (fun () -> - Hashtbl.clear inventory; - read_inventory_contents ()) + Hashtbl.clear inventory; + read_inventory_contents ()) exception Missing_inventory_key of string let lookup ?default key = - Mutex.execute inventory_m (fun () -> - (if not (!loaded_inventory) then read_inventory_contents ()); - if (Hashtbl.mem inventory key) - then - Hashtbl.find inventory key - else - match default with - | None -> raise (Missing_inventory_key key) - | Some v -> v) + Mutex.execute inventory_m (fun () -> + (if not (!loaded_inventory) then read_inventory_contents ()); + if (Hashtbl.mem inventory key) + then + Hashtbl.find inventory key + else + match default with + | None -> raise (Missing_inventory_key key) + | Some v -> v) let flush_to_disk_locked () = - let h = Hashtbl.fold (fun k v acc -> (k, v) :: acc) inventory [] in - Unixext.write_string_to_file !inventory_filename (string_of_table h) + let h = Hashtbl.fold (fun k v acc -> (k, v) :: acc) inventory [] in + Unixext.write_string_to_file !inventory_filename (string_of_table h) let update key value = Mutex.execute inventory_m (fun () -> - Hashtbl.clear inventory; - read_inventory_contents (); - Hashtbl.replace inventory key value; - flush_to_disk_locked ()) + Hashtbl.clear inventory; + read_inventory_contents (); + Hashtbl.replace inventory key value; + flush_to_disk_locked ()) let remove key = Mutex.execute inventory_m (fun () -> - Hashtbl.clear inventory; - read_inventory_contents (); - Hashtbl.remove inventory key; - flush_to_disk_locked ()) + Hashtbl.clear inventory; + read_inventory_contents (); + Hashtbl.remove inventory key; + flush_to_disk_locked ()) diff --git a/lib/jbuild b/lib/jbuild new file mode 100644 index 00000000000..6c3d373c403 --- /dev/null +++ b/lib/jbuild @@ -0,0 +1,14 @@ +(jbuild_version 1) + +(library ( + (name inventory) + (public_name xcp-inventory) + (wrapped false) + (libraries ( + uuidm + astring + xapi-stdext-unix + xapi-stdext-threads + threads + )) +)) diff --git a/lib/xcp-inventory.mldylib b/lib/xcp-inventory.mldylib deleted file mode 100644 index 88a85e8a119..00000000000 --- a/lib/xcp-inventory.mldylib +++ /dev/null @@ -1,5 +0,0 @@ -# OASIS_START -# DO NOT EDIT (digest: 95a1c971a85ff73690cb8621533dc11c) -Inventory -Xcp_inventory_config -# OASIS_STOP diff --git a/lib/xcp-inventory.mllib b/lib/xcp-inventory.mllib deleted file mode 100644 index 88a85e8a119..00000000000 --- a/lib/xcp-inventory.mllib +++ /dev/null @@ -1,5 +0,0 @@ -# OASIS_START -# DO NOT EDIT (digest: 95a1c971a85ff73690cb8621533dc11c) -Inventory -Xcp_inventory_config -# OASIS_STOP diff --git a/xapi-inventory.opam b/xapi-inventory.opam new file mode 100644 index 00000000000..12139ca1736 --- /dev/null +++ b/xapi-inventory.opam @@ -0,0 +1,16 @@ +opam-version: "1.2" +name: "xapi-inventory" +maintainer: "xen-api@lists.xen.org" +authors: "xen-api@lists.xen.org" +homepage: "https://github.com/xapi-project/xcp-inventory" +bug-reports: "https://github.com/xapi-project/xcp-inventory/issues" +dev-repo: "git://github.com/xapi-project/xcp-inventory.git" +tags: [ "org:xapi-project" ] +build: [ + ["./configure" "--default_inventory=%{prefix}%/etc"] + [ "jbuilder" "build" "-p" name "-j" jobs ] +] +build-test: [[ "jbuilder" "runtest" "-p" name "-j" jobs ]] +depends: [ + "xcp-inventory" +] diff --git a/opam b/xcp-inventory.opam similarity index 68% rename from opam rename to xcp-inventory.opam index 2845c850f09..da50d93d469 100644 --- a/opam +++ b/xcp-inventory.opam @@ -1,4 +1,5 @@ opam-version: "1.2" +name: "xcp-inventory" maintainer: "xen-api@lists.xen.org" authors: "xen-api@lists.xen.org" homepage: "https://github.com/xapi-project/xcp-inventory" @@ -7,20 +8,16 @@ dev-repo: "git://github.com/xapi-project/xcp-inventory.git" tags: [ "org:xapi-project" ] build: [ ["./configure" "--default_inventory=%{prefix}%/etc"] - [make] -] -install: [ - [make "install"] -] -remove: [ - [make "uninstall"] + [ "jbuilder" "build" "-p" name "-j" jobs ] ] +build-test: [[ "jbuilder" "runtest" "-p" name "-j" jobs ]] depends: [ "ocamlfind" {build} - "oasis" {build} - "ocamlbuild" {build} + "jbuilder" {build} "base-threads" - "xapi-stdext" + "astring" + "xapi-stdext-unix" + "xapi-stdext-threads" "cmdliner" "uuidm" ]