-
-
Notifications
You must be signed in to change notification settings - Fork 702
/
build_v3.d
executable file
·140 lines (122 loc) · 3.02 KB
/
build_v3.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
#!/usr/bin/env rdmd
/**
Phobos V3 Build Script
Usage:
./build_v3.d [debug,release,unittest]
*/
import std.conv;
import std.datetime;
import std.file;
import std.path;
import std.process;
import std.stdio;
import std.string;
int main(string[] args)
{
int result = 0;
bool buildUnittest = false;
bool buildRelease = false;
if (args.length > 1)
{
buildUnittest = args[1] == "unittest";
buildRelease = args[1] == "release";
}
string argFilePath = buildNormalizedPath(getcwd(), "phobosbuildargs.txt");
auto dFiles = dirEntries(buildNormalizedPath(getcwd(), "phobos"), "*.d", SpanMode.breadth);
auto argFile = File(argFilePath, "w");
version(Windows)
{
string unittestExecutable = buildNormalizedPath(getcwd(), "unittest.exe");
}
else
{
string unittestExecutable = buildNormalizedPath(getcwd(), "unittest");
}
scope(exit)
{
argFile.close();
remove(argFilePath);
if (exists(unittestExecutable)) remove(unittestExecutable);
}
result = runCommand("dmd --version", getcwd());
if (result != 0)
{
writeln("Compiler Failure.");
return result;
}
writeln("Source files:");
//Add source file list to args file.
foreach(dFile; dFiles)
{
if (dFile.isDir()) continue;
argFile.writeln(dFile.name);
writeln(dFile.name);
}
//Add appropriate DMD arguments to the args file.
argFile.writeln("-od=./lib");
if (buildUnittest)
{
argFile.writeln("-main");
argFile.writeln("-unittest");
argFile.writeln("-debug");
version(Windows)
{
argFile.writeln("-of=unittest.exe");
}
else
{
argFile.writeln("-of=unittest");
}
}
else if (buildRelease)
{
argFile.writeln("-release -O");
argFile.writeln("-lib");
argFile.writeln("-of=libphobos3");
}
else
{
argFile.writeln("-debug");
argFile.writeln("-lib");
argFile.writeln("-of=libphobos3-debug");
}
argFile.flush();
argFile.close();
//Run the build.
result = runCommand("dmd @\"" ~ argFilePath ~ "\"", getcwd());
if (result != 0)
{
writeln("Build failed.");
return result;
}
else
{
writeln("Build successful.");
writeln();
}
//Run unittests if built.
if (buildUnittest)
{
writeln("Running tests...");
result = runCommand(unittestExecutable, getcwd());
if (result != 0)
{
writeln("Tests failed.");
return result;
}
else
{
writeln("Tests successful.");
}
}
return result;
}
private int runCommand(string command, string workDir)
{
auto pid = pipeShell(command, Redirect.all, null, Config.none, workDir);
int result = wait(pid.pid);
foreach (line; pid.stdout.byLine) writeln(line);
foreach (line; pid.stderr.byLine) writeln(line);
writeln();
return result;
}