We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
conda-build no longer generates .exe files for my scripts on Windows
I notice that conda-build, verson 1.21.7, used to generate .exe files to invoke my scripts.  But 2.0.6 doesn't seem to do that.  I've got Python scripts, goodstuff, goodstuff-data, and goodstuff-library, which are marked as scripts in my setup.py file.  1.21.7 turns them into goodstuff-script.py and goodstuff.exe, goodstuff-data-script.py and goodstuff-data.exe, etc.  Which I found very useful.

Is there any way to get that 1.21.functionality back again?


--- 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/windows.py`
Content:
```
1 from __future__ import absolute_import, division, print_function
2 
3 import os
4 import sys
5 from os.path import isdir, join
6 
7 # importing setuptools patches distutils so that it knows how to find VC for python 2.7
8 import setuptools  # noqa
9 # Leverage the hard work done by setuptools/distutils to find vcvarsall using
10 # either the registry or the VS**COMNTOOLS environment variable
11 from distutils.msvc9compiler import find_vcvarsall as distutils_find_vcvarsall
12 from distutils.msvc9compiler import Reg, WINSDK_BASE
13 
14 from .conda_interface import bits
15 
16 from conda_build import environ
17 from conda_build.utils import _check_call, root_script_dir, path_prepended
18 
19 
20 assert sys.platform == 'win32'
21 
22 
23 VS_VERSION_STRING = {
24     '8.0': 'Visual Studio 8 2005',
25     '9.0': 'Visual Studio 9 2008',
26     '10.0': 'Visual Studio 10 2010',
27     '11.0': 'Visual Studio 11 2012',
28     '12.0': 'Visual Studio 12 2013',
29     '14.0': 'Visual Studio 14 2015'
30 }
31 
32 
33 def build_vcvarsall_vs_path(version):
34     """
35     Given the Visual Studio version, returns the default path to the
36     Microsoft Visual Studio vcvarsall.bat file.
37     Expected versions are of the form {9.0, 10.0, 12.0, 14.0}
38     """
39     # Set up a load of paths that can be imported from the tests
40     if 'ProgramFiles(x86)' in os.environ:
41         PROGRAM_FILES_PATH = os.environ['ProgramFiles(x86)']
42     else:
43         PROGRAM_FILES_PATH = os.environ['ProgramFiles']
44 
45     flatversion = str(version).replace('.', '')
46     vstools = "VS{0}COMNTOOLS".format(flatversion)
47 
48     if vstools in os.environ:
49         return os.path.join(os.environ[vstools], '..\\..\\VC\\vcvarsall.bat')
50     else:
51         # prefer looking at env var; fall back to program files defaults
52         return os.path.join(PROGRAM_FILES_PATH,
53                             'Microsoft Visual Studio {}'.format(version), 'VC',
54                             'vcvarsall.bat')
55 
56 
57 def msvc_env_cmd(bits, config, override=None):
58     arch_selector = 'x86' if bits == 32 else 'amd64'
59 
60     msvc_env_lines = []
61 
62     version = None
63     if override is not None:
64         version = override
65 
66     # The DISTUTILS_USE_SDK variable tells distutils to not try and validate
67     # the MSVC compiler. For < 3.5 this still forcibly looks for 'cl.exe'.
68     # For > 3.5 it literally just skips the validation logic.
69     # See distutils _msvccompiler.py and msvc9compiler.py / msvccompiler.py
70     # for more information.
71     msvc_env_lines.append('set DISTUTILS_USE_SDK=1')
72     # This is also required to hit the 'don't validate' logic on < 3.5.
73     # For > 3.5 this is ignored.
74     msvc_env_lines.append('set MSSdk=1')
75 
76     if not version:
77         if config.PY3K and config.use_MSVC2015:
78             version = '14.0'
79         elif config.PY3K:
80             version = '10.0'
81         else:
82             version = '9.0'
83 
84     if float(version) >= 14.0:
85         # For Python 3.5+, ensure that we link with the dynamic runtime.  See
86         # http://stevedower.id.au/blog/building-for-python-3-5-part-two/ for more info
87         msvc_env_lines.append('set PY_VCRUNTIME_REDIST=%LIBRARY_BIN%\\vcruntime{0}.dll'.format(
88             version.replace('.', '')))
89 
90     vcvarsall_vs_path = build_vcvarsall_vs_path(version)
91 
92     def build_vcvarsall_cmd(cmd, arch=arch_selector):
93         # Default argument `arch_selector` is defined above
94         return 'call "{cmd}" {arch}'.format(cmd=cmd, arch=arch)
95 
96     msvc_env_lines.append('set "VS_VERSION={}"'.format(version))
97     msvc_env_lines.append('set "VS_MAJOR={}"'.format(version.split('.')[0]))
98     msvc_env_lines.append('set "VS_YEAR={}"'.format(VS_VERSION_STRING[version][-4:]))
99     msvc_env_lines.append('set "CMAKE_GENERATOR={}"'.format(VS_VERSION_STRING[version] +
100                                                             {64: ' Win64', 32: ''}[bits]))
101     # tell msys2 to ignore path conversions for issue-causing windows-style flags in build
102     #   See https://github.com/conda-forge/icu-feedstock/pull/5
103     msvc_env_lines.append('set "MSYS2_ARG_CONV_EXCL=/AI;/AL;/OUT;/out;%MSYS2_ARG_CONV_EXCL%"')
104     msvc_env_lines.append('set "MSYS2_ENV_CONV_EXCL=CL"')
105     if version == '10.0':
106         try:
107             WIN_SDK_71_PATH = Reg.get_value(os.path.join(WINSDK_BASE, 'v7.1'),
108                                             'installationfolder')
109             WIN_SDK_71_BAT_PATH = os.path.join(WIN_SDK_71_PATH, 'Bin', 'SetEnv.cmd')
110 
111             win_sdk_arch = '/Release /x86' if bits == 32 else '/Release /x64'
112             win_sdk_cmd = build_vcvarsall_cmd(WIN_SDK_71_BAT_PATH, arch=win_sdk_arch)
113 
114             # There are two methods of building Python 3.3 and 3.4 extensions (both
115             # of which required Visual Studio 2010 - as explained in the Python wiki
116             # https://wiki.python.org/moin/WindowsCompilers)
117             # 1) Use the Windows SDK 7.1
118             # 2) Use Visual Studio 2010 (any edition)
119             # However, VS2010 never shipped with a 64-bit compiler, so in this case
120             # **only** option (1) applies. For this reason, we always try and
121             # activate the Windows SDK first. Unfortunately, unsuccessfully setting
122             # up the environment does **not EXIT 1** and therefore we must fall
123             # back to attempting to set up VS2010.
124             # DelayedExpansion is required for the SetEnv.cmd
125             msvc_env_lines.append('Setlocal EnableDelayedExpansion')
126             msvc_env_lines.append(win_sdk_cmd)
127             # If the WindowsSDKDir environment variable has not been successfully
128             # set then try activating VS2010
129             msvc_env_lines.append('if not "%WindowsSDKDir%" == "{}" ( {} )'.format(
130                 WIN_SDK_71_PATH, build_vcvarsall_cmd(vcvarsall_vs_path)))
131         # sdk is not installed.  Fall back to only trying VS 2010
132         except KeyError:
133             msvc_env_lines.append(build_vcvarsall_cmd(vcvarsall_vs_path))
134     elif version == '9.0':
135         # Get the Visual Studio 2008 path (not the Visual C++ for Python path)
136         # and get the 'vcvars64.bat' from inside the bin (in the directory above
137         # that returned by distutils_find_vcvarsall)
138         try:
139             VCVARS64_VS9_BAT_PATH = os.path.join(os.path.dirname(distutils_find_vcvarsall(9)),
140                                                 'bin', 'vcvars64.bat')
141         # there's an exception if VS or the VC compiler for python are not actually installed.
142         except (KeyError, TypeError):
143             VCVARS64_VS9_BAT_PATH = None
144 
145         error1 = 'if errorlevel 1 {}'
146 
147         # Prefer VS9 proper over Microsoft Visual C++ Compiler for Python 2.7
148         msvc_env_lines.append(build_vcvarsall_cmd(vcvarsall_vs_path))
149         # The Visual Studio 2008 Express edition does not properly contain
150         # the amd64 build files, so we call the vcvars64.bat manually,
151         # rather than using the vcvarsall.bat which would try and call the
152         # missing bat file.
153         if arch_selector == 'amd64' and VCVARS64_VS9_BAT_PATH:
154             msvc_env_lines.append(error1.format(
155                 build_vcvarsall_cmd(VCVARS64_VS9_BAT_PATH)))
156         # Otherwise, fall back to icrosoft Visual C++ Compiler for Python 2.7+
157         # by using the logic provided by setuptools
158         msvc_env_lines.append(error1.format(
159             build_vcvarsall_cmd(distutils_find_vcvarsall(9))))
160     else:
161         # Visual Studio 14 or otherwise
162         msvc_env_lines.append(build_vcvarsall_cmd(vcvarsall_vs_path))
163 
164     return '\n'.join(msvc_env_lines) + '\n'
165 
166 
167 def build(m, bld_bat, config):
168     with path_prepended(config.build_prefix):
169         env = environ.get_dict(config=config, m=m)
170     env["CONDA_BUILD_STATE"] = "BUILD"
171 
172     for name in 'BIN', 'INC', 'LIB':
173         path = env['LIBRARY_' + name]
174         if not isdir(path):
175             os.makedirs(path)
176 
177     src_dir = config.work_dir
178     if os.path.isfile(bld_bat):
179         with open(bld_bat) as fi:
180             data = fi.read()
181         with open(join(src_dir, 'bld.bat'), 'w') as fo:
182             # more debuggable with echo on
183             fo.write('@echo on\n')
184             for key, value in env.items():
185                 fo.write('set "{key}={value}"\n'.format(key=key, value=value))
186             fo.write(msvc_env_cmd(bits=bits, config=config,
187                                   override=m.get_value('build/msvc_compiler', None)))
188             # Reset echo on, because MSVC scripts might have turned it off
189             fo.write('@echo on\n')
190             fo.write('set "INCLUDE={};%INCLUDE%"\n'.format(env["LIBRARY_INC"]))
191             fo.write('set "LIB={};%LIB%"\n'.format(env["LIBRARY_LIB"]))
192             if config.activate:
193                 fo.write('call "{conda_root}\\activate.bat" "{prefix}"\n'.format(
194                     conda_root=root_script_dir,
195                     prefix=config.build_prefix))
196             fo.write("REM ===== end generated header =====\n")
197             fo.write(data)
198 
199         cmd = ['cmd.exe', '/c', 'bld.bat']
200         _check_call(cmd, cwd=src_dir)
201
```
--- 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/windows.py b/conda_build/windows.py
--- a/conda_build/windows.py
+++ b/conda_build/windows.py
@@ -2,7 +2,7 @@
 
 import os
 import sys
-from os.path import isdir, join
+from os.path import isdir, join, dirname, isfile
 
 # importing setuptools patches distutils so that it knows how to find VC for python 2.7
 import setuptools  # noqa
@@ -14,7 +14,7 @@
 from .conda_interface import bits
 
 from conda_build import environ
-from conda_build.utils import _check_call, root_script_dir, path_prepended
+from conda_build.utils import _check_call, root_script_dir, path_prepended, copy_into
 
 
 assert sys.platform == 'win32'
@@ -30,6 +30,36 @@
 }
 
 
+def fix_staged_scripts(scripts_dir):
+    """
+    Fixes scripts which have been installed unix-style to have a .bat
+    helper
+    """
+    if not isdir(scripts_dir):
+        return
+    for fn in os.listdir(scripts_dir):
+        # process all the extensionless files
+        if not isfile(join(scripts_dir, fn)) or '.' in fn:
+            continue
+
+        with open(join(scripts_dir, fn)) as f:
+            line = f.readline().lower()
+            # If it's a #!python script
+            if not (line.startswith('#!') and 'python' in line.lower()):
+                continue
+            print('Adjusting unix-style #! script %s, '
+                  'and adding a .bat file for it' % fn)
+            # copy it with a .py extension (skipping that first #! line)
+            with open(join(scripts_dir, fn + '-script.py'), 'w') as fo:
+                fo.write(f.read())
+            # now create the .exe file
+            copy_into(join(dirname(__file__), 'cli-%d.exe' % bits),
+                            join(scripts_dir, fn + '.exe'))
+
+        # remove the original script
+        os.remove(join(scripts_dir, fn))
+
+
 def build_vcvarsall_vs_path(version):
     """
     Given the Visual Studio version, returns the default path to the
@@ -198,3 +228,5 @@
 
         cmd = ['cmd.exe', '/c', 'bld.bat']
         _check_call(cmd, cwd=src_dir)
+
+    fix_staged_scripts(join(config.build_prefix, 'Scripts'))

{"golden_diff": "diff --git a/conda_build/windows.py b/conda_build/windows.py\n--- a/conda_build/windows.py\n+++ b/conda_build/windows.py\n@@ -2,7 +2,7 @@\n \n import os\n import sys\n-from os.path import isdir, join\n+from os.path import isdir, join, dirname, isfile\n \n # importing setuptools patches distutils so that it knows how to find VC for python 2.7\n import setuptools  # noqa\n@@ -14,7 +14,7 @@\n from .conda_interface import bits\n \n from conda_build import environ\n-from conda_build.utils import _check_call, root_script_dir, path_prepended\n+from conda_build.utils import _check_call, root_script_dir, path_prepended, copy_into\n \n \n assert sys.platform == 'win32'\n@@ -30,6 +30,36 @@\n }\n \n \n+def fix_staged_scripts(scripts_dir):\n+    \"\"\"\n+    Fixes scripts which have been installed unix-style to have a .bat\n+    helper\n+    \"\"\"\n+    if not isdir(scripts_dir):\n+        return\n+    for fn in os.listdir(scripts_dir):\n+        # process all the extensionless files\n+        if not isfile(join(scripts_dir, fn)) or '.' in fn:\n+            continue\n+\n+        with open(join(scripts_dir, fn)) as f:\n+            line = f.readline().lower()\n+            # If it's a #!python script\n+            if not (line.startswith('#!') and 'python' in line.lower()):\n+                continue\n+            print('Adjusting unix-style #! script %s, '\n+                  'and adding a .bat file for it' % fn)\n+            # copy it with a .py extension (skipping that first #! line)\n+            with open(join(scripts_dir, fn + '-script.py'), 'w') as fo:\n+                fo.write(f.read())\n+            # now create the .exe file\n+            copy_into(join(dirname(__file__), 'cli-%d.exe' % bits),\n+                            join(scripts_dir, fn + '.exe'))\n+\n+        # remove the original script\n+        os.remove(join(scripts_dir, fn))\n+\n+\n def build_vcvarsall_vs_path(version):\n     \"\"\"\n     Given the Visual Studio version, returns the default path to the\n@@ -198,3 +228,5 @@\n \n         cmd = ['cmd.exe', '/c', 'bld.bat']\n         _check_call(cmd, cwd=src_dir)\n+\n+    fix_staged_scripts(join(config.build_prefix, 'Scripts'))\n", "issue": "conda-build no longer generates .exe files for my scripts on Windows\nI notice that conda-build, verson 1.21.7, used to generate .exe files to invoke my scripts.  But 2.0.6 doesn't seem to do that.  I've got Python scripts, goodstuff, goodstuff-data, and goodstuff-library, which are marked as scripts in my setup.py file.  1.21.7 turns them into goodstuff-script.py and goodstuff.exe, goodstuff-data-script.py and goodstuff-data.exe, etc.  Which I found very useful.\n\nIs there any way to get that 1.21.functionality back again?\n\n", "before_files": [{"content": "from __future__ import absolute_import, division, print_function\n\nimport os\nimport sys\nfrom os.path import isdir, join\n\n# importing setuptools patches distutils so that it knows how to find VC for python 2.7\nimport setuptools  # noqa\n# Leverage the hard work done by setuptools/distutils to find vcvarsall using\n# either the registry or the VS**COMNTOOLS environment variable\nfrom distutils.msvc9compiler import find_vcvarsall as distutils_find_vcvarsall\nfrom distutils.msvc9compiler import Reg, WINSDK_BASE\n\nfrom .conda_interface import bits\n\nfrom conda_build import environ\nfrom conda_build.utils import _check_call, root_script_dir, path_prepended\n\n\nassert sys.platform == 'win32'\n\n\nVS_VERSION_STRING = {\n    '8.0': 'Visual Studio 8 2005',\n    '9.0': 'Visual Studio 9 2008',\n    '10.0': 'Visual Studio 10 2010',\n    '11.0': 'Visual Studio 11 2012',\n    '12.0': 'Visual Studio 12 2013',\n    '14.0': 'Visual Studio 14 2015'\n}\n\n\ndef build_vcvarsall_vs_path(version):\n    \"\"\"\n    Given the Visual Studio version, returns the default path to the\n    Microsoft Visual Studio vcvarsall.bat file.\n    Expected versions are of the form {9.0, 10.0, 12.0, 14.0}\n    \"\"\"\n    # Set up a load of paths that can be imported from the tests\n    if 'ProgramFiles(x86)' in os.environ:\n        PROGRAM_FILES_PATH = os.environ['ProgramFiles(x86)']\n    else:\n        PROGRAM_FILES_PATH = os.environ['ProgramFiles']\n\n    flatversion = str(version).replace('.', '')\n    vstools = \"VS{0}COMNTOOLS\".format(flatversion)\n\n    if vstools in os.environ:\n        return os.path.join(os.environ[vstools], '..\\\\..\\\\VC\\\\vcvarsall.bat')\n    else:\n        # prefer looking at env var; fall back to program files defaults\n        return os.path.join(PROGRAM_FILES_PATH,\n                            'Microsoft Visual Studio {}'.format(version), 'VC',\n                            'vcvarsall.bat')\n\n\ndef msvc_env_cmd(bits, config, override=None):\n    arch_selector = 'x86' if bits == 32 else 'amd64'\n\n    msvc_env_lines = []\n\n    version = None\n    if override is not None:\n        version = override\n\n    # The DISTUTILS_USE_SDK variable tells distutils to not try and validate\n    # the MSVC compiler. For < 3.5 this still forcibly looks for 'cl.exe'.\n    # For > 3.5 it literally just skips the validation logic.\n    # See distutils _msvccompiler.py and msvc9compiler.py / msvccompiler.py\n    # for more information.\n    msvc_env_lines.append('set DISTUTILS_USE_SDK=1')\n    # This is also required to hit the 'don't validate' logic on < 3.5.\n    # For > 3.5 this is ignored.\n    msvc_env_lines.append('set MSSdk=1')\n\n    if not version:\n        if config.PY3K and config.use_MSVC2015:\n            version = '14.0'\n        elif config.PY3K:\n            version = '10.0'\n        else:\n            version = '9.0'\n\n    if float(version) >= 14.0:\n        # For Python 3.5+, ensure that we link with the dynamic runtime.  See\n        # http://stevedower.id.au/blog/building-for-python-3-5-part-two/ for more info\n        msvc_env_lines.append('set PY_VCRUNTIME_REDIST=%LIBRARY_BIN%\\\\vcruntime{0}.dll'.format(\n            version.replace('.', '')))\n\n    vcvarsall_vs_path = build_vcvarsall_vs_path(version)\n\n    def build_vcvarsall_cmd(cmd, arch=arch_selector):\n        # Default argument `arch_selector` is defined above\n        return 'call \"{cmd}\" {arch}'.format(cmd=cmd, arch=arch)\n\n    msvc_env_lines.append('set \"VS_VERSION={}\"'.format(version))\n    msvc_env_lines.append('set \"VS_MAJOR={}\"'.format(version.split('.')[0]))\n    msvc_env_lines.append('set \"VS_YEAR={}\"'.format(VS_VERSION_STRING[version][-4:]))\n    msvc_env_lines.append('set \"CMAKE_GENERATOR={}\"'.format(VS_VERSION_STRING[version] +\n                                                            {64: ' Win64', 32: ''}[bits]))\n    # tell msys2 to ignore path conversions for issue-causing windows-style flags in build\n    #   See https://github.com/conda-forge/icu-feedstock/pull/5\n    msvc_env_lines.append('set \"MSYS2_ARG_CONV_EXCL=/AI;/AL;/OUT;/out;%MSYS2_ARG_CONV_EXCL%\"')\n    msvc_env_lines.append('set \"MSYS2_ENV_CONV_EXCL=CL\"')\n    if version == '10.0':\n        try:\n            WIN_SDK_71_PATH = Reg.get_value(os.path.join(WINSDK_BASE, 'v7.1'),\n                                            'installationfolder')\n            WIN_SDK_71_BAT_PATH = os.path.join(WIN_SDK_71_PATH, 'Bin', 'SetEnv.cmd')\n\n            win_sdk_arch = '/Release /x86' if bits == 32 else '/Release /x64'\n            win_sdk_cmd = build_vcvarsall_cmd(WIN_SDK_71_BAT_PATH, arch=win_sdk_arch)\n\n            # There are two methods of building Python 3.3 and 3.4 extensions (both\n            # of which required Visual Studio 2010 - as explained in the Python wiki\n            # https://wiki.python.org/moin/WindowsCompilers)\n            # 1) Use the Windows SDK 7.1\n            # 2) Use Visual Studio 2010 (any edition)\n            # However, VS2010 never shipped with a 64-bit compiler, so in this case\n            # **only** option (1) applies. For this reason, we always try and\n            # activate the Windows SDK first. Unfortunately, unsuccessfully setting\n            # up the environment does **not EXIT 1** and therefore we must fall\n            # back to attempting to set up VS2010.\n            # DelayedExpansion is required for the SetEnv.cmd\n            msvc_env_lines.append('Setlocal EnableDelayedExpansion')\n            msvc_env_lines.append(win_sdk_cmd)\n            # If the WindowsSDKDir environment variable has not been successfully\n            # set then try activating VS2010\n            msvc_env_lines.append('if not \"%WindowsSDKDir%\" == \"{}\" ( {} )'.format(\n                WIN_SDK_71_PATH, build_vcvarsall_cmd(vcvarsall_vs_path)))\n        # sdk is not installed.  Fall back to only trying VS 2010\n        except KeyError:\n            msvc_env_lines.append(build_vcvarsall_cmd(vcvarsall_vs_path))\n    elif version == '9.0':\n        # Get the Visual Studio 2008 path (not the Visual C++ for Python path)\n        # and get the 'vcvars64.bat' from inside the bin (in the directory above\n        # that returned by distutils_find_vcvarsall)\n        try:\n            VCVARS64_VS9_BAT_PATH = os.path.join(os.path.dirname(distutils_find_vcvarsall(9)),\n                                                'bin', 'vcvars64.bat')\n        # there's an exception if VS or the VC compiler for python are not actually installed.\n        except (KeyError, TypeError):\n            VCVARS64_VS9_BAT_PATH = None\n\n        error1 = 'if errorlevel 1 {}'\n\n        # Prefer VS9 proper over Microsoft Visual C++ Compiler for Python 2.7\n        msvc_env_lines.append(build_vcvarsall_cmd(vcvarsall_vs_path))\n        # The Visual Studio 2008 Express edition does not properly contain\n        # the amd64 build files, so we call the vcvars64.bat manually,\n        # rather than using the vcvarsall.bat which would try and call the\n        # missing bat file.\n        if arch_selector == 'amd64' and VCVARS64_VS9_BAT_PATH:\n            msvc_env_lines.append(error1.format(\n                build_vcvarsall_cmd(VCVARS64_VS9_BAT_PATH)))\n        # Otherwise, fall back to icrosoft Visual C++ Compiler for Python 2.7+\n        # by using the logic provided by setuptools\n        msvc_env_lines.append(error1.format(\n            build_vcvarsall_cmd(distutils_find_vcvarsall(9))))\n    else:\n        # Visual Studio 14 or otherwise\n        msvc_env_lines.append(build_vcvarsall_cmd(vcvarsall_vs_path))\n\n    return '\\n'.join(msvc_env_lines) + '\\n'\n\n\ndef build(m, bld_bat, config):\n    with path_prepended(config.build_prefix):\n        env = environ.get_dict(config=config, m=m)\n    env[\"CONDA_BUILD_STATE\"] = \"BUILD\"\n\n    for name in 'BIN', 'INC', 'LIB':\n        path = env['LIBRARY_' + name]\n        if not isdir(path):\n            os.makedirs(path)\n\n    src_dir = config.work_dir\n    if os.path.isfile(bld_bat):\n        with open(bld_bat) as fi:\n            data = fi.read()\n        with open(join(src_dir, 'bld.bat'), 'w') as fo:\n            # more debuggable with echo on\n            fo.write('@echo on\\n')\n            for key, value in env.items():\n                fo.write('set \"{key}={value}\"\\n'.format(key=key, value=value))\n            fo.write(msvc_env_cmd(bits=bits, config=config,\n                                  override=m.get_value('build/msvc_compiler', None)))\n            # Reset echo on, because MSVC scripts might have turned it off\n            fo.write('@echo on\\n')\n            fo.write('set \"INCLUDE={};%INCLUDE%\"\\n'.format(env[\"LIBRARY_INC\"]))\n            fo.write('set \"LIB={};%LIB%\"\\n'.format(env[\"LIBRARY_LIB\"]))\n            if config.activate:\n                fo.write('call \"{conda_root}\\\\activate.bat\" \"{prefix}\"\\n'.format(\n                    conda_root=root_script_dir,\n                    prefix=config.build_prefix))\n            fo.write(\"REM ===== end generated header =====\\n\")\n            fo.write(data)\n\n        cmd = ['cmd.exe', '/c', 'bld.bat']\n        _check_call(cmd, cwd=src_dir)\n", "path": "conda_build/windows.py"}], "after_files": [{"content": "from __future__ import absolute_import, division, print_function\n\nimport os\nimport sys\nfrom os.path import isdir, join, dirname, isfile\n\n# importing setuptools patches distutils so that it knows how to find VC for python 2.7\nimport setuptools  # noqa\n# Leverage the hard work done by setuptools/distutils to find vcvarsall using\n# either the registry or the VS**COMNTOOLS environment variable\nfrom distutils.msvc9compiler import find_vcvarsall as distutils_find_vcvarsall\nfrom distutils.msvc9compiler import Reg, WINSDK_BASE\n\nfrom .conda_interface import bits\n\nfrom conda_build import environ\nfrom conda_build.utils import _check_call, root_script_dir, path_prepended, copy_into\n\n\nassert sys.platform == 'win32'\n\n\nVS_VERSION_STRING = {\n    '8.0': 'Visual Studio 8 2005',\n    '9.0': 'Visual Studio 9 2008',\n    '10.0': 'Visual Studio 10 2010',\n    '11.0': 'Visual Studio 11 2012',\n    '12.0': 'Visual Studio 12 2013',\n    '14.0': 'Visual Studio 14 2015'\n}\n\n\ndef fix_staged_scripts(scripts_dir):\n    \"\"\"\n    Fixes scripts which have been installed unix-style to have a .bat\n    helper\n    \"\"\"\n    if not isdir(scripts_dir):\n        return\n    for fn in os.listdir(scripts_dir):\n        # process all the extensionless files\n        if not isfile(join(scripts_dir, fn)) or '.' in fn:\n            continue\n\n        with open(join(scripts_dir, fn)) as f:\n            line = f.readline().lower()\n            # If it's a #!python script\n            if not (line.startswith('#!') and 'python' in line.lower()):\n                continue\n            print('Adjusting unix-style #! script %s, '\n                  'and adding a .bat file for it' % fn)\n            # copy it with a .py extension (skipping that first #! line)\n            with open(join(scripts_dir, fn + '-script.py'), 'w') as fo:\n                fo.write(f.read())\n            # now create the .exe file\n            copy_into(join(dirname(__file__), 'cli-%d.exe' % bits),\n                            join(scripts_dir, fn + '.exe'))\n\n        # remove the original script\n        os.remove(join(scripts_dir, fn))\n\n\ndef build_vcvarsall_vs_path(version):\n    \"\"\"\n    Given the Visual Studio version, returns the default path to the\n    Microsoft Visual Studio vcvarsall.bat file.\n    Expected versions are of the form {9.0, 10.0, 12.0, 14.0}\n    \"\"\"\n    # Set up a load of paths that can be imported from the tests\n    if 'ProgramFiles(x86)' in os.environ:\n        PROGRAM_FILES_PATH = os.environ['ProgramFiles(x86)']\n    else:\n        PROGRAM_FILES_PATH = os.environ['ProgramFiles']\n\n    flatversion = str(version).replace('.', '')\n    vstools = \"VS{0}COMNTOOLS\".format(flatversion)\n\n    if vstools in os.environ:\n        return os.path.join(os.environ[vstools], '..\\\\..\\\\VC\\\\vcvarsall.bat')\n    else:\n        # prefer looking at env var; fall back to program files defaults\n        return os.path.join(PROGRAM_FILES_PATH,\n                            'Microsoft Visual Studio {}'.format(version), 'VC',\n                            'vcvarsall.bat')\n\n\ndef msvc_env_cmd(bits, config, override=None):\n    arch_selector = 'x86' if bits == 32 else 'amd64'\n\n    msvc_env_lines = []\n\n    version = None\n    if override is not None:\n        version = override\n\n    # The DISTUTILS_USE_SDK variable tells distutils to not try and validate\n    # the MSVC compiler. For < 3.5 this still forcibly looks for 'cl.exe'.\n    # For > 3.5 it literally just skips the validation logic.\n    # See distutils _msvccompiler.py and msvc9compiler.py / msvccompiler.py\n    # for more information.\n    msvc_env_lines.append('set DISTUTILS_USE_SDK=1')\n    # This is also required to hit the 'don't validate' logic on < 3.5.\n    # For > 3.5 this is ignored.\n    msvc_env_lines.append('set MSSdk=1')\n\n    if not version:\n        if config.PY3K and config.use_MSVC2015:\n            version = '14.0'\n        elif config.PY3K:\n            version = '10.0'\n        else:\n            version = '9.0'\n\n    if float(version) >= 14.0:\n        # For Python 3.5+, ensure that we link with the dynamic runtime.  See\n        # http://stevedower.id.au/blog/building-for-python-3-5-part-two/ for more info\n        msvc_env_lines.append('set PY_VCRUNTIME_REDIST=%LIBRARY_BIN%\\\\vcruntime{0}.dll'.format(\n            version.replace('.', '')))\n\n    vcvarsall_vs_path = build_vcvarsall_vs_path(version)\n\n    def build_vcvarsall_cmd(cmd, arch=arch_selector):\n        # Default argument `arch_selector` is defined above\n        return 'call \"{cmd}\" {arch}'.format(cmd=cmd, arch=arch)\n\n    msvc_env_lines.append('set \"VS_VERSION={}\"'.format(version))\n    msvc_env_lines.append('set \"VS_MAJOR={}\"'.format(version.split('.')[0]))\n    msvc_env_lines.append('set \"VS_YEAR={}\"'.format(VS_VERSION_STRING[version][-4:]))\n    msvc_env_lines.append('set \"CMAKE_GENERATOR={}\"'.format(VS_VERSION_STRING[version] +\n                                                            {64: ' Win64', 32: ''}[bits]))\n    # tell msys2 to ignore path conversions for issue-causing windows-style flags in build\n    #   See https://github.com/conda-forge/icu-feedstock/pull/5\n    msvc_env_lines.append('set \"MSYS2_ARG_CONV_EXCL=/AI;/AL;/OUT;/out;%MSYS2_ARG_CONV_EXCL%\"')\n    msvc_env_lines.append('set \"MSYS2_ENV_CONV_EXCL=CL\"')\n    if version == '10.0':\n        try:\n            WIN_SDK_71_PATH = Reg.get_value(os.path.join(WINSDK_BASE, 'v7.1'),\n                                            'installationfolder')\n            WIN_SDK_71_BAT_PATH = os.path.join(WIN_SDK_71_PATH, 'Bin', 'SetEnv.cmd')\n\n            win_sdk_arch = '/Release /x86' if bits == 32 else '/Release /x64'\n            win_sdk_cmd = build_vcvarsall_cmd(WIN_SDK_71_BAT_PATH, arch=win_sdk_arch)\n\n            # There are two methods of building Python 3.3 and 3.4 extensions (both\n            # of which required Visual Studio 2010 - as explained in the Python wiki\n            # https://wiki.python.org/moin/WindowsCompilers)\n            # 1) Use the Windows SDK 7.1\n            # 2) Use Visual Studio 2010 (any edition)\n            # However, VS2010 never shipped with a 64-bit compiler, so in this case\n            # **only** option (1) applies. For this reason, we always try and\n            # activate the Windows SDK first. Unfortunately, unsuccessfully setting\n            # up the environment does **not EXIT 1** and therefore we must fall\n            # back to attempting to set up VS2010.\n            # DelayedExpansion is required for the SetEnv.cmd\n            msvc_env_lines.append('Setlocal EnableDelayedExpansion')\n            msvc_env_lines.append(win_sdk_cmd)\n            # If the WindowsSDKDir environment variable has not been successfully\n            # set then try activating VS2010\n            msvc_env_lines.append('if not \"%WindowsSDKDir%\" == \"{}\" ( {} )'.format(\n                WIN_SDK_71_PATH, build_vcvarsall_cmd(vcvarsall_vs_path)))\n        # sdk is not installed.  Fall back to only trying VS 2010\n        except KeyError:\n            msvc_env_lines.append(build_vcvarsall_cmd(vcvarsall_vs_path))\n    elif version == '9.0':\n        # Get the Visual Studio 2008 path (not the Visual C++ for Python path)\n        # and get the 'vcvars64.bat' from inside the bin (in the directory above\n        # that returned by distutils_find_vcvarsall)\n        try:\n            VCVARS64_VS9_BAT_PATH = os.path.join(os.path.dirname(distutils_find_vcvarsall(9)),\n                                                'bin', 'vcvars64.bat')\n        # there's an exception if VS or the VC compiler for python are not actually installed.\n        except (KeyError, TypeError):\n            VCVARS64_VS9_BAT_PATH = None\n\n        error1 = 'if errorlevel 1 {}'\n\n        # Prefer VS9 proper over Microsoft Visual C++ Compiler for Python 2.7\n        msvc_env_lines.append(build_vcvarsall_cmd(vcvarsall_vs_path))\n        # The Visual Studio 2008 Express edition does not properly contain\n        # the amd64 build files, so we call the vcvars64.bat manually,\n        # rather than using the vcvarsall.bat which would try and call the\n        # missing bat file.\n        if arch_selector == 'amd64' and VCVARS64_VS9_BAT_PATH:\n            msvc_env_lines.append(error1.format(\n                build_vcvarsall_cmd(VCVARS64_VS9_BAT_PATH)))\n        # Otherwise, fall back to icrosoft Visual C++ Compiler for Python 2.7+\n        # by using the logic provided by setuptools\n        msvc_env_lines.append(error1.format(\n            build_vcvarsall_cmd(distutils_find_vcvarsall(9))))\n    else:\n        # Visual Studio 14 or otherwise\n        msvc_env_lines.append(build_vcvarsall_cmd(vcvarsall_vs_path))\n\n    return '\\n'.join(msvc_env_lines) + '\\n'\n\n\ndef build(m, bld_bat, config):\n    with path_prepended(config.build_prefix):\n        env = environ.get_dict(config=config, m=m)\n    env[\"CONDA_BUILD_STATE\"] = \"BUILD\"\n\n    for name in 'BIN', 'INC', 'LIB':\n        path = env['LIBRARY_' + name]\n        if not isdir(path):\n            os.makedirs(path)\n\n    src_dir = config.work_dir\n    if os.path.isfile(bld_bat):\n        with open(bld_bat) as fi:\n            data = fi.read()\n        with open(join(src_dir, 'bld.bat'), 'w') as fo:\n            # more debuggable with echo on\n            fo.write('@echo on\\n')\n            for key, value in env.items():\n                fo.write('set \"{key}={value}\"\\n'.format(key=key, value=value))\n            fo.write(msvc_env_cmd(bits=bits, config=config,\n                                  override=m.get_value('build/msvc_compiler', None)))\n            # Reset echo on, because MSVC scripts might have turned it off\n            fo.write('@echo on\\n')\n            fo.write('set \"INCLUDE={};%INCLUDE%\"\\n'.format(env[\"LIBRARY_INC\"]))\n            fo.write('set \"LIB={};%LIB%\"\\n'.format(env[\"LIBRARY_LIB\"]))\n            if config.activate:\n                fo.write('call \"{conda_root}\\\\activate.bat\" \"{prefix}\"\\n'.format(\n                    conda_root=root_script_dir,\n                    prefix=config.build_prefix))\n            fo.write(\"REM ===== end generated header =====\\n\")\n            fo.write(data)\n\n        cmd = ['cmd.exe', '/c', 'bld.bat']\n        _check_call(cmd, cwd=src_dir)\n\n    fix_staged_scripts(join(config.build_prefix, 'Scripts'))\n", "path": "conda_build/windows.py"}]}