|
1 | 1 | @echo OFF |
| 2 | +setlocal |
| 3 | +@rem Copyright (c) nexB Inc. http://www.nexb.com/ - All rights reserved. |
2 | 4 |
|
3 | | -@rem Copyright (c) 2015-2018 nexB Inc. http://www.nexb.com/ - All rights reserved. |
| 5 | +@rem ################################ |
| 6 | +@rem # A configuration script for Windows |
| 7 | +@rem # The possible options and arguments are: |
| 8 | +@rem # --clean : this is exclusive of anything else and cleans the environment |
| 9 | +@rem # from built and installed files |
| 10 | +@rem # <some conf path> : this must be the last argument and sets the path to a |
| 11 | +@rem # configuration directory to use. |
| 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 ################################ |
4 | 17 |
|
5 | 18 | @rem ################################ |
6 | | -@rem # change these variables to customize this script locally |
| 19 | +@rem # Defaults. Change these variables to customize this script locally |
7 | 20 | @rem ################################ |
8 | 21 | @rem # you can define one or more thirdparty dirs, each prefixed with TPP_DIR |
9 | | -set TPP_DIR_BASE=thirdparty/base |
10 | | -set TPP_DIR_PROD=thirdparty/prod |
11 | | -set TPP_DIR_DEV=thirdparty/dev |
| 22 | +set TPP_DIR=thirdparty |
12 | 23 |
|
| 24 | +@rem # A fallback Python location. |
| 25 | +@rem # To use a given interpreter, you should use the --python option with a |
| 26 | +@rem # value pointing to your Python executable |
| 27 | +set DEFAULT_PYTHON=C:\Python27\python.exe |
13 | 28 |
|
14 | 29 | @rem # default configurations for dev |
15 | | -set CONF_DEFAULT="etc/conf/dev" |
| 30 | +set "CONF_DEFAULT=etc/conf/dev" |
16 | 31 | @rem ################################# |
17 | 32 |
|
18 | | -set CFG_CMD_LINE_ARGS= |
19 | | -@rem Collect/Slurp all command line arguments in a variable |
20 | | -:collectarg |
21 | | - if ""%1""=="""" ( |
22 | | - goto continue |
23 | | - ) |
24 | | - call set CFG_CMD_LINE_ARGS=%CFG_CMD_LINE_ARGS% %1 |
25 | | - shift |
26 | | - goto collectarg |
| 33 | +set CFG_ROOT_DIR=%~dp0 |
| 34 | + |
| 35 | +set CONFIGURED_PYTHON=%CFG_ROOT_DIR%Scripts\python.exe |
| 36 | + |
| 37 | +set "CFG_CMD_LINE_ARGS= " |
| 38 | + |
| 39 | +python --version |
| 40 | +python -c "import sys;print(sys.executable)" |
| 41 | + |
27 | 42 |
|
28 | | -:continue |
| 43 | +@rem parse command line options and arguments |
| 44 | +if ""%1""=="""" ( |
| 45 | + set CFG_CMD_LINE_ARGS=%CONF_DEFAULT% |
| 46 | + goto python |
| 47 | +) |
| 48 | + |
| 49 | +if ""%1""==""--clean"" ( |
| 50 | + set CFG_CMD_LINE_ARGS=--clean |
| 51 | + goto python |
| 52 | +) |
29 | 53 |
|
30 | | -@rem default to dev configuration when no args are passed |
31 | | -if "%CFG_CMD_LINE_ARGS%"==" " ( |
32 | | - set CFG_CMD_LINE_ARGS="%CONF_DEFAULT%" |
33 | | - goto configure |
| 54 | + |
| 55 | +if ""%1""==""--python"" ( |
| 56 | + set PROVIDED_PYTHON=%2 |
| 57 | + if ""%3""=="""" ( |
| 58 | + set CFG_CMD_LINE_ARGS=%CONF_DEFAULT% |
| 59 | + ) else ( |
| 60 | + set CFG_CMD_LINE_ARGS=%3 |
| 61 | + ) |
| 62 | + goto python |
| 63 | +) else ( |
| 64 | + set CFG_CMD_LINE_ARGS=%1 |
| 65 | + goto python |
34 | 66 | ) |
35 | 67 |
|
36 | | -if "%CFG_CMD_LINE_ARGS%"==" --init" ( |
37 | | - set CFG_CMD_LINE_ARGS="%CONF_INIT%" |
38 | | - goto configure |
| 68 | + |
| 69 | +@rem Pick a Python interpreter |
| 70 | +:python |
| 71 | + |
| 72 | +if exist "%CONFIGURED_PYTHON%" ( |
| 73 | + if not ""%1""==""--clean"" ( |
| 74 | + @rem we do not want to use the configured Python in clean... it will be deleted |
| 75 | + set PYTHON_EXECUTABLE=%CONFIGURED_PYTHON% |
| 76 | + goto run |
| 77 | + ) |
39 | 78 | ) |
40 | 79 |
|
41 | | -:configure |
42 | | -call c:\Python27\python.exe etc/configure.py %CFG_CMD_LINE_ARGS% |
43 | | -if exist bin\activate ( |
44 | | - bin\activate |
| 80 | +if ""%PROVIDED_PYTHON%""==""path"" ( |
| 81 | + @rem use a bare python available in the PATH |
| 82 | + set PYTHON_EXECUTABLE=python |
| 83 | + goto run |
45 | 84 | ) |
46 | | -goto EOS |
47 | 85 |
|
48 | | -:EOS |
| 86 | +if exist "%PROVIDED_PYTHON%" ( |
| 87 | + set PYTHON_EXECUTABLE=%PROVIDED_PYTHON% |
| 88 | + goto run |
| 89 | +) |
| 90 | + |
| 91 | +if exist %DEFAULT_PYTHON% ( |
| 92 | + set PYTHON_EXECUTABLE=%DEFAULT_PYTHON% |
| 93 | + goto run |
| 94 | +) |
| 95 | + |
| 96 | +if not exist "%PYTHON_EXECUTABLE%" ( |
| 97 | + echo * Unable to find an installation of Python. |
| 98 | + exit /b 1 |
| 99 | +) |
| 100 | + |
| 101 | +:run |
| 102 | + |
| 103 | +call ""%PYTHON_EXECUTABLE%"" "%CFG_ROOT_DIR%etc\configure.py" %CFG_CMD_LINE_ARGS% |
| 104 | + |
| 105 | +@rem Return a proper return code on failure |
| 106 | +if %errorlevel% neq 0 ( |
| 107 | + exit /b %errorlevel% |
| 108 | +) |
| 109 | + |
| 110 | +@rem Activate the virtualenv |
| 111 | +endlocal |
| 112 | +if exist "%CFG_ROOT_DIR%Scripts\activate" ( |
| 113 | + "%CFG_ROOT_DIR%Scripts\activate" |
| 114 | +) |
0 commit comments