Skip to content

Commit

Permalink
Merge pull request xapi-project#12 from kc284/master
Browse files Browse the repository at this point in the history
CA-276606: Ported build from _oasis to jbuilder.
  • Loading branch information
mseri authored Dec 14, 2017
2 parents cecd1f6 + fc0653a commit ed9ceb2
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 161 deletions.
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*.swp
_build/
setup.data
setup.log
setup.bin
*.install
.merlin

*.orig
*.rej
xcp_inventory_config.ml
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
59 changes: 15 additions & 44 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
14 changes: 0 additions & 14 deletions _oasis

This file was deleted.

14 changes: 11 additions & 3 deletions configure
Original file line number Diff line number Diff line change
@@ -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 $*
26 changes: 12 additions & 14 deletions configure.ml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

let config_ml = "lib/xcp_inventory_config.ml"
let config_ml= "lib/xcp_inventory_config.ml"

(* Configure script *)
open Cmdliner
Expand All @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(jbuild_version 1)
120 changes: 59 additions & 61 deletions lib/inventory.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 ())
14 changes: 14 additions & 0 deletions lib/jbuild
Original file line number Diff line number Diff line change
@@ -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
))
))
5 changes: 0 additions & 5 deletions lib/xcp-inventory.mldylib

This file was deleted.

5 changes: 0 additions & 5 deletions lib/xcp-inventory.mllib

This file was deleted.

16 changes: 16 additions & 0 deletions xapi-inventory.opam
Original file line number Diff line number Diff line change
@@ -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"
]
Loading

0 comments on commit ed9ceb2

Please # to comment.