aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am2
-rw-r--r--build-aux/pre-inst-env.in3
-rw-r--r--configure.ac10
-rw-r--r--src/cuirass/config.scm.in4
-rw-r--r--src/cuirass/database.scm49
-rw-r--r--src/schema.sql18
6 files changed, 56 insertions, 30 deletions
diff --git a/Makefile.am b/Makefile.am
index 85cac05..438dcdc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,6 +14,8 @@ nodist_pkgmodule_DATA = \
src/cuirass/config.scm \
src/cuirass/config.go
+dist_pkgdata_DATA = src/schema.sql
+
TEST_EXTENSIONS = .scm .sh
AM_TESTS_ENVIRONMENT = \
env GUILE_AUTO_COMPILE='0' \
diff --git a/build-aux/pre-inst-env.in b/build-aux/pre-inst-env.in
index b92a1a1..e8d9487 100644
--- a/build-aux/pre-inst-env.in
+++ b/build-aux/pre-inst-env.in
@@ -24,6 +24,9 @@ GUILE_LOAD_COMPILED_PATH="$abs_top_builddir/src${GUILE_LOAD_COMPILED_PATH:+:}$GU
GUILE_LOAD_PATH="$abs_top_builddir/src:$abs_top_srcdir/src${GUILE_LOAD_PATH:+:}$GUILE_LOAD_PATH"
export GUILE_LOAD_COMPILED_PATH GUILE_LOAD_PATH
+CUIRASS_DATADIR="$abs_top_srcdir/src"
+export CUIRASS_DATADIR
+
PATH="$abs_top_builddir/bin:$PATH"
export PATH
diff --git a/configure.ac b/configure.ac
index 945260c..61f5d0a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -8,11 +8,13 @@ AM_SILENT_RULES([yes]) # enables silent rules by default
AC_CANONICAL_HOST
-# Prepare a version of $localstatedir that does not contain references to
-# shell variables.
+# Prepare a version of installation directories that does not contain
+# references to shell variables.
expanded_prefix="`eval echo $prefix | sed -e "s|NONE|/usr/local|g"`"
-expanded_localstatedir="`eval echo $localstatedir | sed -e "s|NONE|$expanded_prefix|g"`"
-AC_SUBST([expanded_localstatedir])
+AC_SUBST([expanded_datadir],
+ [`eval echo $datadir | sed -e "s|NONE|$expanded_prefix|g"`])
+AC_SUBST([expanded_localstatedir],
+ [`eval echo $localstatedir | sed -e "s|NONE|$expanded_prefix|g"`])
PKG_CHECK_MODULES([GUILE], [guile-2.0 >= 2.0.7])
AC_PATH_PROG([GUILE], [guile])
diff --git a/src/cuirass/config.scm.in b/src/cuirass/config.scm.in
index 361ccd8..5619168 100644
--- a/src/cuirass/config.scm.in
+++ b/src/cuirass/config.scm.in
@@ -47,6 +47,10 @@
;; Define to the version of this package.
"@PACKAGE_VERSION@")
+(define-public %datadir
+ ;; Define to DATADIR without reference to '${prefix}'.
+ "@expanded_datadir@")
+
(define-public %localstatedir
;; Define to LOCALSTATEDIR without reference to '${prefix}'.
"@expanded_localstatedir@")
diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index 88e282c..72c5fd8 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -1,5 +1,4 @@
-;;;; database.scm - store evaluation and build results
-;;;
+;;; database.scm -- store evaluation and build results
;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
;;;
;;; This file is part of Cuirass.
@@ -18,8 +17,8 @@
;;; along with Cuirass. If not, see <http://www.gnu.org/licenses/>.
(define-module (cuirass database)
- #:use-module (cuirass base)
#:use-module (cuirass config)
+ #:use-module (ice-9 rdelim)
#:use-module (sqlite3)
#:export (;; Procedures.
db-init
@@ -29,6 +28,7 @@
db-get-evaluation
db-delete-evaluation
db-add-build-log
+ read-sql-file
;; Parameters.
%package-database
;; Macros.
@@ -44,6 +44,24 @@
;; Define to the database file name of this package.
(make-parameter (string-append %localstatedir "/" %package ".db")))
+(define %package-schema-file
+ ;; Define to the database schema file of this package.
+ (make-parameter (string-append (or (getenv "CUIRASS_DATADIR")
+ (string-append %datadir "/" %package))
+ "/schema.sql")))
+
+(define (read-sql-file file-name)
+ "Return a list of string containing SQL instructions from FILE-NAME."
+ (call-with-input-file file-name
+ (λ (port)
+ (let loop ((insts '()))
+ (let ((inst (read-delimited ";" port 'concat)))
+ (if (or (eof-object? inst)
+ ;; Don't cons the spaces after the last instructions.
+ (string-every char-whitespace? inst))
+ (reverse! insts)
+ (loop (cons inst insts))))))))
+
(define (db-init)
"Open the database to store and read jobs and builds informations. Return a
database object."
@@ -53,29 +71,8 @@ database object."
(delete-file db-name))
(let ((db (sqlite-open db-name (logior SQLITE_OPEN_CREATE
SQLITE_OPEN_READWRITE))))
- (for-each (λ (sql) (sqlite-exec db sql))
- '("PRAGMA foreign_keys=OFF;"
- "BEGIN TRANSACTION;"
- "COMMIT;"
- "
-CREATE TABLE job_spec (
- name text not null,
- url text not null,
- branch text not null,
- file text not null,
- proc text not null,
- arguments text not null,
- primary key (name)
-);"
- "
-CREATE TABLE build (
- id integer primary key autoincrement not null,
- job_spec text not null,
- drv text not null,
- log text,
- output text
- -- foreign key (job_spec) references job_spec(name)
-);"))
+ (for-each (λ (sql) (false-if-exception (sqlite-exec db sql)))
+ (read-sql-file (%package-schema-file)))
db)))
(define (db-open)
diff --git a/src/schema.sql b/src/schema.sql
new file mode 100644
index 0000000..9786064
--- /dev/null
+++ b/src/schema.sql
@@ -0,0 +1,18 @@
+create table job_spec (
+ name text not null,
+ url text not null,
+ branch text not null,
+ file text not null,
+ proc text not null,
+ arguments text not null,
+ primary key (name)
+);
+
+create table build (
+ id integer primary key autoincrement not null,
+ job_spec text not null,
+ drv text not null,
+ log text,
+ output text
+ -- foreign key (job_spec) references job_spec(name)
+);