make_distribution_library.anubis
8.33 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
Preparing the official distribution.
(AP 2014-08-26)
read tools/basis.anubis
read system/files.anubis
read official_library.anubis
type CompileFor:
linux,
windows.
define One
do_one_file
(
String srcdir,
String dstdir,
String name
) =
with s = srcdir/name,
d = dstdir/name,
if copy_file(s,d) is
{
cant_read_file then print("Cannot read file '"+s+"'.\n")
cant_create_file then print("Cannot create file '"+d+"'.\n")
copy_error then print("Error while copying '"+s+"'.\n")
copy_file_mode_error then print("File mode error while copying '"+s+"'.\n")
copy_file_times_error then print("File time error while copying '"+s+"'.\n")
copy_ok(written) then print("'"+s+"' copied ("+to_decimal(written)+" bytes).\n")
}.
define One
do_file
(
String srcdir,
String dstdir,
String mask
) =
with l = directory_full_list(srcdir,mask,"",""),
//print("in '"+srcdir+"' with mask '"+mask+"' found "+length(l)+" files.\n");
map_forget((FileDescription fd) |-> (if fd is file(name,_,_,_)
then do_one_file(srcdir,dstdir,name)
else unique)
,l).
define One
do_for_item
(
CompileFor system,
String srcdir,
String dstdir,
AnubisSourceItem i
).
define One
do_directory
(
CompileFor system,
String srcdir,
String dstdir,
String name,
List(AnubisSourceItem) content
) =
with dname = dstdir/name,
if make_directory(dname,default_directory_mode) is
{
permission_denied then print("Cannot create directory '"+dname+"' (permission denied).\n"),
name_already_exists then (print("Directory '"+dname+"' already exists.\n");
map_forget((AnubisSourceItem i) |-> do_for_item(system,srcdir/name,dstdir/name,i),
content)),
too_many_links then print("Cannot create directory '"+dname+"' (too many links).\n"),
not_enough_room then print("Cannot create directory '"+dname+"' (not enough room).\n"),
read_only_file_system then print("Cannot create directory '"+dname+"' (read-only file system).\n"),
ok then (print("Directory '"+dname+"' created.\n");
map_forget((AnubisSourceItem i) |-> do_for_item(system,srcdir/name,dstdir/name,i),
content))
}.
define One
do_for_item
(
CompileFor system,
String srcdir,
String dstdir,
AnubisSourceItem i
) =
if i is directory(rel,name,content)
then (if rel:[r,e] then do_directory(system,srcdir,dstdir,name,content) else unique)
else if i is win32_file(_,_)
then if system is
{
linux then unique,
windows then (if rel(i):[r,e] then do_file(srcdir,dstdir,name(i)) else unique)
}
else (if rel(i):[r,e] then do_file(srcdir,dstdir,name(i)) else unique).
define Maybe(String)
is_anubis_dev
(
ByteArray path,
String dest_name
) =
with n = length(path),
if extract(path,n-10,n) = to_byte_array("anubis_dev")
then success(to_string(extract(path,0,n-10)+to_byte_array(dest_name)))
else failure.
define One
print_item
(
WStream fp,
AnubisSourceItem i,
String indent
).
define One
print_item_list
(
WStream fp,
List(AnubisSourceItem) l,
String indent
) =
if l is
{
[ ] then unique,
[h . t] then
(if rel(h):[r,e]
then
(
print_item(fp,h,indent);
print(fp,if t is [] then "\n" else ",\n")
)
else unique);
print_item_list(fp,t,indent)
}.
define One
print_item
(
WStream fp,
AnubisSourceItem i,
String indent
) =
if rel(i):[r,e]
then if i is
{
anubis_file(rel,name) then print(fp,indent+"anubis_file (\""+name+"\")"),
anubis_c_file(rel,name) then print(fp,indent+"anubis_c_file (\""+name+"\")"),
anubis_font(rel,name) then print(fp,indent+"anubis_font (\""+name+"\")"),
apg_file(rel,name) then print(fp,indent+"apg_file (\""+name+"\")"),
image(rel,name) then print(fp,indent+"image (\""+name+"\")"),
h_file(rel,name) then print(fp,indent+"h_file (\""+name+"\")"),
c_file(rel,name) then print(fp,indent+"c_file (\""+name+"\")"),
cpp_file(rel,name) then print(fp,indent+"cpp_file (\""+name+"\")"),
make_file(rel,name) then print(fp,indent+"make_file (\""+name+"\")"),
flex_file(rel,name) then print(fp,indent+"flex_file (\""+name+"\")"),
bison_file(rel,name) then print(fp,indent+"bison_file (\""+name+"\")"),
win32_file(rel,name) then print(fp,indent+"win32_file (\""+name+"\")"),
shell_file(rel,name) then print(fp,indent+"shell_file (\""+name+"\")"),
text_file(rel,name) then print(fp,indent+"text_file (\""+name+"\")"),
pdf_file(rel,name) then print(fp,indent+"pdf_file (\""+name+"\")"),
binary_file(rel,name) then print(fp,indent+"binary_file (\""+name+"\")"),
directory(rel,name,content) then print(fp,indent+"directory (\""+name+"\",\n"+indent+" [\n");
print_item_list(fp,content,indent+" ");
print(fp,indent+" ])")
}
else unique.
define One
generate_released_library_description
(
One u
) =
if file("library/official_released_library.anubis",new) is
{
failure then print("Cannot create file 'library/official_released_library.anubis'.\n"),
success(f) then with fp = (WStream)weaken(f),
print(fp,"\n The Anubis Project\n");
print(fp,"\n This file describes the official Anubis library as Anubis data.\n\n");
print(fp,"public type AnubisLibraryItem:\n");
print(fp," anubis_file (String name),\n");
print(fp," anubis_c_file (String name),\n");
print(fp," anubis_font (String name),\n");
print(fp," apg_file (String name),\n");
print(fp," image (String name),\n");
print(fp," text_file (String name),\n");
print(fp," pdf_file (String name),\n");
print(fp," directory (String name, List(AnubisLibraryItem) content).\n\n");
print(fp,"public define AnubisLibraryItem\n");
print(fp," the_official_Anubis_library\n =\n");
print_item(fp,the_official_Anubis_files," ");
print(fp,".\n\n")
}.
global define One
make_linux_tarball
(
List(String) args
) =
if get_environment_variable("HOME") is
{
failure then print("Cannot find your home directory.\n"),
success(home_dir) then
with main_name = name(the_official_Anubis_files), // for example "anubis.1.14"
src_dir = home_dir,
dest_dir = home_dir/"linux_tarball",
forget((String)make_directory(dest_dir));
do_for_item(linux,src_dir,dest_dir,the_official_Anubis_files);
forget((Maybe(Word8))execute(success(dest_dir),"tar",["-czf",main_name+".tar.gz",main_name]))
}.
global define One
make_distribution_library
(
List(String) args // not used
) =
with cdir = get_current_directory, // should be 'anubis_dev'
print("Current directory: "+cdir+"\n");
if is_anubis_dev(to_byte_array(cdir),"anubis_distrib") is
{
failure then print("'anbexec make_distribution_library' must be executed from within 'anubis_dev'.\n"),
success(ddir) then
generate_released_library_description(unique);
do_for_item(cdir,ddir,the_official_Anubis_library);
do_for_item(cdir,ddir,the_official_Anubis_documentation);
do_for_item(cdir,ddir,the_official_Anubis_server_certs);
do_for_item(cdir,ddir,the_official_Anubis_trusted_certs)
}.