|
1 | 1 | @echo OFF |
2 | | - |
3 | | -@rem Copyright (c) 2018 nexB Inc. http://www.nexb.com/ - All rights reserved. |
| 2 | +@setlocal |
| 3 | +@rem Copyright (c) nexB Inc. http://www.nexb.com/ - All rights reserved. |
4 | 4 |
|
5 | 5 | @rem ################################ |
6 | | -@rem # change these variables to customize this script locally |
| 6 | +@rem # A configuration script for Windows |
| 7 | +@rem # |
| 8 | +@rem # The options and (optional) arguments are: |
| 9 | +@rem # --clean : this is exclusive of anything else and cleans the environment |
| 10 | +@rem # from built and installed files |
| 11 | +@rem # |
| 12 | +@rem # --python < path to python.exe> : this must be the first argument and set |
| 13 | +@rem # the path to the Python executable to use. If < path to python.exe> is |
| 14 | +@rem # set to "path", then the executable will be the python.exe available |
| 15 | +@rem # in the PATH. |
| 16 | +@rem # |
| 17 | +@rem # <some conf path> : this must be the last argument and sets the path to a |
| 18 | +@rem # configuration directory to use. |
7 | 19 | @rem ################################ |
8 | | -@rem # you can define one or more thirdparty dirs, each prefixed with TPP_DIR |
9 | | -set TPP_DIR=thirdparty |
10 | 20 |
|
| 21 | +@rem ################################ |
| 22 | +@rem # Defaults. Change these variables to customize this script locally |
| 23 | +@rem ################################ |
| 24 | +@rem # you can define one or more thirdparty dirs, each where the varibale name |
| 25 | +@rem # is prefixed with TPP_DIR |
| 26 | +set "TPP_DIR=thirdparty" |
11 | 27 |
|
12 | 28 | @rem # default configurations |
13 | | -set CONF_DEFAULT="etc/conf" |
| 29 | +set "CONF_DEFAULT=etc/conf" |
| 30 | + |
| 31 | +@rem # default supported version for Python 3 |
| 32 | +set SUPPORTED_PYTHON3=3.6 |
| 33 | + |
14 | 34 | @rem ################################# |
15 | 35 |
|
16 | | -set ABOUT_ROOT_DIR=%~dp0 |
17 | | -@rem !!!!!!!!!!! ATTENTION !!!!! |
18 | | -@rem there is a space at the end of the set SCANCODE_CLI_ARGS= line ... |
19 | | -@rem NEVER remove this! |
20 | | -@rem otherwise, this script and scancode do not work. |
21 | | - |
22 | | -set ABOUT_CLI_ARGS= |
23 | | -@rem Collect/Slurp all command line arguments in a variable |
24 | | -:collectarg |
25 | | - if ""%1""=="""" ( |
26 | | - goto continue |
27 | | - ) |
28 | | - call set ABOUT_CLI_ARGS=%ABOUT_CLI_ARGS% %1 |
29 | | - shift |
30 | | - goto collectarg |
31 | | - |
32 | | -:continue |
33 | | - |
34 | | -@rem default configuration when no args are passed |
35 | | -if "%ABOUT_CLI_ARGS%"==" " ( |
36 | | - set ABOUT_CLI_ARGS="%CONF_DEFAULT%" |
37 | | - goto configure |
| 36 | +@rem python --version |
| 37 | +@rem python -c "import sys;print(sys.executable)" |
| 38 | + |
| 39 | + |
| 40 | +@rem Current directory where this .bat files lives |
| 41 | +set CFG_ROOT_DIR=%~dp0 |
| 42 | + |
| 43 | +@rem path where a configured Python should live in the current virtualenv if installed |
| 44 | +set CONFIGURED_PYTHON=%CFG_ROOT_DIR%Scripts\python.exe |
| 45 | + |
| 46 | +set PYTHON_EXECUTABLE= |
| 47 | + |
| 48 | +@rem parse command line options and arguments |
| 49 | +:collectopts |
| 50 | +if "%1" EQU "--help" (goto cli_help) |
| 51 | +if "%1" EQU "--clean" (set CFG_CMD_LINE_ARGS=--clean) && goto find_python |
| 52 | +if "%1" EQU "--python" (set PROVIDED_PYTHON=%~2) && shift && shift && goto collectopts |
| 53 | + |
| 54 | +@rem We are not cleaning: Either we have a provided configure config path or we use a default. |
| 55 | +if ""%1""=="""" ( |
| 56 | + set CFG_CMD_LINE_ARGS=%CONF_DEFAULT% |
| 57 | +) else ( |
| 58 | + set CFG_CMD_LINE_ARGS=%1 |
38 | 59 | ) |
39 | 60 |
|
40 | | -:configure |
41 | | -if not exist "c:\python27\python.exe" ( |
42 | | - echo( |
43 | | - echo On Windows, AboutCode requires Python 2.7.x 32 bits to be installed first. |
44 | | - echo( |
45 | | - echo Please download and install Python 2.7 ^(Windows x86 MSI installer^) version 2.7.10. |
46 | | - echo Install Python on the c: drive and use all default installer options. |
47 | | - echo Do NOT install Python v3 or any 64 bits edition. |
48 | | - echo Instead download Python from this url and see the README.rst file for more details: |
49 | | - echo( |
50 | | - echo https://www.python.org/ftp/python/2.7.15/python-2.7.15.msi |
51 | | - echo( |
52 | | - exit /b 1 |
| 61 | +@rem If we have a pre-configured Python in our virtualenv, reuse this as-is and run |
| 62 | +if exist ""%CONFIGURED_PYTHON%"" ( |
| 63 | + set PYTHON_EXECUTABLE=%CONFIGURED_PYTHON% |
| 64 | + goto run |
53 | 65 | ) |
54 | 66 |
|
55 | | -call c:\python27\python.exe "%ABOUT_ROOT_DIR%etc\configure.py" %ABOUT_CLI_ARGS% |
56 | | -if %errorlevel% neq 0 ( |
57 | | - exit /b %errorlevel% |
| 67 | +@rem If we have a command arg for Python use this as-is |
| 68 | +if ""%PROVIDED_PYTHON%""==""path"" ( |
| 69 | + @rem use a bare python available in the PATH |
| 70 | + set PYTHON_EXECUTABLE=python |
| 71 | + goto run |
58 | 72 | ) |
59 | | -if exist "%SCANCODE_ROOT_DIR%bin\activate" ( |
60 | | - "%SCANCODE_ROOT_DIR%bin\activate" |
| 73 | +if exist ""%PROVIDED_PYTHON%"" ( |
| 74 | + set PYTHON_EXECUTABLE=%PROVIDED_PYTHON% |
| 75 | + goto run |
| 76 | +) |
| 77 | + |
| 78 | + |
| 79 | +@rem otherwise we search for a suitable Python interpreter |
| 80 | +:find_python |
| 81 | + |
| 82 | +@rem First check the existence of the "py" launcher (available in Python 3) |
| 83 | +@rem if we have it, check if we have a py -3 installed with the good version or a py 2.7 |
| 84 | +@rem if not, check if we have an old py 2.7 |
| 85 | +@rem exist if all fails |
| 86 | + |
| 87 | +where py >nul 2>nul |
| 88 | +if %ERRORLEVEL% == 0 ( |
| 89 | + @rem we have a py launcher, check for the availability of our required Python 3 version |
| 90 | + py -3.6 --version >nul 2>nul |
| 91 | + if %ERRORLEVEL% == 0 ( |
| 92 | + set PYTHON_EXECUTABLE=py -3.6 |
| 93 | + ) else ( |
| 94 | + @rem we have no required python 3, let's try python 2: |
| 95 | + py -2 --version >nul 2>nul |
| 96 | + if %ERRORLEVEL% == 0 ( |
| 97 | + set PYTHON_EXECUTABLE=py -2 |
| 98 | + ) else ( |
| 99 | + @rem we have py and no python 3 and 2, exit |
| 100 | + echo * Unable to find an installation of Python. |
| 101 | + exit /b 1 |
| 102 | + ) |
| 103 | + ) |
| 104 | +) else ( |
| 105 | + @rem we have no py launcher, check for a default Python 2 installation |
| 106 | + if not exist ""%DEFAULT_PYTHON2%"" ( |
| 107 | + echo * Unable to find an installation of Python. |
| 108 | + exit /b 1 |
| 109 | + ) else ( |
| 110 | + set PYTHON_EXECUTABLE=%DEFAULT_PYTHON2% |
| 111 | + ) |
| 112 | +) |
| 113 | + |
| 114 | +:run |
| 115 | + |
| 116 | +@rem without this things may not always work on Windows 10, but this makes things slower |
| 117 | +set PYTHONDONTWRITEBYTECODE=1 |
| 118 | + |
| 119 | +call %PYTHON_EXECUTABLE% "%CFG_ROOT_DIR%etc\configure.py" %CFG_CMD_LINE_ARGS% |
| 120 | + |
| 121 | + |
| 122 | +@rem Return a proper return code on failure |
| 123 | +if %ERRORLEVEL% neq 0 ( |
| 124 | + exit /b %ERRORLEVEL% |
61 | 125 | ) |
62 | | -goto EOS |
| 126 | +endlocal |
63 | 127 |
|
64 | | -:EOS |
|
0 commit comments