Repository: conda/conda-build

Issue:
On Windows: conda-build >=3 includes broken Scripts/activate.bat,deactivate.bat
When I build this empty package with conda-build=3.0.8:
```
package:
  name: scratch
  version: '0'

build:
  number: 0
  script:
    - DIR %PREFIX%\Scripts    
```
I see this unexpected content in the package:
```
-rw-rw-rw- 0/0              48 2017-08-01 15:45 info/hash_input.json
-rw-rw-rw- 0/0             118 2017-08-01 15:45 info/files
-rw-rw-rw- 0/0             207 2017-08-01 15:45 info/index.json
-rw-rw-rw- 0/0            1225 2017-08-01 15:45 info/paths.json
-rw-rw-rw- 0/0            2542 2017-08-01 15:45 info/about.json
-rw-rw-rw- 0/0               0 2017-08-01 15:45 info/hash_input_files
-rw-rw-rw- 0/0               0 2017-08-01 15:45 info/git
-rwxrwxrwx 0/0              78 2017-08-01 15:45 Scripts/conda.bat
-rwxrwxrwx 0/0              81 2017-08-01 15:45 Scripts/activate.bat
-rwxrwxrwx 0/0              83 2017-08-01 15:45 Scripts/deactivate.bat
-rw-rw-rw- 0/0              86 2017-08-01 15:45 Scripts/conda
-rw-rw-rw- 0/0              92 2017-08-01 15:45 Scripts/activate
-rw-rw-rw- 0/0              94 2017-08-01 15:45 Scripts/deactivate
-rw-rw-rw- 0/0             146 2017-08-01 15:20 info/recipe/meta.yaml.template
-rw-rw-rw- 0/0             191 2017-08-01 15:45 info/recipe/conda_build_config.yaml
-rw-rw-rw- 0/0             368 2017-08-01 15:45 info/recipe/meta.yaml
```

The included activate.bat etc all have the root prefix hardcoded into them. If the package is installed on a machine with the root prefix elsewhere, it breaks the environment. 

Reverting to conda-build 2.1.17 fixes the problem. 









Discussion:
Definitely a bug.  Thanks for reporting.

Resolving patch:
diff --git a/conda_build/environ.py b/conda_build/environ.py
--- a/conda_build/environ.py
+++ b/conda_build/environ.py
@@ -852,20 +852,13 @@ def create_env(prefix, specs_or_actions, env, config, subdir, clear_cache=True,
                     else:
                         log.error("Failed to create env, max retries exceeded.")
                         raise
-    # We must not symlink conda across different platforms when cross-compiling.
-    #  On second thought, I think we must, because activating the host env does
-    #     the symlink for us anyway, and when activate does it, we end up with
-    #     conda symlinks in every package. =()
-    # if os.path.basename(prefix) == '_build_env' or not is_cross:
-
-    # Hack, do not SYMLINK_CONDA when we're building conda.
-    if not any(include in ('bin/deactivate', 'Scripts/deactivate.bat')
-               for include in always_include_files):
-        if utils.on_win:
-            shell = "cmd.exe"
-        else:
-            shell = "bash"
-            symlink_conda(prefix, sys.prefix, shell)
+    # Symlinking conda is critical here to make sure that activate scripts are not
+    #    accidentally included in packages.
+    if utils.on_win:
+        shell = "cmd.exe"
+    else:
+        shell = "bash"
+    symlink_conda(prefix, sys.prefix, shell)
 
 
 def clean_pkg_cache(dist, config):
diff --git a/conda_build/metadata.py b/conda_build/metadata.py
--- a/conda_build/metadata.py
+++ b/conda_build/metadata.py
@@ -585,7 +585,7 @@ def get_output_dicts_from_metadata(metadata):
             outputs.append(output_dict_from_top_level_meta(metadata))
     for out in outputs:
         if (metadata.name() == out.get('name', '') and not (out.get('files') or
-                                                        out.get('script'))):
+                                                            out.get('script'))):
             out['requirements'] = out.get('requirements', metadata.meta.get('requirements', {}))
             out['noarch_python'] = out.get('noarch_python',
                                             metadata.get_value('build/noarch_python'))


Test patch:
diff --git a/tests/test-recipes/metadata/_activate_scripts_not_included/meta.yaml b/tests/test-recipes/metadata/_activate_scripts_not_included/meta.yaml
new file mode 100644
--- /dev/null
+++ b/tests/test-recipes/metadata/_activate_scripts_not_included/meta.yaml
@@ -0,0 +1,10 @@
+package:
+  name: scratch
+  version: 0
+
+build:
+  script: echo weee
+
+requirements:
+  build:
+    - python
diff --git a/tests/test_cli.py b/tests/test_cli.py
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -514,3 +514,16 @@ def test_package_test(testing_workdir, testing_metadata):
     output = api.build(testing_workdir, config=testing_metadata.config, notest=True)[0]
     args = ['-t', output]
     main_build.execute(args)
+
+
+@pytest.mark.serial
+def test_activate_scripts_not_included(testing_workdir):
+    recipe = os.path.join(metadata_dir, '_activate_scripts_not_included')
+    args = ['--no-anaconda-upload', '--croot', testing_workdir, recipe]
+    main_build.execute(args)
+    out = api.get_output_file_paths(recipe, croot=testing_workdir)[0]
+    for f in ('bin/activate', 'bin/deactivate', 'bin/conda',
+              'Scripts/activate.bat', 'Scripts/deactivate.bat', 'Scripts/conda.bat',
+              'Scripts/activate.exe', 'Scripts/deactivate.exe', 'Scripts/conda.exe',
+              'Scripts/activate', 'Scripts/deactivate', 'Scripts/conda'):
+        assert not package_has_file(out, f)