-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgetmodules.d
65 lines (48 loc) · 1.77 KB
/
getmodules.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
module getmodules;
import redub.plugin.api;
class GetModulePlugin : RedubPlugin
{
void preGenerate()
{
}
void postGenerate()
{
}
/**
* Simple utility file to get the source files used for a game project in Hipreme Engine.
* This utility may be replaced in the future to prefer dub describe --data=source-files
*/
extern(C) ref RedubPluginStatus preBuild(RedubPluginData input, out RedubPluginData output, const ref string[] args, ref return RedubPluginStatus status)
{
import std.file;
import std.path;
import std.array:replace;
if(args.length != 1)
return status = RedubPluginStatus(RedubPluginExitCode.error, "Usage: rdmd gemodules outputFileName");
string outputPath = args[0];
if(exists(outputPath) && isDir(outputPath))
return status = RedubPluginStatus(RedubPluginExitCode.error, "Invalid output path '"~outputPath~"', the output path is a directory");
if(outputPath.length == 0)
return status = RedubPluginStatus(RedubPluginExitCode.error, "Invalid output path '"~outputPath~"', the output path is empty.");
string getModulesFile;
foreach(string inputPath; input.sourcePaths)
foreach(DirEntry e; dirEntries(inputPath, "*.d", SpanMode.depth))
{
string file = e.name;
if(getModulesFile != "")
getModulesFile~="\n";
//Remove .d, change / or \ to .
file = relativePath(file, inputPath)[0..$-2];
getModulesFile~= file.replace('/', '.').replace('\\', '.');
}
string outDir = dirName(outputPath);
if(!std.file.exists(outDir))
std.file.mkdirRecurse(outDir);
std.file.write(outputPath, getModulesFile);
return status = RedubPluginStatus(RedubPluginExitCode.success, "getModule plugin generated file "~outputPath);
}
void postBuild()
{
}
}
mixin PluginEntrypoint!(GetModulePlugin);