This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

source: ps/trunk/build/premake/premake5/scripts/package.lua

Last change on this file was 24387, checked in by s0600204, 4 years ago

(1/2) Update premake5 to Alpha 15 - premake5 files

See CHANGES.txt below for the upstream-composed list of changes.

premake5.exe built by Stan

Accepted By: Stan (for Windows)
Trac Tickets: #5869
Differential Revision: https://code.wildfiregames.com/D3219

File size: 6.2 KB
Line 
1---
2-- Create a source or binary release package.
3---
4
5
6---
7-- Helper function: run a command while hiding its output.
8---
9
10 local function execQuiet(cmd, ...)
11 cmd = string.format(cmd, ...) .. " > _output_.log 2> _error_.log"
12 local z = os.execute(cmd)
13 os.remove("_output_.log")
14 os.remove("_error_.log")
15 return z
16 end
17
18
19---
20-- Check the command line arguments, and show some help if needed.
21---
22
23 local allowedCompilers = {}
24
25 if os.ishost("windows") then
26 allowedCompilers = {
27 "vs2019",
28 "vs2017",
29 "vs2015",
30 "vs2013",
31 "vs2012",
32 "vs2010",
33 "vs2008",
34 "vs2005",
35 }
36 elseif os.ishost("linux") or os.ishost("bsd") then
37 allowedCompilers = {
38 "gcc",
39 "clang",
40 }
41 elseif os.ishost("macosx") then
42 allowedCompilers = {
43 "clang",
44 }
45 else
46 error("Unsupported host os", 0)
47 end
48
49 local usage = 'usage is: package <branch> <type> [<compiler>]\n' ..
50 ' <branch> is the name of the release branch to target\n' ..
51 ' <type> is one of "source" or "binary"\n' ..
52 ' <compiler> (default: ' .. allowedCompilers[1] .. ') is one of ' .. table.implode(allowedCompilers, "", "", " ")
53
54 if #_ARGS ~= 2 and #_ARGS ~= 3 then
55 error(usage, 0)
56 end
57
58 local branch = _ARGS[1]
59 local kind = _ARGS[2]
60 local compiler = _ARGS[3] or allowedCompilers[1]
61
62 if kind ~= "source" and kind ~= "binary" then
63 print("Invalid package kind: "..kind)
64 error(usage, 0)
65 end
66
67 if not table.contains(allowedCompilers, compiler) then
68 print("Invalid compiler: "..compiler)
69 error(usage, 0)
70 end
71
72 local compilerIsVS = compiler:startswith("vs")
73
74--
75-- Make sure I've got what I've need to be happy.
76--
77
78 local required = { "git" }
79
80 if not compilerIsVS then
81 table.insert(required, "make")
82 table.insert(required, compiler)
83 end
84
85 for _, value in ipairs(required) do
86 local z = execQuiet("%s --version", value)
87 if not z then
88 error("required tool '" .. value .. "' not found", 0)
89 end
90 end
91
92
93--
94-- Figure out what I'm making.
95--
96
97 os.chdir("..")
98 local text = os.outputof(string.format('git show %s:src/host/premake.h', branch))
99 local _, _, version = text:find('VERSION%s*"([%w%p]+)"')
100
101 local pkgName = "premake-" .. version
102 local pkgExt = ".zip"
103
104 if not os.istarget("windows") and kind == "binary" then
105 pkgExt = ".tar.gz"
106 end
107
108
109--
110-- Make sure I'm sure.
111--
112
113 printf("")
114 printf("I am about to create a %s package", kind:upper())
115 printf(" ...named release/%s%s", pkgName, pkgExt)
116 printf(" ...from the %s branch", branch)
117 printf("")
118 printf("Does this look right to you? If so, press [Enter] to begin.")
119 io.read()
120
121
122--
123-- Pull down the release branch.
124--
125
126 print("Preparing release folder")
127 os.mkdir("release")
128 os.chdir("release")
129 os.rmdir(pkgName)
130
131 print("Cloning source code")
132 local z = execQuiet("git clone .. %s -b %s --recurse-submodules --depth 1 --shallow-submodules", pkgName, branch)
133 if not z then
134 error("clone failed", 0)
135 end
136
137 os.chdir(pkgName)
138
139--
140-- Bootstrap Premake in the newly cloned repository
141--
142
143 print("Bootstrapping Premake...")
144 if compilerIsVS then
145 z = os.execute("Bootstrap.bat " .. compiler)
146 else
147 z = os.execute("make -j -f Bootstrap.mak " .. os.host())
148 end
149 if not z then
150 error("Failed to Bootstrap Premake", 0)
151 end
152 local premakeBin = path.translate("./bin/release/premake5")
153
154
155--
156-- Make absolutely sure the embedded scripts have been updated
157--
158
159 print("Updating embedded scripts...")
160
161 local z = execQuiet("%s embed %s", premakeBin, iif(kind == "source", "", "--bytecode"))
162 if not z then
163 error("failed to update the embedded scripts", 0)
164 end
165
166
167--
168-- Generate a source package.
169--
170
171if kind == "source" then
172
173 local function genProjects(parameters)
174 if not execQuiet("%s %s", premakeBin, parameters) then
175 error("failed to generate project for "..parameters, 0)
176 end
177 end
178
179 os.rmdir("build")
180
181 print("Generating project files...")
182
183 local ignoreActions = {
184 "clean",
185 "embed",
186 "package",
187 "self-test",
188 "test",
189 "gmake", -- deprecated
190 }
191
192 local perOSActions = {
193 "gmake2",
194 "codelite"
195 }
196
197 for action in premake.action.each() do
198
199 if not table.contains(ignoreActions, action.trigger) then
200 if table.contains(perOSActions, action.trigger) then
201
202 local osList = {
203 { "windows", },
204 { "unix", "linux" },
205 { "macosx", },
206 { "bsd", },
207 }
208
209 for _, os in ipairs(osList) do
210 local osTarget = os[2] or os[1]
211 genProjects(string.format("--to=build/%s.%s --os=%s %s", action.trigger, os[1], osTarget, action.trigger))
212 end
213 else
214 genProjects(string.format("--to=build/%s %s", action.trigger, action.trigger))
215 end
216 end
217 end
218
219 print("Creating source code package...")
220
221 local excludeList = {
222 ".gitignore",
223 ".gitattributes",
224 ".gitmodules",
225 ".travis.yml",
226 ".editorconfig",
227 "appveyor.yml",
228 "Bootstrap.*",
229 "packages/*",
230 }
231 local includeList = {
232 "build",
233 "src/scripts.c",
234 }
235
236 if not execQuiet("git rm --cached -r -f --ignore-unmatch "..table.concat(excludeList, ' ')) or
237 not execQuiet("git add -f "..table.concat(includeList, ' ')) or
238 not execQuiet("git stash") or
239 not execQuiet("git archive --format=zip -9 -o ../%s-src.zip --prefix=%s/ stash@{0}", pkgName, pkgName) or
240 not execQuiet("git stash drop stash@{0}")
241 then
242 error("failed to archive release", 0)
243 end
244
245 os.chdir("..")
246end
247
248
249--
250-- Create a binary package for this platform. This step requires a working
251-- GNU/Make/GCC environment.
252--
253
254if kind == "binary" then
255
256 print("Building binary...")
257
258 os.chdir("bin/release")
259
260 local addCommand = "git add -f premake5%s"
261 local archiveCommand = "git archive --format=%s -o ../../../%s-%s%s stash@{0} -- ./premake5%s"
262
263 if os.ishost("windows") then
264 addCommand = string.format(addCommand, ".exe")
265 archiveCommand = string.format(archiveCommand, "zip -9", pkgName, os.host(), pkgExt, ".exe")
266 else
267 addCommand = string.format(addCommand, "")
268 archiveCommand = string.format(archiveCommand, "tar.gz", pkgName, os.host(), pkgExt, "")
269 end
270
271 if not execQuiet(addCommand) or
272 not execQuiet("git stash") or
273 not execQuiet(archiveCommand) or
274 not execQuiet("git stash drop stash@{0}")
275 then
276 error("failed to archive release", 0)
277 end
278
279 os.chdir("../../..")
280
281end
282
283
284--
285-- Clean up
286--
287
288 -- Use RMDIR token instead of os.rmdir to force remove .git dir which has read only files
289 execQuiet(os.translateCommands("{RMDIR} "..pkgName))
Note: See TracBrowser for help on using the repository browser.