Skip to content

Commit

Permalink
Windows: allow quoted batch file with standalone toolchain
Browse files Browse the repository at this point in the history
It will allow the batch files to be executed using quotes and found using
the PATH:

    "clang"
    "clang.cmd"
    "clang".cmd
    "<triple>-clang"

Regarding the local/temp variable:
 * I'm hoping the _ prefix makes the variable unique.
 * setlocal ensures that the batch file won't affect the caller's
   environment.
 * `set "_BIN_DIR="` prevents the variable from being inherited in the
   clang subprocess. The quotes are necessary because
   `set _BIN_DIR= && ...` would set _BIN_DIR to a single space.

Bug: android/ndk#616
Test: manual
Test: python.exe run_tests.py --rebuild ...
Change-Id: Iff37183de269931b96a6a8842578dd50d366ae31
  • Loading branch information
rprichard committed Jan 17, 2018
1 parent addc157 commit 02bf235
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions build/tools/make_standalone_toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,43 +246,43 @@ def make_clang_scripts(install_dir, triple, api, windows):
os.path.join(install_dir, 'bin', triple + '-clang++'))

if windows:
flags = '-target {} --sysroot %~dp0\\..\\sysroot'.format(target)
flags = '-target {}'.format(target)
flags += ' --sysroot %_BIN_DIR%..\\sysroot'
flags += ' -D__ANDROID_API__={}'.format(api)

clangbat_path = os.path.join(install_dir, 'bin/clang.cmd')
with open(clangbat_path, 'w') as clangbat:
clangbat.write(textwrap.dedent("""\
for pp_suffix in ('', '++'):
exe_name = 'clang{}{}.exe'.format(version_number, pp_suffix)
clangbat_text = textwrap.dedent("""\
@echo off
setlocal
call :find_bin
if "%1" == "-cc1" goto :L
%~dp0\\clang{version}.exe {flags} %*
if ERRORLEVEL 1 exit /b 1
goto :done
:L
rem target/triple already spelled out.
%~dp0\\clang{version}.exe %*
if ERRORLEVEL 1 exit /b 1
:done
""".format(version=version_number, flags=flags)))
clangbatpp_path = os.path.join(install_dir, 'bin/clang++.cmd')
with open(clangbatpp_path, 'w') as clangbatpp:
clangbatpp.write(textwrap.dedent("""\
@echo off
if "%1" == "-cc1" goto :L
%~dp0\\clang{version}++.exe {flags} %*
set "_BIN_DIR=" && %_BIN_DIR%{exe} {flags} %*
if ERRORLEVEL 1 exit /b 1
goto :done
:L
rem target/triple already spelled out.
%~dp0\\clang{version}++.exe %*
set "_BIN_DIR=" && %_BIN_DIR%{exe} %*
if ERRORLEVEL 1 exit /b 1
:done
""".format(version=version_number, flags=flags)))
goto :done
:find_bin
rem Accommodate a quoted arg0, e.g.: "clang"
rem https://github.com/android-ndk/ndk/issues/616
set _BIN_DIR=%~dp0
exit /b
shutil.copy2(os.path.join(install_dir, 'bin/clang.cmd'),
os.path.join(install_dir, 'bin', triple + '-clang.cmd'))
shutil.copy2(os.path.join(install_dir, 'bin/clang++.cmd'),
os.path.join(install_dir, 'bin', triple + '-clang++.cmd'))
:done
""".format(exe=exe_name, flags=flags))

for triple_prefix in ('', triple + '-'):
clangbat_path = os.path.join(
install_dir, 'bin',
'{}clang{}.cmd'.format(triple_prefix, pp_suffix))
with open(clangbat_path, 'w') as clangbat:
clangbat.write(clangbat_text)


def copy_gnustl_abi_headers(src_dir, dst_dir, gcc_ver, triple, abi,
Expand Down

0 comments on commit 02bf235

Please sign in to comment.