Repository: conda/conda-build

Issue:
conda convert does not produce expected results
On two platforms (Mac OSX and Linux 64 bit), `conda convert` of a built package produces tar.bz2 files with almost nothing in them. Each produced file is the proper name but is of size ~360 bytes.

```
conda convert -p all /home/ubuntu/miniconda2/conda-bld/linux-64/taxcalc-0.6.6-np110py27_2.tar.bz2 -o .
```

yields as follows:

```
ubuntu@ip-172-31-23-146:~/tmp_build/packages$ ls -l */taxcalc*
-rw-rw-r-- 1 ubuntu ubuntu 361 Sep  6 02:36 linux-32/taxcalc-0.6.6-np110py27_2.tar.bz2
-rw-rw-r-- 1 ubuntu ubuntu 360 Sep  6 02:36 linux-64/taxcalc-0.6.6-np110py27_2.tar.bz2
-rw-rw-r-- 1 ubuntu ubuntu 361 Sep  6 02:36 osx-64/taxcalc-0.6.6-np110py27_2.tar.bz2
-rw-rw-r-- 1 ubuntu ubuntu 359 Sep  6 02:36 win-32/taxcalc-0.6.6-np110py27_2.tar.bz2
-rw-rw-r-- 1 ubuntu ubuntu 361 Sep  6 02:36 win-64/taxcalc-0.6.6-np110py27_2.tar.bz2
```

```
ubuntu@ip-172-31-23-146:~/tmp_build/packages$ conda --version
conda 4.1.11
ubuntu@ip-172-31-23-146:~/tmp_build/packages$ conda-build --version
conda-build 2.0.0
```

I'm assuming you need more to debug. What do you need?



Discussion:
It looks like I can repeat this locally.  I'll see about a test and a fix ASAP.


Resolving patch:
diff --git a/conda_build/convert.py b/conda_build/convert.py
--- a/conda_build/convert.py
+++ b/conda_build/convert.py
@@ -165,18 +165,6 @@ def tar_update(source, dest, file_map, verbose=True, quiet=False):
         t.close()
 
 
-def write_info(t, info):
-    tmp_dir = tempfile.mkdtemp()
-    with open(join(tmp_dir, 'files'), 'w') as fo:
-        for m in t.getmembers():
-            fo.write('%s\n' % m.path)
-    with open(join(tmp_dir, 'index.json'), 'w') as fo:
-        json.dump(info, fo, indent=2, sort_keys=True)
-    for fn in os.listdir(tmp_dir):
-        t.add(join(tmp_dir, fn), 'info/' + fn)
-    rm_rf(tmp_dir)
-
-
 path_mapping_bat_proxy = [
     (re.compile(r'bin/(.*)(\.py)'), r'Scripts/\1.bat'),
     (re.compile(r'bin/(.*)'), r'Scripts/\1.bat'),
@@ -196,6 +184,13 @@ def write_info(t, info):
     (r'Scripts/', r'bin/'),  # Not supported right now anyway
 ]
 
+path_mapping_identity = [
+    (r'Lib/', r'Lib/'),
+    (r'lib/python{pyver}/', r'lib/python{pyver}/'),
+    (r'Scripts/', r'Scripts/'),
+    (r'bin/', 'bin/'),  # Not supported right now anyway
+]
+
 pyver_re = re.compile(r'python(?:(?:\s+[<>=]*)(\d.\d))?')
 
 
@@ -213,7 +208,7 @@ def get_pure_py_file_map(t, platform):
     elif source_type == 'win' and dest_type == 'unix':
         mapping = path_mapping_windows_unix
     else:
-        mapping = []
+        mapping = path_mapping_identity
 
     newinfo = info.copy()
     newinfo['platform'] = dest_plat
@@ -276,6 +271,8 @@ def get_pure_py_file_map(t, platform):
                 file_map[oldpath] = None
                 file_map[newpath] = newmember
                 files = files.replace(oldpath, newpath)
+            else:
+                file_map[oldpath] = member
 
         # Make Windows compatible entry-points
         batseen = set()
@@ -304,14 +301,6 @@ def get_pure_py_file_map(t, platform):
     return file_map
 
 
-path_mapping = [  # (unix, windows)
-                ('lib/python{pyver}', 'Lib'),
-                ('bin', 'Scripts')]
-
-
-pyver_re = re.compile(r'python\s+(\d.\d)')
-
-
 def conda_convert(file_path, output_dir=".", show_imports=False, platforms=None, force=False,
                   dependencies=None, verbose=False, quiet=True, dry_run=False):
     if not show_imports and platforms is None:
@@ -394,5 +383,3 @@ def conda_convert(file_path, output_dir=".", show_imports=False, platforms=None,
                 os.makedirs(output_dir)
             tar_update(t, join(output_dir, fn), file_map,
                 verbose=verbose, quiet=quiet)
-            with tarfile.open(join(output_dir, fn), 'w:bz2') as tf:
-                write_info(tf, info)


Test patch:
diff --git a/tests/test_api_convert.py b/tests/test_api_convert.py
--- a/tests/test_api_convert.py
+++ b/tests/test_api_convert.py
@@ -1,7 +1,11 @@
+import os
+
 import pytest
 
+from conda_build.conda_interface import download
 from conda_build.api import convert
 
+from .utils import testing_workdir, package_has_file, test_config
 
 def test_convert_wheel_raises():
     with pytest.raises(RuntimeError) as exc:
@@ -13,3 +17,15 @@ def test_convert_exe_raises():
     with pytest.raises(RuntimeError) as exc:
         convert("some_wheel.exe")
         assert "cannot convert:" in str(exc)
+
+
+@pytest.mark.parametrize('base_platform', ['linux', 'win', 'osx'])
+def test_convert_platform_to_others(testing_workdir, base_platform):
+    f = 'http://repo.continuum.io/pkgs/free/{}-64/itsdangerous-0.24-py27_0.tar.bz2'.format(base_platform)
+    fn = "itsdangerous-0.24-py27_0.tar.bz2"
+    download(f, fn)
+    convert(fn, platforms='all', quiet=False, verbose=True)
+    for platform in ['osx-64', 'win-64', 'win-32', 'linux-64', 'linux-32']:
+        python_folder = 'lib/python2.7' if not platform.startswith('win') else 'Lib'
+        assert package_has_file(os.path.join(platform, fn),
+                                '{}/site-packages/itsdangerous.py'.format(python_folder))