Repository: conda/conda-build

Issue:
Hashes mismatch during test (split packages)
For the following recipe:
```
package:
  name: test
  version: 1.0.0

outputs:
  - name: test-split1
    build:
      skip: True  # [blas_impl == 'openblas' and win]
      # conda > 4.4 might be able to use this
      requires_features:
        blas: {{ blas_impl }}
      # this is for conda 4.4 and below
      features:
        - nomkl    # [x86 and blas_impl != 'mkl']
    requirements:
      host:
        - zlib
      build:
        - {{ compiler('c') }}
        - make
    test:
      commands:
        - echo hello
```
... with conda_build_config.yaml:
```
blas_impl:
  - mkl                        # [x86 or x86_64]
  - openblas
```
The build failes with:
```
(base) [root@eb29c4d90e4d recipe]# conda build .                                                                                                                                                                   
Adding in variants from internal_defaults
INFO:conda_build.variants:Adding in variants from internal_defaults
Adding in variants from /root/conda_build_config.yaml
INFO:conda_build.variants:Adding in variants from /root/conda_build_config.yaml
Adding in variants from /tmp/recipe/conda_build_config.yaml
INFO:conda_build.variants:Adding in variants from /tmp/recipe/conda_build_config.yaml
Attempting to finalize metadata for test-split1
INFO:conda_build.metadata:Attempting to finalize metadata for test-split1
Solving environment: done
Solving environment: done
Solving environment: done
BUILD START: ['test-split1-1.0.0-h54607b7_0.tar.bz2', 'test-split1-1.0.0-nomklhce18021_0.tar.bz2']
...
Fixing permissions
updating: test-split1-1.0.0-nomklhce18021_0.tar.bz2
TEST START: /opt/conda/conda-bld/linux-64/test-split1-1.0.0-h54607b7_0.tar.bz2
Updating index at /opt/conda/conda-bld/linux-64 to make package installable with dependencies
INFO:conda_build.build:Updating index at /opt/conda/conda-bld/linux-64 to make package installable with dependencies
Updating index at /opt/conda/conda-bld/noarch to make package installable with dependencies
INFO:conda_build.build:Updating index at /opt/conda/conda-bld/noarch to make package installable with dependencies
Renaming work directory,  /opt/conda/conda-bld/test_1514452225412/work  to  /opt/conda/conda-bld/test_1514452225412/work_moved_test-split1-1.0.0-hce18021_0_linux-64
Solving environment: failed
Traceback (most recent call last):
  File "/opt/conda/lib/python3.6/site-packages/conda_build/environ.py", line 691, in get_install_actions
    actions = install_actions(prefix, index, specs, force=True)
  File "/opt/conda/lib/python3.6/site-packages/conda/common/io.py", line 415, in decorated
    return f(*args, **kwds)
  File "/opt/conda/lib/python3.6/site-packages/conda/plan.py", line 546, in install_actions
    txn = solver.solve_for_transaction(prune=prune, ignore_pinned=not pinned)
  File "/opt/conda/lib/python3.6/site-packages/conda/core/solve.py", line 504, in solve_for_transaction
    force_remove, force_reinstall)
  File "/opt/conda/lib/python3.6/site-packages/conda/core/solve.py", line 437, in solve_for_diff
    final_precs = self.solve_final_state(deps_modifier, prune, ignore_pinned, force_remove)
  File "/opt/conda/lib/python3.6/site-packages/conda/core/solve.py", line 317, in solve_final_state
    conflicting_specs = r.get_conflicting_specs(tuple(final_environment_specs))
  File "/opt/conda/lib/python3.6/site-packages/conda/resolve.py", line 690, in get_conflicting_specs
    reduced_index = self.get_reduced_index(specs)
  File "/opt/conda/lib/python3.6/site-packages/conda/resolve.py", line 254, in get_reduced_index
    specs, features = self.verify_specs(specs)
  File "/opt/conda/lib/python3.6/site-packages/conda/resolve.py", line 172, in verify_specs
    raise ResolvePackageNotFound(bad_deps)
conda.exceptions.ResolvePackageNotFound: 
  - test-split1==1.0.0=hce18021_0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/conda/bin/conda-build", line 11, in <module>
    sys.exit(main())
  File "/opt/conda/lib/python3.6/site-packages/conda_build/cli/main_build.py", line 393, in main
    execute(sys.argv[1:])
  File "/opt/conda/lib/python3.6/site-packages/conda_build/cli/main_build.py", line 384, in execute
    verify=args.verify)
  File "/opt/conda/lib/python3.6/site-packages/conda_build/api.py", line 186, in build
    need_source_download=need_source_download, config=config, variants=variants)
  File "/opt/conda/lib/python3.6/site-packages/conda_build/build.py", line 1891, in build_tree
    test(pkg, config=metadata.config)
  File "/opt/conda/lib/python3.6/site-packages/conda_build/build.py", line 1655, in test
    channel_urls=tuple(metadata.config.channel_urls))
  File "/opt/conda/lib/python3.6/site-packages/conda_build/environ.py", line 693, in get_install_actions
    raise DependencyNeedsBuildingError(exc, subdir=subdir)
conda_build.exceptions.DependencyNeedsBuildingError: Unsatisfiable dependencies for platform linux-64: {'test-split1==1.0.0=hce18021_0'}
```
`hce18021` is the part of the build string of the nomkl package, but it is being used directly?


Discussion:

Resolving patch:
diff --git a/conda_build/build.py b/conda_build/build.py
--- a/conda_build/build.py
+++ b/conda_build/build.py
@@ -980,9 +980,9 @@ def build(m, post=None, need_source_download=True, need_reparse_in_env=False, bu
                         "are already built in {0}, skipping.".format(package_locations))
                 return default_return
             else:
-                package_locations = [bldpkg_path(om) for _, om in output_metas]
+                package_locations = [bldpkg_path(om) for _, om in output_metas if not om.skip()]
         else:
-            package_locations = [bldpkg_path(om) for _, om in output_metas]
+            package_locations = [bldpkg_path(om) for _, om in output_metas if not om.skip()]
 
         print("BUILD START:", [os.path.basename(pkg) for pkg in package_locations])
 
@@ -1243,6 +1243,9 @@ def build(m, post=None, need_source_download=True, need_reparse_in_env=False, bu
                                 os.path.join(prefix_files_backup, f),
                                 symlinks=True)
             for (output_d, m) in outputs:
+                if m.skip():
+                    print(utils.get_skip_message(m))
+                    continue
                 if (top_level_meta.name() == output_d.get('name') and not (output_d.get('files') or
                                                                            output_d.get('script'))):
                     output_d['files'] = (utils.prefix_files(prefix=m.config.host_prefix) -
@@ -1452,6 +1455,9 @@ def _construct_metadata_for_test_from_package(package, config):
         else:
             config.filename_hashing = False
             hash_input = {}
+        # not actually used as a variant, since metadata will have been finalized.
+        #    This is still necessary for computing the hash correctly though
+        config.variant = hash_input
 
     log = utils.get_logger(__name__)
 
@@ -1569,7 +1575,6 @@ def test(recipedir_or_package_or_metadata, config, move_broken=True):
 
     trace = '-x ' if metadata.config.debug else ''
 
-    metadata.append_metadata_sections(hash_input, merge=False)
     metadata.config.compute_build_id(metadata.name())
 
     # Must download *after* computing build id, or else computing build id will change


Test patch:
diff --git a/tests/test-recipes/split-packages/split_packages_hash_resolution/conda_build_config.yaml b/tests/test-recipes/split-packages/split_packages_hash_resolution/conda_build_config.yaml
new file mode 100644
--- /dev/null
+++ b/tests/test-recipes/split-packages/split_packages_hash_resolution/conda_build_config.yaml
@@ -0,0 +1,3 @@
+blas_impl:
+  - mkl                        # [x86 or x86_64]
+  - openblas
diff --git a/tests/test-recipes/split-packages/split_packages_hash_resolution/meta.yaml b/tests/test-recipes/split-packages/split_packages_hash_resolution/meta.yaml
new file mode 100644
--- /dev/null
+++ b/tests/test-recipes/split-packages/split_packages_hash_resolution/meta.yaml
@@ -0,0 +1,27 @@
+package:
+  name: test
+  version: 1.0.0
+
+build:
+
+outputs:
+  - name: test-split1
+    build:
+      skip: True  # [blas_impl != 'mkl' and win]
+      # conda > 4.4 might be able to use this
+      requires_features:
+        blas: {{ blas_impl }}
+      # this is for conda 4.4 and below
+      features:
+        - nomkl    # [x86 and blas_impl != 'mkl']
+    requirements:
+      host:
+        - zlib
+      build:
+        - {{ compiler('c') }}
+        - make
+      run:
+        - nomkl    # [blas_impl != 'mkl']
+    test:
+      commands:
+        - echo hello