-
Notifications
You must be signed in to change notification settings - Fork 1
/
BuildDistro.lua
190 lines (148 loc) · 5.41 KB
/
BuildDistro.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
--[[
Will automatically generate all files from the current sources.
Takes three parameters:
- The destination directory, as a relative directory. Will create it if it does not exist.
- The Mercurial revision number to archive to the destination directory.
- The version number of the tutorials.
]]--
require("ex")
require "ufs"
require "lfs"
require "_FindFileInPath"
local baseDir, hgChangelist, versionNum = ...
if(#({...}) ~= 3) then
print("Not enough commandline parameters. You provided: " .. #({...}));
print("Paramters:")
print("\tDestination dir, relative to this path.")
print("\tMercurial revision to archive.")
print("\tVersion number of the SDK.")
return
end
local buildDirname = "Tutorial " .. versionNum
lfs.mkdir(baseDir);
local pathDestDir = ufs.path(baseDir) / buildDirname;
local destDir = tostring(pathDestDir);
lfs.mkdir(destDir);
local pathCurrent = ufs.current_path();
local pathDest = pathCurrent / destDir;
local pathBase = pathCurrent / baseDir;
-------------------------------------------
-- Use the other Lua script to copy the HTML and PDFs to the destination.
local CopyWebsite = assert(loadfile("CopyWebsite.lua"));
CopyWebsite(destDir .. "\\html\\");
--Generate the PDF files.
local pdfOutDir = "..\\..\\" .. destDir .. "\\"
local cwd = lfs.currentdir();
lfs.chdir("Documents\\Build");
local BuildPrintBW = assert(loadfile("BuildPrintBWFO.lua"));
BuildPrintBW(pdfOutDir);
local BuildKindleFO = assert(loadfile("BuildKindleFO.lua"));
BuildKindleFO(pdfOutDir);
local BuildComputerFO = assert(loadfile("BuildComputerFO.lua"));
BuildComputerFO(pdfOutDir);
lfs.chdir(cwd);
------------------------------------------
-- Use Mercurial to get a version in the destination directory.
local clone = [[hg archive -r "%s" "%s"]];
clone = clone:format(hgChangelist, destDir);
print(clone);
os.execute(clone);
---------------------------------------------------------------
-- Install the dependencies.
local luaFilename = "lua.exe"
local pathLua = ufs.path(FindFileInPath(luaFilename))
local luaDepScriptName = "get_externals.lua"
ufs.current_path(pathDest);
local depProc = ex.spawn(tostring(pathLua),
{args={luaDepScriptName}});
depProc:wait(depProc);
---------------------------------------------------------------
-- Apply Copyright Info
local luaCopyScriptName = "make_copyright.lua"
if(pathLua:empty()) then
print("Could not find Lua. Since this is a Lua script, that's kinda confusing...");
return;
end
ufs.current_path(pathCurrent);
local copyProc = ex.spawn(tostring(pathLua),
{args={luaCopyScriptName, tostring(pathDest)}});
copyProc:wait(copyProc);
-------------------------------------------
-- Generate the ancillary files
--Readme.txt
local readme = io.open(destDir .. "\\readme.txt", "wt");
readme:write(string.format(
[===[
OpenGL Tutorials, version %s
This is a series of tutorials on using OpenGL to do graphical rendering.
The code for each tutorial is found in the "Tut *" directories. The code
alone is not enough information to understand what is going on. The actual
documentation is available in several forms.
The HTML form of the documentation can be found by opening the "index.html"
file. There are 3 PDF forms of the documentation. TutorialsComp.pdf is a PDF
that uses very thin margins; it is useful for display on computers (or
tablets). TutorialsPrintBW.pdf is a PDF designed for printing on a black-and-white
printer. TutorialsKindle.pdf is a PDF that is sized specifically for the screen
of the Kindle 2.
The License.txt file contains the licensing information for the materials distributed in these tutorials.
]===], versionNum))
readme:close()
--Version.txt
local version = io.open(destDir .. "\\version.txt", "wt");
version:write(string.format(
[===[
OpenGL Tutorials.
Version %s
]===]
, versionNum))
version:close();
--Index.html
local index_html = io.open(destDir .. "\\index.html", "wt");
index_html:write(
[===[
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta HTTP-EQUIV="REFRESH" content="0; url=html/index.html"/>
</head>
<body>
</body>
]===]
)
index_html:close();
------------------------------------------------------------
-- Delete select files from the destination location.
local toDelete =
{
--files
--Distro building
"BuildDistro.lua", "CopyWebsite.lua",
"_FindFileInPath.lua", "file_copyright_info.lua", "make_copyright.lua",
--Mercurial
".hgignore", ".hgtags", ".hg_archival.txt",
--directories
"glimg\\Test", "glload\\Test", "glload\\codegen",
"Documents", "Meshes",
}
for i, filename in ipairs(toDelete) do
local pathFile = pathDest / filename;
print("deleting:", pathFile);
ufs.remove_all(pathFile);
end
------------------------------------------------------------
-- Create Zip archive of the distro.
local szFilename = "7z.exe"
local archiveName = buildDirname .. ".7z"
local pathSZ = ufs.path(FindFileInPath(szFilename))
if(pathSZ:empty()) then
print("Could not find 7zip.");
return;
end
ufs.current_path(pathBase);
local zipProc = ex.spawn(tostring(pathSZ),
{args={"a", "-r", archiveName, buildDirname}});
zipProc:wait(zipProc);
------------------------------------------------------------
-- Destroy the directory.
ufs.remove_all(pathDest);