This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
outdeps.d
101 lines (83 loc) · 2.1 KB
/
outdeps.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
/**
* C preprocessor
* Copyright: 2013 by Digital Mars
* License: $(LINK2 http://boost.org/LICENSE_1_0.txt, Boost License 1.0).
* Authors: Walter Bright
*/
module outdeps;
import std.stdio;
import std.path;
import std.range;
import textbuf;
version (Windows)
immutable string extObj = "obj";
else
immutable string extObj = "o";
/***************************************
* Format dependencies into OutputRange r.
* Formatting is separated from file writing so the former can be unittested.
*/
R dependencyFileFormat(R)(ref R r, string[] deps) if (isOutputRange!(R, char))
{
void puts(string s)
{
foreach (char c; s)
r.put(c);
}
void putln() { r.put('\n'); }
if (deps.length)
{
int col = 1;
string objfilename = setExtension(deps[0], extObj);
puts(objfilename);
puts(": ");
col += objfilename.length + 2;
foreach (dep; deps)
{
if (col >= 70)
{
puts(" \\");
putln();
col = 1;
}
r.put(' ');
puts(dep);
col += 1 + dep.length;
}
if (col > 1)
putln();
}
return r;
}
unittest
{
string[] deps = ["asdfasdf.d", "kjjksdkfj.d", "asdkjfksdfj.d",
"asdfasdf0.d", "kjjksdkfj0.d", "asdkjfksdfj0.d",
"asdfasdf1.d", "kjjksdkfj1.d", "asdkjfksdfj1.d",
];
char[1000] buf;
auto textbuf = Textbuf!char(buf);
textbuf.dependencyFileFormat(deps);
auto r = textbuf[0 .. textbuf.length];
//writefln("|%s|", r);
assert(r ==
"asdfasdf." ~ extObj ~ ": asdfasdf.d kjjksdkfj.d asdkjfksdfj.d asdfasdf0.d kjjksdkfj0.d \\
asdkjfksdfj0.d asdfasdf1.d kjjksdkfj1.d asdkjfksdfj1.d
");
textbuf.free();
}
/*************************************
* Write dependencies to filename.
*/
void dependencyFileWrite(string filename, string[] deps)
{
auto f = File(filename, "w");
auto w = f.lockingTextWriter();
dependencyFileFormat(w, deps);
}
/*
* Local Variables:
* mode: d
* c-basic-offset: 4
* End:
*/