summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Conrads <christoph.conrads@inria.fr>2021-09-23 09:54:02 +0200
committerGitHub <noreply@github.com>2021-09-23 09:54:02 +0200
commit45c6fe2b942573661b5075f11045932a766cf621 (patch)
tree20c4f2fc6cbcd65d07c18e9c8678a9c6b6253b63
parent56a81ec81c22219d4f0bdf2e9f4a11d384354fbe (diff)
downloadspack-45c6fe2b942573661b5075f11045932a766cf621.tar.gz
spack-45c6fe2b942573661b5075f11045932a766cf621.tar.bz2
spack-45c6fe2b942573661b5075f11045932a766cf621.tar.xz
spack-45c6fe2b942573661b5075f11045932a766cf621.zip
SQLite: make variants discoverable (#25885)
Co-authored-by: Harmen Stoppels <harmenstoppels@gmail.com>
-rw-r--r--var/spack/repos/builtin/packages/sqlite/package.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/var/spack/repos/builtin/packages/sqlite/package.py b/var/spack/repos/builtin/packages/sqlite/package.py
index 68f22494bd..57e4b78622 100644
--- a/var/spack/repos/builtin/packages/sqlite/package.py
+++ b/var/spack/repos/builtin/packages/sqlite/package.py
@@ -3,7 +3,9 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+import os
import re
+from tempfile import NamedTemporaryFile
from spack import architecture
@@ -85,6 +87,53 @@ class Sqlite(AutotoolsPackage):
match = re.match(r'(\S+) \d{4}-\d{2}-\d{2}', output)
return match.group(1) if match else None
+ @classmethod
+ def determine_variants(cls, exes, version_str):
+ all_variants = []
+
+ def call(exe, query):
+ with NamedTemporaryFile(mode='w', buffering=1) as sqlite_stdin:
+ sqlite_stdin.write(query + '\n')
+ e = Executable(exe)
+ e(fail_on_error=False,
+ input=sqlite_stdin.name,
+ output=os.devnull,
+ error=os.devnull)
+ return e.returncode
+
+ def get_variant(name, has_variant):
+ fmt = "+{:s}" if has_variant else "~{:s}"
+ return fmt.format(name)
+
+ for exe in exes:
+ variants = []
+
+ # check for fts
+ def query_fts(version):
+ return 'CREATE VIRTUAL TABLE name ' \
+ 'USING fts{:d}(sender, title, body);'.format(version)
+
+ rc_fts4 = call(exe, query_fts(4))
+ rc_fts5 = call(exe, query_fts(5))
+ variants.append(get_variant('fts', rc_fts4 == 0 and rc_fts5 == 0))
+
+ # check for functions
+ # SQL query taken from extension-functions.c usage instructions
+ query_functions = "SELECT load_extension('libsqlitefunctions');"
+ rc_functions = call(exe, query_functions)
+ variants.append(get_variant('functions', rc_functions == 0))
+
+ # check for rtree
+ query_rtree = 'CREATE VIRTUAL TABLE name USING rtree(id, x, y);'
+ rc_rtree = call(exe, query_rtree)
+ variants.append(get_variant('rtree', rc_rtree == 0))
+
+ # TODO: column_metadata
+
+ all_variants.append(''.join(variants))
+
+ return all_variants
+
def url_for_version(self, version):
full_version = list(version.version) + [0 * (4 - len(version.version))]
version_string\