Skip to content
Snippets Groups Projects
Commit 3acfed62 authored by Richard W.M. Jones's avatar Richard W.M. Jones
Browse files

Add a command line tool for examining the goaljobs persistent memory.

  goaljobs-memory list

  goaljobs-memory set target_foo 1.2
parent bd08c0a8
No related branches found
No related tags found
No related merge requests found
...@@ -3,3 +3,5 @@ goaljobs.cmo : goaljobs_config.cmo goaljobs.cmi ...@@ -3,3 +3,5 @@ goaljobs.cmo : goaljobs_config.cmo goaljobs.cmi
goaljobs.cmx : goaljobs_config.cmx goaljobs.cmi goaljobs.cmx : goaljobs_config.cmx goaljobs.cmi
goaljobs_config.cmo : goaljobs_config.cmo :
goaljobs_config.cmx : goaljobs_config.cmx :
goaljobs_memory.cmo : goaljobs.cmi
goaljobs_memory.cmx : goaljobs.cmx
...@@ -26,6 +26,7 @@ Makefile ...@@ -26,6 +26,7 @@ Makefile
/goaljobs_config.ml /goaljobs_config.ml
/goaljobs.spec /goaljobs.spec
/goaljobs-*.tar.gz /goaljobs-*.tar.gz
/goaljobs-memory
/install-sh /install-sh
/libtool /libtool
/ltmain.sh /ltmain.sh
......
...@@ -25,6 +25,7 @@ EXTRA_DIST = \ ...@@ -25,6 +25,7 @@ EXTRA_DIST = \
goaljobs_config.ml.in \ goaljobs_config.ml.in \
goaljobs.ml \ goaljobs.ml \
goaljobs.mli \ goaljobs.mli \
goaljobs_memory.ml \
goaljobs.pod \ goaljobs.pod \
goaljobs-reference.pod \ goaljobs-reference.pod \
goaljobs.spec \ goaljobs.spec \
...@@ -40,9 +41,10 @@ SUBDIRS = . examples tests ...@@ -40,9 +41,10 @@ SUBDIRS = . examples tests
sources = \ sources = \
goaljobs_config.ml \ goaljobs_config.ml \
goaljobs.ml \ goaljobs.ml \
goaljobs.mli goaljobs.mli \
goaljobs_memory.ml
bin_SCRIPTS = goaljobs bin_SCRIPTS = goaljobs goaljobs-memory
# These targets are noinst because we use a custom install hook to # These targets are noinst because we use a custom install hook to
# install them, and are _SCRIPTS because automake doesn't know how to # install them, and are _SCRIPTS because automake doesn't know how to
...@@ -61,6 +63,11 @@ pa_goal.cmo: pa_goal.ml ...@@ -61,6 +63,11 @@ pa_goal.cmo: pa_goal.ml
$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -package camlp4.lib -linkpkg \ $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -package camlp4.lib -linkpkg \
-pp $(CAMLP4OF) -c $< -o $@ -pp $(CAMLP4OF) -c $< -o $@
# Standalone program for examining the goaljobs memory.
goaljobs-memory: goaljobs_config.cmx goaljobs.cmx goaljobs_memory.cmx
$(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(OCAMLOPTPACKAGES) \
$^ -linkpkg -o $@
# Install. # Install.
install-data-hook: install-data-hook:
mkdir -p $(DESTDIR)$(OCAMLLIB) mkdir -p $(DESTDIR)$(OCAMLLIB)
......
...@@ -420,6 +420,14 @@ let memory_delete key = ...@@ -420,6 +420,14 @@ let memory_delete key =
Pervasives.flush chan; Pervasives.flush chan;
) )
let memory_list () =
with_memory_locked (
fun fd ->
let chan = in_channel_of_descr fd in
let memory : (string, string) Hashtbl.t = input_value chan in
Hashtbl.fold (fun key value xs -> (key, value) :: xs) memory []
)
let published_goals = ref [] let published_goals = ref []
let publish name fn = published_goals := (name, fn) :: !published_goals let publish name fn = published_goals := (name, fn) :: !published_goals
let get_goal name = let get_goal name =
......
...@@ -265,6 +265,9 @@ val memory_get : string -> string option ...@@ -265,6 +265,9 @@ val memory_get : string -> string option
val memory_delete : string -> unit val memory_delete : string -> unit
(** Delete the [key]. If the key doesn't exist, has no effect. *) (** Delete the [key]. If the key doesn't exist, has no effect. *)
val memory_list : unit -> (string * string) list
(** Return all [(key, value)] pairs in the memory. *)
(** {2 Publishing goals} *) (** {2 Publishing goals} *)
val publish : string -> (string list -> unit) -> unit val publish : string -> (string list -> unit) -> unit
......
(* goaljobs
* Copyright (C) 2013-2014 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
open Unix
open Printf
open Goaljobs
(* Stand-alone tool to read and modify the user's goaljobs memory. *)
let usage ret =
printf " %s list\n" Sys.executable_name;
printf " %s [exists|get|delete] key\n" Sys.executable_name;
printf " %s set key value\n" Sys.executable_name;
printf "Subcommands:\n";
printf " exists - Check if key exists, exit code 0 if exists, 1 if not\n";
printf " get - Print the current value of the key\n";
printf " set - Set the key to a new value\n";
printf " delete - Delete the key\n";
printf " list - List the names and values of all keys\n";
exit ret
let () =
match Array.to_list Sys.argv with
| [] -> usage 1
| [ ("--help" | "-h" | "-?") ] -> usage 0
| [ _; "exists"; key ] ->
if memory_exists key then exit 0 else exit 1
| [ _; "get"; key ] ->
(match memory_get key with
| None ->
eprintf "%s: key '%s' not found in memory\n" Sys.executable_name key;
exit 1
| Some v -> print_endline v
)
| [ _; "set"; key; value ] ->
memory_set key value
| [ _; "delete"; key ] ->
memory_delete key
| [ _; "list" ] ->
let mem = memory_list () in
List.iter (fun (key, value) -> printf "%s\t%s\n" key value) mem
| _ -> usage 1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment