This repository has been archived by the owner on Sep 14, 2022. It is now read-only.
/
deployD.d
executable file
·179 lines (147 loc) · 3.2 KB
/
deployD.d
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
#!/usr/bin/env rdmd
import std.stdio;
import std.file;
import std.path;
import std.exception;
import std.process;
auto SRC_GET_NAMES = ["dmd", "druntime", "phobos", "tools", "dub"];
auto SRC_BUILD_NAMES = ["dmd", "druntime", "phobos", "tools"];
void isDirOk(string path)
{
chdir(path);
}
void renewRepo(string path, string name, string url)
{
Exception err;
string bp_p_n = buildPath(path,name);
bool makeClone;
bool makePull;
writeln("checking ",bp_p_n);
err = collectException(isDirOk(bp_p_n));
if (err !is null)
{
writeln(" error. trying to recreate (clone will be done on success)");
makeClone = true;
collectException(mkdir(bp_p_n));
err = collectException(isDirOk(bp_p_n));
if (err !is null)
{
throw err;
}
} else {
writeln(" ok. going to pull updates");
makePull = true;
}
if (makeClone)
{
chdir(bp_p_n);
writeln("clonning ", url, " to ", bp_p_n);
auto pid = spawnProcess(["git", "clone", url, "."]);
if (wait(pid) != 0)
{
throw new Exception("error clonning "~ url);
}
writeln(" ok");
}
if (makePull)
{
chdir(bp_p_n);
auto pid = spawnProcess(["git", "checkout", "-f", "master"]);
if (wait(pid) != 0)
{
throw new Exception("error checking out master at "~ bp_p_n);
}
writeln("pulling ", url, " to ", bp_p_n);
pid = spawnProcess(["git", "pull"]);
if (wait(pid) != 0)
{
throw new Exception("error pulling updates for "~ name);
}
writeln(" ok");
}
}
void renewRepos(string path)
{
foreach (v; SRC_GET_NAMES)
{
renewRepo(path, v, r"https://github.com/dlang/"~v);
}
}
void buildTargetPrepareClones(
string src_root_dir,
string target_root_dir,
string target
)
{
foreach(v; SRC_BUILD_NAMES)
{
auto td = buildPath(target_root_dir, v);
mkdirRecurse(td);
chdir(td);
auto pid = spawnProcess(["git", "clone", buildPath(src_root_dir, v), "."]);
if (wait(pid) != 0)
{
throw new Exception("Couldn't clone source here: " ~ td);
}
pid = spawnProcess(["git", "checkout", target]);
if (wait(pid) != 0)
{
throw new Exception("Couldn't checkout "~ target~ " at "~ td);
}
}
}
void buildDMD(
string target_root_dir
)
{
auto tdmd = buildPath(target_root_dir, "dmd");
auto tlocal = buildPath(target_root_dir, "_local");
chdir(tdmd);
auto pid = spawnProcess(["rdmd", "src/build.d"]);
if (wait(pid) != 0)
{
throw new Exception("Couldn't build source here: " ~ tdmd);
}
pid = spawnProcess(
["rdmd", "src/build.d",
"install", "INSTALL="~tlocal]
);
if (wait(pid) != 0)
{
throw new Exception("Couldn't install dmd here: " ~ tlocal);
}
}
void buildTarget(
string src_root_dir,
string target_root_dir,
string target
)
{
buildTargetPrepareClones(
src_root_dir,
target_root_dir,
target
);
buildDMD(target_root_dir);
}
void main(string[] args)
{
auto wd = expandTilde("~/dlang");
writeln("UPDATING:");
writeln("==============================");
renewRepos(wd);
writeln("==============================");
string target;
if (args.length > 1)
{
target = args[1];
}
if (target == "")
{
writeln("target not selected. exiting.");
return;
}
writeln("selected target: ", target);
auto wd_target = buildPath(wd, "d_"~target);
buildTarget(wd, wd_target, target);
}