We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
--output reports wrong folder for noarch packages
In linux-64 packages build with the noarch  flag end up in the appropriate directory, but the --output function does not return the correct path.  


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `conda_build/render.py`
Content:
```
1 # (c) Continuum Analytics, Inc. / http://continuum.io
2 # All Rights Reserved
3 #
4 # conda is distributed under the terms of the BSD 3-clause license.
5 # Consult LICENSE.txt or http://opensource.org/licenses/BSD-3-Clause.
6 
7 from __future__ import absolute_import, division, print_function
8 
9 from locale import getpreferredencoding
10 import os
11 from os.path import isdir, isfile, abspath
12 import subprocess
13 import sys
14 import tarfile
15 import tempfile
16 
17 import yaml
18 
19 from .conda_interface import PY3
20 
21 from conda_build import exceptions, utils
22 from conda_build.metadata import MetaData
23 import conda_build.source as source
24 from conda_build.completers import all_versions, conda_version
25 from conda_build.utils import rm_rf
26 
27 
28 def set_language_env_vars(args, parser, config, execute=None):
29     """Given args passed into conda command, set language env vars"""
30     for lang in all_versions:
31         versions = getattr(args, lang)
32         if not versions:
33             continue
34         if versions == ['all']:
35             if all_versions[lang]:
36                 versions = all_versions[lang]
37             else:
38                 parser.error("'all' is not supported for --%s" % lang)
39         if len(versions) > 1:
40             for ver in versions[:]:
41                 setattr(args, lang, [str(ver)])
42                 if execute:
43                     execute(args, parser, config)
44                 # This is necessary to make all combinations build.
45                 setattr(args, lang, versions)
46             return
47         else:
48             version = versions[0]
49             if lang in ('python', 'numpy'):
50                 version = int(version.replace('.', ''))
51             setattr(config, conda_version[lang], version)
52         if not len(str(version)) in (2, 3) and lang in ['python', 'numpy']:
53             if all_versions[lang]:
54                 raise RuntimeError("%s must be major.minor, like %s, not %s" %
55                     (conda_version[lang], all_versions[lang][-1] / 10, version))
56             else:
57                 raise RuntimeError("%s must be major.minor, not %s" %
58                     (conda_version[lang], version))
59 
60     # Using --python, --numpy etc. is equivalent to using CONDA_PY, CONDA_NPY, etc.
61     # Auto-set those env variables
62     for var in conda_version.values():
63         if hasattr(config, var) and getattr(config, var):
64             # Set the env variable.
65             os.environ[var] = str(getattr(config, var))
66 
67 
68 def bldpkg_path(m, config):
69     '''
70     Returns path to built package's tarball given its ``Metadata``.
71     '''
72     return os.path.join(config.bldpkgs_dir, '%s.tar.bz2' % m.dist())
73 
74 
75 def parse_or_try_download(metadata, no_download_source, config,
76                           force_download=False):
77 
78     need_reparse_in_env = False
79     if (force_download or (not no_download_source and (metadata.uses_vcs_in_meta or
80                                                        metadata.uses_setup_py_in_meta))):
81 
82         # this try/catch is for when the tool to download source is actually in
83         #    meta.yaml, and not previously installed in builder env.
84         try:
85             if not config.dirty:
86                 source.provide(metadata.path, metadata.get_section('source'), config=config)
87                 need_source_download = False
88             try:
89                 metadata.parse_again(config=config, permit_undefined_jinja=False)
90             except (ImportError, exceptions.UnableToParseMissingSetuptoolsDependencies):
91                 need_reparse_in_env = True
92         except subprocess.CalledProcessError as error:
93             print("Warning: failed to download source.  If building, will try "
94                 "again after downloading recipe dependencies.")
95             print("Error was: ")
96             print(error)
97             need_source_download = True
98 
99     elif not metadata.get_section('source'):
100         need_source_download = False
101         if not os.path.isdir(config.work_dir):
102             os.makedirs(config.work_dir)
103     else:
104         # we have not downloaded source in the render phase.  Download it in
105         #     the build phase
106         need_source_download = not no_download_source
107     if not need_reparse_in_env:
108         try:
109             metadata.parse_until_resolved(config=config)
110         except exceptions.UnableToParseMissingSetuptoolsDependencies:
111             need_reparse_in_env = True
112     return metadata, need_source_download, need_reparse_in_env
113 
114 
115 def reparse(metadata, config):
116     """Some things need to be parsed again after the build environment has been created
117     and activated."""
118     sys.path.insert(0, config.build_prefix)
119     sys.path.insert(0, utils.get_site_packages(config.build_prefix))
120     metadata.parse_again(config=config, permit_undefined_jinja=False)
121 
122 
123 def render_recipe(recipe_path, config, no_download_source=False):
124     arg = recipe_path
125     # Don't use byte literals for paths in Python 2
126     if not PY3:
127         arg = arg.decode(getpreferredencoding() or 'utf-8')
128     if isfile(arg):
129         if arg.endswith(('.tar', '.tar.gz', '.tgz', '.tar.bz2')):
130             recipe_dir = tempfile.mkdtemp()
131             t = tarfile.open(arg, 'r:*')
132             t.extractall(path=recipe_dir)
133             t.close()
134             need_cleanup = True
135         else:
136             print("Ignoring non-recipe: %s" % arg)
137             return
138     else:
139         recipe_dir = abspath(arg)
140         need_cleanup = False
141 
142     if not isdir(recipe_dir):
143         sys.exit("Error: no such directory: %s" % recipe_dir)
144 
145     if config.set_build_id:
146         # updates a unique build id if not already computed
147         config.compute_build_id(os.path.basename(recipe_dir))
148     try:
149         m = MetaData(recipe_dir, config=config)
150     except exceptions.YamlParsingError as e:
151         sys.stderr.write(e.error_msg())
152         sys.exit(1)
153 
154     config.noarch = m.get_value('build/noarch')
155     m, need_download, need_reparse_in_env = parse_or_try_download(m,
156                                                 no_download_source=no_download_source,
157                                                 config=config)
158 
159     if need_cleanup:
160         rm_rf(recipe_dir)
161 
162     return m, need_download, need_reparse_in_env
163 
164 
165 # Next bit of stuff is to support YAML output in the order we expect.
166 # http://stackoverflow.com/a/17310199/1170370
167 class _MetaYaml(dict):
168     fields = ["package", "source", "build", "requirements", "test", "about", "extra"]
169 
170     def to_omap(self):
171         return [(field, self[field]) for field in _MetaYaml.fields if field in self]
172 
173 
174 def _represent_omap(dumper, data):
175     return dumper.represent_mapping(u'tag:yaml.org,2002:map', data.to_omap())
176 
177 
178 def _unicode_representer(dumper, uni):
179     node = yaml.ScalarNode(tag=u'tag:yaml.org,2002:str', value=uni)
180     return node
181 
182 
183 class _IndentDumper(yaml.Dumper):
184     def increase_indent(self, flow=False, indentless=False):
185         return super(_IndentDumper, self).increase_indent(flow, False)
186 
187 yaml.add_representer(_MetaYaml, _represent_omap)
188 if PY3:
189     yaml.add_representer(str, _unicode_representer)
190     unicode = None  # silence pyflakes about unicode not existing in py3
191 else:
192     yaml.add_representer(unicode, _unicode_representer)
193 
194 
195 def output_yaml(metadata, filename=None):
196     output = yaml.dump(_MetaYaml(metadata.meta), Dumper=_IndentDumper,
197                        default_flow_style=False, indent=4)
198     if filename:
199         with open(filename, "w") as f:
200             f.write(output)
201         return "Wrote yaml to %s" % filename
202     else:
203         return output
204
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/conda_build/render.py b/conda_build/render.py
--- a/conda_build/render.py
+++ b/conda_build/render.py
@@ -69,7 +69,8 @@
     '''
     Returns path to built package's tarball given its ``Metadata``.
     '''
-    return os.path.join(config.bldpkgs_dir, '%s.tar.bz2' % m.dist())
+    output_dir = m.info_index()['subdir']
+    return os.path.join(os.path.dirname(config.bldpkgs_dir), output_dir, '%s.tar.bz2' % m.dist())
 
 
 def parse_or_try_download(metadata, no_download_source, config,

{"golden_diff": "diff --git a/conda_build/render.py b/conda_build/render.py\n--- a/conda_build/render.py\n+++ b/conda_build/render.py\n@@ -69,7 +69,8 @@\n     '''\n     Returns path to built package's tarball given its ``Metadata``.\n     '''\n-    return os.path.join(config.bldpkgs_dir, '%s.tar.bz2' % m.dist())\n+    output_dir = m.info_index()['subdir']\n+    return os.path.join(os.path.dirname(config.bldpkgs_dir), output_dir, '%s.tar.bz2' % m.dist())\n \n \n def parse_or_try_download(metadata, no_download_source, config,\n", "issue": "--output reports wrong folder for noarch packages\nIn linux-64 packages build with the noarch  flag end up in the appropriate directory, but the --output function does not return the correct path.  \n\n", "before_files": [{"content": "# (c) Continuum Analytics, Inc. / http://continuum.io\n# All Rights Reserved\n#\n# conda is distributed under the terms of the BSD 3-clause license.\n# Consult LICENSE.txt or http://opensource.org/licenses/BSD-3-Clause.\n\nfrom __future__ import absolute_import, division, print_function\n\nfrom locale import getpreferredencoding\nimport os\nfrom os.path import isdir, isfile, abspath\nimport subprocess\nimport sys\nimport tarfile\nimport tempfile\n\nimport yaml\n\nfrom .conda_interface import PY3\n\nfrom conda_build import exceptions, utils\nfrom conda_build.metadata import MetaData\nimport conda_build.source as source\nfrom conda_build.completers import all_versions, conda_version\nfrom conda_build.utils import rm_rf\n\n\ndef set_language_env_vars(args, parser, config, execute=None):\n    \"\"\"Given args passed into conda command, set language env vars\"\"\"\n    for lang in all_versions:\n        versions = getattr(args, lang)\n        if not versions:\n            continue\n        if versions == ['all']:\n            if all_versions[lang]:\n                versions = all_versions[lang]\n            else:\n                parser.error(\"'all' is not supported for --%s\" % lang)\n        if len(versions) > 1:\n            for ver in versions[:]:\n                setattr(args, lang, [str(ver)])\n                if execute:\n                    execute(args, parser, config)\n                # This is necessary to make all combinations build.\n                setattr(args, lang, versions)\n            return\n        else:\n            version = versions[0]\n            if lang in ('python', 'numpy'):\n                version = int(version.replace('.', ''))\n            setattr(config, conda_version[lang], version)\n        if not len(str(version)) in (2, 3) and lang in ['python', 'numpy']:\n            if all_versions[lang]:\n                raise RuntimeError(\"%s must be major.minor, like %s, not %s\" %\n                    (conda_version[lang], all_versions[lang][-1] / 10, version))\n            else:\n                raise RuntimeError(\"%s must be major.minor, not %s\" %\n                    (conda_version[lang], version))\n\n    # Using --python, --numpy etc. is equivalent to using CONDA_PY, CONDA_NPY, etc.\n    # Auto-set those env variables\n    for var in conda_version.values():\n        if hasattr(config, var) and getattr(config, var):\n            # Set the env variable.\n            os.environ[var] = str(getattr(config, var))\n\n\ndef bldpkg_path(m, config):\n    '''\n    Returns path to built package's tarball given its ``Metadata``.\n    '''\n    return os.path.join(config.bldpkgs_dir, '%s.tar.bz2' % m.dist())\n\n\ndef parse_or_try_download(metadata, no_download_source, config,\n                          force_download=False):\n\n    need_reparse_in_env = False\n    if (force_download or (not no_download_source and (metadata.uses_vcs_in_meta or\n                                                       metadata.uses_setup_py_in_meta))):\n\n        # this try/catch is for when the tool to download source is actually in\n        #    meta.yaml, and not previously installed in builder env.\n        try:\n            if not config.dirty:\n                source.provide(metadata.path, metadata.get_section('source'), config=config)\n                need_source_download = False\n            try:\n                metadata.parse_again(config=config, permit_undefined_jinja=False)\n            except (ImportError, exceptions.UnableToParseMissingSetuptoolsDependencies):\n                need_reparse_in_env = True\n        except subprocess.CalledProcessError as error:\n            print(\"Warning: failed to download source.  If building, will try \"\n                \"again after downloading recipe dependencies.\")\n            print(\"Error was: \")\n            print(error)\n            need_source_download = True\n\n    elif not metadata.get_section('source'):\n        need_source_download = False\n        if not os.path.isdir(config.work_dir):\n            os.makedirs(config.work_dir)\n    else:\n        # we have not downloaded source in the render phase.  Download it in\n        #     the build phase\n        need_source_download = not no_download_source\n    if not need_reparse_in_env:\n        try:\n            metadata.parse_until_resolved(config=config)\n        except exceptions.UnableToParseMissingSetuptoolsDependencies:\n            need_reparse_in_env = True\n    return metadata, need_source_download, need_reparse_in_env\n\n\ndef reparse(metadata, config):\n    \"\"\"Some things need to be parsed again after the build environment has been created\n    and activated.\"\"\"\n    sys.path.insert(0, config.build_prefix)\n    sys.path.insert(0, utils.get_site_packages(config.build_prefix))\n    metadata.parse_again(config=config, permit_undefined_jinja=False)\n\n\ndef render_recipe(recipe_path, config, no_download_source=False):\n    arg = recipe_path\n    # Don't use byte literals for paths in Python 2\n    if not PY3:\n        arg = arg.decode(getpreferredencoding() or 'utf-8')\n    if isfile(arg):\n        if arg.endswith(('.tar', '.tar.gz', '.tgz', '.tar.bz2')):\n            recipe_dir = tempfile.mkdtemp()\n            t = tarfile.open(arg, 'r:*')\n            t.extractall(path=recipe_dir)\n            t.close()\n            need_cleanup = True\n        else:\n            print(\"Ignoring non-recipe: %s\" % arg)\n            return\n    else:\n        recipe_dir = abspath(arg)\n        need_cleanup = False\n\n    if not isdir(recipe_dir):\n        sys.exit(\"Error: no such directory: %s\" % recipe_dir)\n\n    if config.set_build_id:\n        # updates a unique build id if not already computed\n        config.compute_build_id(os.path.basename(recipe_dir))\n    try:\n        m = MetaData(recipe_dir, config=config)\n    except exceptions.YamlParsingError as e:\n        sys.stderr.write(e.error_msg())\n        sys.exit(1)\n\n    config.noarch = m.get_value('build/noarch')\n    m, need_download, need_reparse_in_env = parse_or_try_download(m,\n                                                no_download_source=no_download_source,\n                                                config=config)\n\n    if need_cleanup:\n        rm_rf(recipe_dir)\n\n    return m, need_download, need_reparse_in_env\n\n\n# Next bit of stuff is to support YAML output in the order we expect.\n# http://stackoverflow.com/a/17310199/1170370\nclass _MetaYaml(dict):\n    fields = [\"package\", \"source\", \"build\", \"requirements\", \"test\", \"about\", \"extra\"]\n\n    def to_omap(self):\n        return [(field, self[field]) for field in _MetaYaml.fields if field in self]\n\n\ndef _represent_omap(dumper, data):\n    return dumper.represent_mapping(u'tag:yaml.org,2002:map', data.to_omap())\n\n\ndef _unicode_representer(dumper, uni):\n    node = yaml.ScalarNode(tag=u'tag:yaml.org,2002:str', value=uni)\n    return node\n\n\nclass _IndentDumper(yaml.Dumper):\n    def increase_indent(self, flow=False, indentless=False):\n        return super(_IndentDumper, self).increase_indent(flow, False)\n\nyaml.add_representer(_MetaYaml, _represent_omap)\nif PY3:\n    yaml.add_representer(str, _unicode_representer)\n    unicode = None  # silence pyflakes about unicode not existing in py3\nelse:\n    yaml.add_representer(unicode, _unicode_representer)\n\n\ndef output_yaml(metadata, filename=None):\n    output = yaml.dump(_MetaYaml(metadata.meta), Dumper=_IndentDumper,\n                       default_flow_style=False, indent=4)\n    if filename:\n        with open(filename, \"w\") as f:\n            f.write(output)\n        return \"Wrote yaml to %s\" % filename\n    else:\n        return output\n", "path": "conda_build/render.py"}], "after_files": [{"content": "# (c) Continuum Analytics, Inc. / http://continuum.io\n# All Rights Reserved\n#\n# conda is distributed under the terms of the BSD 3-clause license.\n# Consult LICENSE.txt or http://opensource.org/licenses/BSD-3-Clause.\n\nfrom __future__ import absolute_import, division, print_function\n\nfrom locale import getpreferredencoding\nimport os\nfrom os.path import isdir, isfile, abspath\nimport subprocess\nimport sys\nimport tarfile\nimport tempfile\n\nimport yaml\n\nfrom .conda_interface import PY3\n\nfrom conda_build import exceptions, utils\nfrom conda_build.metadata import MetaData\nimport conda_build.source as source\nfrom conda_build.completers import all_versions, conda_version\nfrom conda_build.utils import rm_rf\n\n\ndef set_language_env_vars(args, parser, config, execute=None):\n    \"\"\"Given args passed into conda command, set language env vars\"\"\"\n    for lang in all_versions:\n        versions = getattr(args, lang)\n        if not versions:\n            continue\n        if versions == ['all']:\n            if all_versions[lang]:\n                versions = all_versions[lang]\n            else:\n                parser.error(\"'all' is not supported for --%s\" % lang)\n        if len(versions) > 1:\n            for ver in versions[:]:\n                setattr(args, lang, [str(ver)])\n                if execute:\n                    execute(args, parser, config)\n                # This is necessary to make all combinations build.\n                setattr(args, lang, versions)\n            return\n        else:\n            version = versions[0]\n            if lang in ('python', 'numpy'):\n                version = int(version.replace('.', ''))\n            setattr(config, conda_version[lang], version)\n        if not len(str(version)) in (2, 3) and lang in ['python', 'numpy']:\n            if all_versions[lang]:\n                raise RuntimeError(\"%s must be major.minor, like %s, not %s\" %\n                    (conda_version[lang], all_versions[lang][-1] / 10, version))\n            else:\n                raise RuntimeError(\"%s must be major.minor, not %s\" %\n                    (conda_version[lang], version))\n\n    # Using --python, --numpy etc. is equivalent to using CONDA_PY, CONDA_NPY, etc.\n    # Auto-set those env variables\n    for var in conda_version.values():\n        if hasattr(config, var) and getattr(config, var):\n            # Set the env variable.\n            os.environ[var] = str(getattr(config, var))\n\n\ndef bldpkg_path(m, config):\n    '''\n    Returns path to built package's tarball given its ``Metadata``.\n    '''\n    output_dir = m.info_index()['subdir']\n    return os.path.join(os.path.dirname(config.bldpkgs_dir), output_dir, '%s.tar.bz2' % m.dist())\n\n\ndef parse_or_try_download(metadata, no_download_source, config,\n                          force_download=False):\n\n    need_reparse_in_env = False\n    if (force_download or (not no_download_source and (metadata.uses_vcs_in_meta or\n                                                       metadata.uses_setup_py_in_meta))):\n\n        # this try/catch is for when the tool to download source is actually in\n        #    meta.yaml, and not previously installed in builder env.\n        try:\n            if not config.dirty:\n                source.provide(metadata.path, metadata.get_section('source'), config=config)\n                need_source_download = False\n            try:\n                metadata.parse_again(config=config, permit_undefined_jinja=False)\n            except (ImportError, exceptions.UnableToParseMissingSetuptoolsDependencies):\n                need_reparse_in_env = True\n        except subprocess.CalledProcessError as error:\n            print(\"Warning: failed to download source.  If building, will try \"\n                \"again after downloading recipe dependencies.\")\n            print(\"Error was: \")\n            print(error)\n            need_source_download = True\n\n    elif not metadata.get_section('source'):\n        need_source_download = False\n        if not os.path.isdir(config.work_dir):\n            os.makedirs(config.work_dir)\n    else:\n        # we have not downloaded source in the render phase.  Download it in\n        #     the build phase\n        need_source_download = not no_download_source\n    if not need_reparse_in_env:\n        try:\n            metadata.parse_until_resolved(config=config)\n        except exceptions.UnableToParseMissingSetuptoolsDependencies:\n            need_reparse_in_env = True\n    return metadata, need_source_download, need_reparse_in_env\n\n\ndef reparse(metadata, config):\n    \"\"\"Some things need to be parsed again after the build environment has been created\n    and activated.\"\"\"\n    sys.path.insert(0, config.build_prefix)\n    sys.path.insert(0, utils.get_site_packages(config.build_prefix))\n    metadata.parse_again(config=config, permit_undefined_jinja=False)\n\n\ndef render_recipe(recipe_path, config, no_download_source=False):\n    arg = recipe_path\n    # Don't use byte literals for paths in Python 2\n    if not PY3:\n        arg = arg.decode(getpreferredencoding() or 'utf-8')\n    if isfile(arg):\n        if arg.endswith(('.tar', '.tar.gz', '.tgz', '.tar.bz2')):\n            recipe_dir = tempfile.mkdtemp()\n            t = tarfile.open(arg, 'r:*')\n            t.extractall(path=recipe_dir)\n            t.close()\n            need_cleanup = True\n        else:\n            print(\"Ignoring non-recipe: %s\" % arg)\n            return\n    else:\n        recipe_dir = abspath(arg)\n        need_cleanup = False\n\n    if not isdir(recipe_dir):\n        sys.exit(\"Error: no such directory: %s\" % recipe_dir)\n\n    if config.set_build_id:\n        # updates a unique build id if not already computed\n        config.compute_build_id(os.path.basename(recipe_dir))\n    try:\n        m = MetaData(recipe_dir, config=config)\n    except exceptions.YamlParsingError as e:\n        sys.stderr.write(e.error_msg())\n        sys.exit(1)\n\n    config.noarch = m.get_value('build/noarch')\n    m, need_download, need_reparse_in_env = parse_or_try_download(m,\n                                                no_download_source=no_download_source,\n                                                config=config)\n\n    if need_cleanup:\n        rm_rf(recipe_dir)\n\n    return m, need_download, need_reparse_in_env\n\n\n# Next bit of stuff is to support YAML output in the order we expect.\n# http://stackoverflow.com/a/17310199/1170370\nclass _MetaYaml(dict):\n    fields = [\"package\", \"source\", \"build\", \"requirements\", \"test\", \"about\", \"extra\"]\n\n    def to_omap(self):\n        return [(field, self[field]) for field in _MetaYaml.fields if field in self]\n\n\ndef _represent_omap(dumper, data):\n    return dumper.represent_mapping(u'tag:yaml.org,2002:map', data.to_omap())\n\n\ndef _unicode_representer(dumper, uni):\n    node = yaml.ScalarNode(tag=u'tag:yaml.org,2002:str', value=uni)\n    return node\n\n\nclass _IndentDumper(yaml.Dumper):\n    def increase_indent(self, flow=False, indentless=False):\n        return super(_IndentDumper, self).increase_indent(flow, False)\n\nyaml.add_representer(_MetaYaml, _represent_omap)\nif PY3:\n    yaml.add_representer(str, _unicode_representer)\n    unicode = None  # silence pyflakes about unicode not existing in py3\nelse:\n    yaml.add_representer(unicode, _unicode_representer)\n\n\ndef output_yaml(metadata, filename=None):\n    output = yaml.dump(_MetaYaml(metadata.meta), Dumper=_IndentDumper,\n                       default_flow_style=False, indent=4)\n    if filename:\n        with open(filename, \"w\") as f:\n            f.write(output)\n        return \"Wrote yaml to %s\" % filename\n    else:\n        return output\n", "path": "conda_build/render.py"}]}