[tracker-miners/tracker-miners-2.2: 5/47] build: Remove old extract rules from build tree when configuration changes



commit 00b075e4871573113d45428b9aaf3be3e29f5bbc
Author: Sam Thursfield <sam afuera me uk>
Date:   Sat May 25 12:53:43 2019 +0200

    build: Remove old extract rules from build tree when configuration changes
    
    For the functional-tests we run Tracker entirely from the source tree.
    We need to maintain a directory of .rule files for tracker-extract to
    use, and we must only have the .rule files that are enabled in the
    current build configuration. This wasn't working properly because we
    didn't remove old .rule files when reconfiguring, so disabling an
    extractor at configure-time would sometimes not work as expected.
    
    This is fixed by preparing the uninstalled rule files in a shell
    script rather than from Meson, allowing us to delete the rule files
    each time that we reconfigure.

 meson.build                                |  2 +-
 src/tracker-extract/meson.build            | 19 ++++++++++++-------
 src/tracker-extract/setup-extract-rules.sh | 29 +++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 8 deletions(-)
---
diff --git a/meson.build b/meson.build
index c83d8e12e..de68b8d5c 100644
--- a/meson.build
+++ b/meson.build
@@ -393,7 +393,7 @@ tracker_extract_rules_dir = join_paths(get_option('prefix'), get_option('datadir
 tracker_miner_services_dir = join_paths(get_option('prefix'), get_option('datadir'), 'tracker/miners')
 tracker_writeback_modules_dir = join_paths(get_option('prefix'), get_option('libdir'), 
'tracker-miners-@0@/writeback-modules'.format(tracker_api_version))
 
-tracker_uninstalled_extract_rules_dir = join_paths(meson.current_build_dir(), 'src', 'tracker-extract')
+tracker_uninstalled_extract_rules_dir = join_paths(meson.current_build_dir(), 'src', 'tracker-extract', 
'uninstalled-rules')
 tracker_uninstalled_writeback_modules_dir = join_paths(meson.current_build_dir(), 'src', 'tracker-writeback')
 
 gsettings_schema_dir = join_paths(get_option('prefix'), get_option('datadir'), 'glib-2.0', 'schemas')
diff --git a/src/tracker-extract/meson.build b/src/tracker-extract/meson.build
index 0d8966c4c..b4bb2f93a 100644
--- a/src/tracker-extract/meson.build
+++ b/src/tracker-extract/meson.build
@@ -114,6 +114,7 @@ if libgxps.found()
   modules += [['extract-xps', 'tracker-extract-xps.c', ['10-xps.rule'], [libgxps, 
tracker_miners_common_dep]]]
 endif
 
+enabled_rule_files = []
 
 foreach module : modules
   name = module[0]
@@ -130,13 +131,7 @@ foreach module : modules
 
   install_data(rules, install_dir: tracker_extract_rules_dir)
 
-  # Populate tracker_uninstalled_extract_rules_dir with the enabled .rule files.
-  foreach rule: rules
-    configure_file(
-      input: rule,
-      output: rule,
-      copy: true)
-  endforeach
+  enabled_rule_files += rules
 endforeach
 
 tracker_extract_priority_dbus = gnome.gdbus_codegen(
@@ -206,3 +201,13 @@ if install_systemd_user_services
     install: true,
     install_dir: systemd_user_services_dir)
 endif
+
+# Populate a directory inside the build tree with the extract rules that are
+# enabled in this build configuration.
+setup_extract_rules = join_paths(meson.current_source_dir(), 'setup-extract-rules.sh')
+result = run_command(setup_extract_rules, meson.current_source_dir(), tracker_uninstalled_extract_rules_dir, 
enabled_rule_files)
+if result.returncode() != 0
+    output = result.stdout().strip()
+    errortxt = result.stderr().strip()
+    error('Failed to run @0@.\n@1@\n@2@'.format(setup_extract_rules, errortxt, output))
+endif
diff --git a/src/tracker-extract/setup-extract-rules.sh b/src/tracker-extract/setup-extract-rules.sh
new file mode 100644
index 000000000..b681ab66c
--- /dev/null
+++ b/src/tracker-extract/setup-extract-rules.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+# Create a directory of enabled extract rules inside the build tree, for
+# use when running tracker-extract from the build tree.
+
+set -ex
+
+if [ "$#" -lt 2 ]; then
+    echo >&2 "Usage: $0 SOURCE_DIR TARGET_DIR [RULE1 RULE2...]"
+    exit 1;
+fi
+
+source_dir=$1
+target_dir=$2
+shift
+shift
+
+if [ ! -d ${target_dir} ]; then
+    mkdir -p ${target_dir}
+fi
+
+# Start from a clean directory, this is very important when we
+# reconfigure an existing build tree.
+rm -f ${target_dir}/*.rule
+
+while [ -n "$1" ]; do
+    rule="$1"
+    cp ${source_dir}/${rule} ${target_dir}
+    shift
+done


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]