Repository: conda/conda-build

Issue:
Invalid assertion error: "Can't merge/copy source into subdirectory of itself"
The check in https://github.com/conda/conda-build/blob/master/conda_build/utils.py#L194 causes invalid AssertionErrors in some cases.

I have this build where the source is in `/xxx` which causes the build to fail with

```
Copying /xxx to /opt/conda/conda-bld/xxx_1479725365157/work

Traceback (most recent call last):
  File "/opt/conda/bin/conda-build", line 6, in <module>
    sys.exit(conda_build.cli.main_build.main())
  File "/opt/conda/lib/python3.4/site-packages/conda_build/cli/main_build.py", line 247, in main
    execute(sys.argv[1:])
  File "/opt/conda/lib/python3.4/site-packages/conda_build/cli/main_build.py", line 239, in execute
    already_built=None, config=config, noverify=args.no_verify)
  File "/opt/conda/lib/python3.4/site-packages/conda_build/api.py", line 77, in build
    need_source_download=need_source_download, config=config)
  File "/opt/conda/lib/python3.4/site-packages/conda_build/build.py", line 1088, in build_tree
    config=recipe_config)
  File "/opt/conda/lib/python3.4/site-packages/conda_build/build.py", line 652, in build
    config=config)
  File "/opt/conda/lib/python3.4/site-packages/conda_build/render.py", line 86, in parse_or_try_download
    source.provide(metadata.path, metadata.get_section('source'), config=config)
  File "/opt/conda/lib/python3.4/site-packages/conda_build/source.py", line 500, in provide
    copy_into(path, config.work_dir, config.timeout)
  File "/opt/conda/lib/python3.4/site-packages/conda_build/utils.py", line 95, in copy_into
    merge_tree(src, dst, symlinks, timeout=timeout, lock=lock)
  File "/opt/conda/lib/python3.4/site-packages/conda_build/utils.py", line 194, in merge_tree
    assert src not in dst, ("Can't merge/copy source into subdirectory of itself.  Please create "
AssertionError: Can't merge/copy source into subdirectory of itself.  Please create separate spaces for these things.
```

which is obviously invalid.

This check was introduced in https://github.com/conda/conda-build/commit/b7845f86b85c2dbc3010b00b93f79234bedbf2e1 .

Workarounds:

* downgrade to conda-build 2.0.1, or
* make sure that the source dir is not a substring of that target dir


Discussion:
Thanks, I will try to refine the match.

Resolving patch:
diff --git a/conda_build/utils.py b/conda_build/utils.py
--- a/conda_build/utils.py
+++ b/conda_build/utils.py
@@ -193,8 +193,10 @@ def merge_tree(src, dst, symlinks=False, timeout=90, lock=None):
     Like copytree(src, dst), but raises an error if merging the two trees
     would overwrite any files.
     """
-    assert src not in dst, ("Can't merge/copy source into subdirectory of itself.  Please create "
-                            "separate spaces for these things.")
+    dst = os.path.normpath(os.path.normcase(dst))
+    src = os.path.normpath(os.path.normcase(src))
+    assert not dst.startswith(src), ("Can't merge/copy source into subdirectory of itself.  "
+                                     "Please create separate spaces for these things.")
 
     new_files = copytree(src, dst, symlinks=symlinks, dry_run=True)
     existing = [f for f in new_files if isfile(f)]


Test patch: