Repository: conda/conda-build

Issue:
build run_exports missing from host env with empty requirements
<!--
Thanks for opening an issue! A few things to keep in mind:

- This issue tracker is for issues with or enhancements for conda-build.

For conda issues, you should open an issue at https://github.com/conda/conda/issues
For Anaconda issues, you should open an issue at https://github.com/ContinuumIO/anaconda-issues/issues
For an issue with a particular conda-forge package, you should open an issue on the 
corresponding feedstock: https://github.com/conda-forge
-->

### Actual Behavior

conda-build doesn't install strong run_exports from the build env into the host env when the host requirements are specified, but null.

### Expected Behavior

host env should have build env's strong run_exports, as when there are actual host env requirements defined

### Steps to Reproduce

build a package with:

```yaml
build:
  script: test -f $PREFIX/lib/libgfortran${SHLIB_EXT}
requirements:
  build:
    - compiler('fortran')
  host:
```

it will fail because libgfortran (a strong run_exports dependency of `compiler('fortran')`) is not in the host env, only in the build env. Changing `host:` to `host: []` correctly injects libgfortran-ng into the host env.

I *believe* https://github.com/conda/conda-build/pull/2896 was meant to fix this, and it does work when the host requirements is a zero-length list, just not when it's defined and null.

##### Output of conda info

<!-- Between the ticks below, paste the output of 'conda info' -->

```
     active environment : None
            shell level : 0
       user config file : /Users/benjaminrk/.condarc
 populated config files : /Users/benjaminrk/conda/.condarc
                          /Users/benjaminrk/.condarc
          conda version : 4.5.4
    conda-build version : 3.10.9+12.g7dac1cba.dirty
         python version : 3.6.5.final.0
       base environment : /Users/benjaminrk/conda  (writable)
           channel URLs : https://conda.anaconda.org/conda-forge/osx-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/osx-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/free/osx-64
                          https://repo.anaconda.com/pkgs/free/noarch
                          https://repo.anaconda.com/pkgs/r/osx-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/pro/osx-64
                          https://repo.anaconda.com/pkgs/pro/noarch
          package cache : /Users/benjaminrk/conda/pkgs
                          /Users/benjaminrk/.conda/pkgs
       envs directories : /Users/benjaminrk/conda/envs
                          /Users/benjaminrk/.conda/envs
               platform : osx-64
             user-agent : conda/4.5.4 requests/2.19.1 CPython/3.6.5 Darwin/17.6.0 OSX/10.13.5
                UID:GID : 501:20
             netrc file : /Users/benjaminrk/.netrc
           offline mode : False
```


xref https://github.com/regro/cf-scripts/issues/212 and a real build that failed due to this: https://github.com/conda-forge/mpich-feedstock/pull/21



Discussion:
Yeah, your explanation is correct.  This has been tricky to get right.  I'll add your little toy recipe here as a test and try to get it fixed.

Resolving patch:
diff --git a/conda_build/render.py b/conda_build/render.py
--- a/conda_build/render.py
+++ b/conda_build/render.py
@@ -337,13 +337,17 @@ def add_upstream_pins(m, permit_unsatisfiable_variants, exclude_pattern):
         # this must come before we read upstream pins, because it will enforce things
         #      like vc version from the compiler.
         host_reqs = utils.ensure_list(m.get_value('requirements/host'))
+        # ensure host_reqs is present, so in-place modification below is actually in-place
+        requirements = m.meta.setdefault('requirements', {})
+        requirements['host'] = host_reqs
+
         if not host_reqs:
             matching_output = [out for out in m.meta.get('outputs', []) if
                                out.get('name') == m.name()]
             if matching_output:
                 requirements = utils.expand_reqs(matching_output[0].get('requirements', {}))
                 matching_output[0]['requirements'] = requirements
-                host_reqs = requirements.get('host', [])
+                host_reqs = requirements.setdefault('host', [])
         # in-place modification of above thingie
         host_reqs.extend(extra_run_specs_from_build.get('strong', []))
 


Test patch: