]> gitweb.factorcode.org Git - factor.git/blob - build.cmd
scryfall: better moxfield words
[factor.git] / build.cmd
1 @echo off
2 setlocal
3
4 goto start
5
6 :download
7 rem branch url filename
8 echo Fetching %1 boot image from %2
9 cscript /nologo misc\http-get.vbs %2 %3
10 exit /b
11
12 :start
13 : Check which branch we are on, or just assume master if we are not in a git repository
14 for /f %%z in ('git rev-parse --abbrev-ref HEAD') do set GIT_BRANCH=%%z
15 if not defined GIT_BRANCH (
16     set GIT_BRANCH=master
17 )
18
19 if "%1"=="/?" (
20     goto usage
21 ) else if "%1"=="" (
22     set _git_pull=1
23     set _compile_vm=1
24     set _bootimage_type=download
25     set _bootstrap_factor=1
26 ) else if "%1"=="latest" (
27     set _git_pull=1
28     set _compile_vm=1
29     set _bootimage_type=download
30     set _bootstrap_factor=1
31 ) else if "%1"=="update" (
32     set _git_pull=1
33     set _compile_vm=1
34     set _bootimage_type=download
35     set _bootstrap_factor=1
36 ) else if "%1"=="compile" (
37     set _git_pull=0
38     set _compile_vm=1
39     set _bootimage_type=current
40     set _bootstrap_factor=0
41 ) else if "%1"=="self-bootstrap" (
42     set _git_pull=1
43     set _compile_vm=0
44     set _bootimage_type=make
45     set _bootstrap_factor=1
46 ) else if "%1"=="bootstrap" (
47     set _git_pull=0
48     set _compile_vm=0
49     set _bootimage_type=current
50     set _bootstrap_factor=1
51 ) else if "%1"=="net-bootstrap" (
52     set _git_pull=0
53     set _compile_vm=1
54     set _bootimage_type=download
55     set _bootstrap_factor=1
56 ) else if "%1"=="update-boot-image" (
57     set _git_pull=0
58     set _compile_vm=0
59     set _bootimage_type=download
60     set _bootstrap_factor=0
61 ) else goto usage
62
63 if not exist Nmakefile goto wrongdir
64
65 call cl 2>&1 | find "x86" >nul
66 if not errorlevel 1 (
67     echo x86-32 cl.exe detected.
68     set _target=x86-32
69     set _bootimage=boot.windows-x86.32.image
70 ) else (
71     call cl 2>&1 | find "x64" >nul
72     if not errorlevel 1 (
73         echo x86-64 cl.exe detected.
74         set _target=x86-64
75         set _bootimage=boot.windows-x86.64.image
76     ) else goto nocl
77 )
78
79 echo Deleting staging images from temp/...
80 del temp\staging.*.image
81
82 if "%_git_pull%"=="1" (
83     echo Updating working copy from %GIT_BRANCH%...
84     call git pull https://github.com/factor/factor %GIT_BRANCH%
85     if errorlevel 1 goto fail
86 )
87
88 if "%_compile_vm%"=="1" (
89     echo Building vm...
90     nmake /nologo /f Nmakefile clean
91     if errorlevel 1 goto fail
92
93     nmake /nologo /f Nmakefile %_target%
94     if errorlevel 1 goto fail
95 )
96
97 set _bootimage_url=https://downloads.factorcode.org/images/%GIT_BRANCH%/%_bootimage%
98 if "%_bootimage_type%"=="download" (
99     call :download %GIT_BRANCH% %_bootimage_url% %_bootimage%
100     if errorlevel 1 (
101         echo boot image for branch %GIT_BRANCH% is not on server, trying master instead
102         call :download master https://downloads.factorcode.org/images/master/%_bootimage% %_bootimage%
103     )
104     if errorlevel 1 goto fail
105 ) else if "%_bootimage_type%"=="make" (
106     echo Making boot image...
107     .\factor.com -run=bootstrap.image %_bootimage%
108     if errorlevel 1 goto fail
109 )
110
111 if "%_bootstrap_factor%"=="1" (
112     echo Bootstrapping...
113     .\factor.com -i=%_bootimage%
114     if errorlevel 1 goto fail
115
116     echo Copying fresh factor.image to factor.image.fresh.
117     copy factor.image factor.image.fresh
118     if errorlevel 1 goto fail
119 )
120
121 echo Build complete.
122 goto :EOF
123
124 :fail
125 echo Build failed.
126 goto :EOF
127
128 :wrongdir
129 echo build.cmd must be run from the root of the Factor source tree.
130 goto :EOF
131
132 :nocl
133 echo Unable to detect cl.exe target platform.
134 echo Make sure you're running within the Visual Studio or Windows SDK environment.
135 goto :EOF
136
137 :usage
138 echo Usage: build.cmd [command]
139 echo     Updates the working copy, cleans and builds the vm using nmake,
140 echo     fetches a boot image, and bootstraps factor.
141 echo:
142 echo     The branch that bootstraps is the one that is checked out locally.
143 echo:
144 echo     compile - recompile vm
145 echo     update - git pull, recompile vm, download a boot image, bootstrap
146 echo     self-bootstrap - git pull, make a boot image, bootstrap
147 echo     bootstrap - existing boot image, bootstrap
148 echo     net-bootstrap - recompile vm, download a boot image, bootstrap
149 echo     update-boot-image - get the boot image for the current branch
150 goto :EOF