From fb7620cbed5b10b2ff343892bf0da09a6174aa76 Mon Sep 17 00:00:00 2001
From: Andre Anjos <andre.dos.anjos@gmail.com>
Date: Thu, 18 Apr 2019 09:39:23 +0200
Subject: [PATCH] Force re-indexing of locally built packages if "local"
 channel is present

---
 bob/devtools/build.py         | 20 +++++++++++++++-----
 bob/devtools/scripts/build.py |  4 ++++
 bob/devtools/scripts/ci.py    | 14 +++++++++++---
 bob/devtools/scripts/test.py  |  5 +++++
 4 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/bob/devtools/build.py b/bob/devtools/build.py
index 5b6513ef..0de25042 100644
--- a/bob/devtools/build.py
+++ b/bob/devtools/build.py
@@ -471,7 +471,7 @@ def git_clean_build(runner, verbose):
       ['--exclude=%s' % k for k in exclude_from_cleanup])
 
 
-def base_build(bootstrap, server, intranet, group, recipe_dir,
+def base_build(bootstrap, server, intranet, use_local, group, recipe_dir,
     conda_build_config, python_version, condarc_options):
   '''Builds a non-beat/non-bob software dependence that doesn't exist on defaults
 
@@ -489,6 +489,8 @@ def base_build(bootstrap, server, intranet, group, recipe_dir,
     server: The base address of the server containing our conda channels
     intranet: Boolean indicating if we should add "private"/"public" prefixes
       on the returned paths
+    use_local: If set to ``True``, search locally built packages when looking
+      for dependencies
     group: The group of packages (gitlab namespace) the package we're compiling
       is part of.  Values should match URL namespaces currently available on
       our internal webserver.  Currently, only "bob" or "beat" will work.
@@ -514,9 +516,16 @@ def base_build(bootstrap, server, intranet, group, recipe_dir,
   public_channels = bootstrap.get_channels(public=True, stable=True,
     server=server, intranet=intranet, group=group)
 
+  all_channels = ['local'] if use_local else []
+  all_channels += public_channels + ['defaults']
   logger.info('Using the following channels during (potential) build:\n  - %s',
-      '\n  - '.join(public_channels + ['defaults']))
-  condarc_options['channels'] = public_channels + ['defaults']
+      '\n  - '.join(all_channels))
+  condarc_options['channels'] = all_channels
+
+  # updates the local index to get fresh packages if required
+  if use_local:
+    prefix = get_env_directory(os.environ['CONDA_EXE'], 'base')
+    conda_build.api.update_index(os.path.join(prefix, 'conda-bld'))
 
   logger.info('Merging conda configuration files...')
   if python_version not in ('noarch', None):
@@ -642,8 +651,9 @@ if __name__ == '__main__':
     if not os.path.exists(os.path.join(recipe, 'meta.yaml')):
       # ignore - not a conda package
       continue
-    base_build(bootstrap, server, not args.internet, args.group, recipe,
-        conda_build_config, args.python_version, condarc_options)
+    base_build(bootstrap, server, not args.internet, True,
+        args.group, recipe, conda_build_config, args.python_version,
+        condarc_options)
 
   # notice this condarc typically will only contain the defaults channel - we
   # need to boost this up with more channels to get it right for this package's
diff --git a/bob/devtools/scripts/build.py b/bob/devtools/scripts/build.py
index 450d99ef..cebb03eb 100644
--- a/bob/devtools/scripts/build.py
+++ b/bob/devtools/scripts/build.py
@@ -118,6 +118,10 @@ def build(recipe_dir, python, condarc, config, no_test, append_file,
   prefix = get_env_directory(os.environ['CONDA_EXE'], 'base')
   condarc_options['croot'] = os.path.join(prefix, 'conda-bld')
 
+  # updates the local index to get fresh packages if required
+  if use_local:
+    conda_build.api.update_index(os.path.join(prefix, 'conda-bld'))
+
   conda_config = make_conda_config(config, python, append_file,
       condarc_options)
 
diff --git a/bob/devtools/scripts/ci.py b/bob/devtools/scripts/ci.py
index 35a4f31d..07308053 100644
--- a/bob/devtools/scripts/ci.py
+++ b/bob/devtools/scripts/ci.py
@@ -8,7 +8,6 @@ import shutil
 import yaml
 import click
 import pkg_resources
-import conda_build.api
 from click_plugins import with_plugins
 
 from . import bdt
@@ -315,8 +314,17 @@ def base_build(order, group, python, dry_run):
     if not os.path.exists(os.path.join(recipe, 'meta.yaml')):
       logger.info('Ignoring directory "%s" - no meta.yaml found' % recipe)
       continue
-    _build(bootstrap, SERVER, True, group, recipe, CONDA_BUILD_CONFIG, pyver,
-        condarc_options)
+    _build(
+        bootstrap=bootstrap,
+        server=SERVER,
+        intranet=True,
+        use_local=True,
+        group=group,
+        recipe_dir=recipe,
+        conda_build_config=CONDA_BUILD_CONFIG,
+        python_version=pyver,
+        condarc_options=condarc_options,
+        )
 
 
 @ci.command(epilog='''
diff --git a/bob/devtools/scripts/test.py b/bob/devtools/scripts/test.py
index f02fbb8b..d5e951fc 100644
--- a/bob/devtools/scripts/test.py
+++ b/bob/devtools/scripts/test.py
@@ -103,6 +103,11 @@ def test(package, condarc, config, append_file, server, group, private, stable,
         '\n  - '.join(all_channels))
     condarc_options['channels'] = all_channels
 
+  # updates the local index to get fresh packages if required
+  if use_local and not dry_run:
+    prefix = get_env_directory(os.environ['CONDA_EXE'], 'base')
+    conda_build.api.update_index(os.path.join(prefix, 'conda-bld'))
+
   conda_config = make_conda_config(config, None, append_file,
       condarc_options)
 
-- 
GitLab