Repository: conda/conda-build

Issue:
OSError when copying files in 3.7.2 on MacOS
### Actual Behavior

<!-- What actually happens? -->

Build fails with an OSError while trying to copy the license file between working directories. If I remove the license file, the build succeeds. This appears to be related to https://github.com/conda/conda-build/issues/2555

Here's the trace of the relevant error:

```
Resource usage statistics from building pyquil:
   Process count: 1
   CPU time: Sys=0:00:00.0, User=0:00:00.0
   Memory: 2.3M
   Disk usage: 2.5K
   Time elapsed: 0:00:02.1

Packaging pyquil
INFO:conda_build.build:Packaging pyquil
Packaging pyquil-1.8.0-py_0
INFO:conda_build.build:Packaging pyquil-1.8.0-py_0
number of files: 47
Fixing permissions
Traceback (most recent call last):
  File "/Users/pbronez/anaconda/lib/python3.6/site-packages/conda_build/utils.py", line 397, in _copy_with_shell_fallback
    stderr=subprocess.PIPE, stdout=subprocess.PIPE)
  File "/Users/pbronez/anaconda/lib/python3.6/subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command 'cp -a /Users/pbronez/anaconda/conda-bld/pyquil_1522257180644/work/LICENSE /Users/pbronez/anaconda/conda-bld/pyquil_1522257180644/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pla/info/LICENSE.txt' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/pbronez/anaconda/bin/conda-build", line 11, in <module>
    sys.exit(main())
  File "/Users/pbronez/anaconda/lib/python3.6/site-packages/conda_build/cli/main_build.py", line 420, in main
    execute(sys.argv[1:])
  File "/Users/pbronez/anaconda/lib/python3.6/site-packages/conda_build/cli/main_build.py", line 411, in execute
    verify=args.verify)
  File "/Users/pbronez/anaconda/lib/python3.6/site-packages/conda_build/api.py", line 199, in build
    notest=notest, need_source_download=need_source_download, variants=variants)
  File "/Users/pbronez/anaconda/lib/python3.6/site-packages/conda_build/build.py", line 2097, in build_tree
    notest=notest,
  File "/Users/pbronez/anaconda/lib/python3.6/site-packages/conda_build/build.py", line 1508, in build
    built_package = bundlers[output_d.get('type', 'conda')](output_d, m, env, stats)
  File "/Users/pbronez/anaconda/lib/python3.6/site-packages/conda_build/build.py", line 921, in bundle_conda
    output['checksums'] = create_info_files(metadata, files, prefix=metadata.config.host_prefix)
  File "/Users/pbronez/anaconda/lib/python3.6/site-packages/conda_build/build.py", line 615, in create_info_files
    copy_license(m)
  File "/Users/pbronez/anaconda/lib/python3.6/site-packages/conda_build/build.py", line 344, in copy_license
    locking=m.config.locking)
  File "/Users/pbronez/anaconda/lib/python3.6/site-packages/conda_build/utils.py", line 467, in copy_into
    _copy_with_shell_fallback(src, dst_fn)
  File "/Users/pbronez/anaconda/lib/python3.6/site-packages/conda_build/utils.py", line 400, in _copy_with_shell_fallback
    raise OSError("Failed to copy {} to {}.  Error was: {}".format(src, dst, e))
OSError: Failed to copy /Users/pbronez/anaconda/conda-bld/pyquil_1522257180644/work/LICENSE to /Users/pbronez/anaconda/conda-bld/pyquil_1522257180644/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pla/info/LICENSE.txt.  Error was: Command 'cp -a /Users/pbronez/anaconda/conda-bld/pyquil_1522257180644/work/LICENSE /Users/pbronez/anaconda/conda-bld/pyquil_1522257180644/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pla/info/LICENSE.txt' returned non-zero exit status 1.
```

The offending file is just an Apache license description. Note that it does have extended attributes:

```
-rw-r--r--@ 1 pbronez  <SNIP>    12K Mar 28 13:10 LICENSE
	user.xdg.origin.url	  72B
```

### Expected Behavior

<!-- What do you think should happen? -->

The build should succeed with a LICENSE.txt present. The license file is required for upload to conda-forge.

### Steps to Reproduce

<!-- Steps to reproduce issue. -->
#### Reproduce
grab  https://github.com/pbronez/staged-recipes/commit/238d7d076713fdda9f86bc912515ae4dca13bd06 and run `conda build recipes/pyquil/`

#### Fix

Remove LICENSE file and remove `about:license` from meta.yaml. This has been done in this commit: https://github.com/pbronez/staged-recipes/commit/ebdaf6554c0e7bd6dcc1632694322941d71345ad

Now `conda build pyquil` succeeds.

##### `Output of conda info`
<!-- Between the ticks below, paste the output of 'conda info' -->
```
     active environment : None
            shell level : 0
       user config file : /Users/pbronez/.condarc
 populated config files : /Users/pbronez/.condarc
          conda version : 4.5.0
    conda-build version : 3.7.2
         python version : 3.6.0.final.0
       base environment : /Users/pbronez/anaconda  (writable)
           channel URLs : https://conda.anaconda.org/anaconda-fusion/osx-64
                          https://conda.anaconda.org/anaconda-fusion/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
                          https://conda.anaconda.org/conda-forge/osx-64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /Users/pbronez/anaconda/pkgs
                          /Users/pbronez/.conda/pkgs
       envs directories : /Users/pbronez/anaconda/envs
                          /Users/pbronez/.conda/envs
               platform : osx-64
             user-agent : conda/4.5.0 requests/2.12.4 CPython/3.6.0 Darwin/16.7.0 OSX/10.12.6
                UID:GID : 1842615283:1201784756
             netrc file : None
           offline mode : False
```




Discussion:
Yeah, the error handling here really sucks.  We should show a much more informative message than this.
The error is because conda-build looks for that file in the source folder (aka the work dir).  You have the license file in your recipe folder.  I'm going to change it to look for it in either, but prefer the source folder if present there.

Resolving patch:
diff --git a/conda_build/build.py b/conda_build/build.py
--- a/conda_build/build.py
+++ b/conda_build/build.py
@@ -339,9 +339,16 @@ def copy_readme(m):
 def copy_license(m):
     license_file = m.get_value('about/license_file')
     if license_file:
-        utils.copy_into(join(m.config.work_dir, license_file),
-                        join(m.config.info_dir, 'LICENSE.txt'), m.config.timeout,
-                        locking=m.config.locking)
+        src_file = join(m.config.work_dir, license_file)
+        if not os.path.isfile(src_file):
+            src_file = os.path.join(m.path, license_file)
+        if os.path.isfile(src_file):
+            utils.copy_into(src_file,
+                            join(m.config.info_dir, 'LICENSE.txt'), m.config.timeout,
+                            locking=m.config.locking)
+        else:
+            raise ValueError("License file given in about/license_file does not exist in "
+                             "source root dir or in recipe root dir (with meta.yaml)")
 
 
 def copy_test_source_files(m, destination):


Test patch: