This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
/
Tools.Bundlegen.bundle
143 lines (103 loc) · 3.2 KB
/
Tools.Bundlegen.bundle
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
# Self-hosting in the bundle generator! All right!
namespace Tools.Bundlegen {
using default;
using Core;
using Core.Tools;
using Core.Clr;
using Core.Install;
using Core.Config;
using !System.Text;
parameters {
basis Config = /config/tools/bundlegen;
basis Project = /project;
namespace Core;
namespace Core.Install;
namespace Core.Clr;
}
provider Config {
bundlegen_name = "!mb-bundlegen";
bundlegen_binary = FindTool (bundlegen_name) tags {
"prereq" = true;
};
mbuild_snk = ExtractMBuildSnkFile ();
enable_debug = ConfigBool(Core.Generic/enable_debug) tags {
"prompt" = "Generate debugging information for MBuild bundles?";
"config_group" = "Debugging";
};
}
rule BundlegenProcess : OutputFileRule {
BundlegenFileResult+ inputs;
DllAssembly* refs;
SystemDll* sysrefs;
TextFile* natives;
MBFile* resources;
string? language;
bool debug;
default MBString version;
BinaryInfo bundlegen;
StrongnameKeypairFile keyfile;
StrongnameProgram sn;
tags {
"default" = true;
"install" = Install.Config/libdir_installer;
}
build (DllAssembly dest, ctxt) @{
string destname = GetOutputName (ctxt);
if (destname == null)
return true;
dest.Dir = ctxt.WorkingDirectory;
dest.Name = destname;
StringBuilder sb = new StringBuilder ();
if (language != null)
sb.AppendFormat ("/lang:{0} ", language);
sb.AppendFormat ("/v:{0} ", version);
if (debug)
sb.Append ("/g ");
sb.AppendFormat ("/out:{0} ", dest.GetPath (ctxt));
sb.AppendFormat ("/keyfile:{0} ", keyfile.GetPath (ctxt));
// system references
for (int i = 0; i < sysrefs.Length; i++)
sb.AppendFormat ("/r:{0} ", sysrefs[i].Value);
// local references
for (int i = 0; i < refs.Length; i++)
sb.AppendFormat ("/r:{0} ", refs[i].GetPath (ctxt));
// native input files
for (int i = 0; i < natives.Length; i++)
sb.AppendFormat ("/n:{0} ", natives[i].GetPath (ctxt));
// resource files
for (int i = 0; i < resources.Length; i++)
sb.AppendFormat ("/resource:{0} ", resources[i].GetPath (ctxt));
// inputs
for (int i = 0; i < inputs.Length; i++)
sb.AppendFormat ("{0} ", inputs[i].GetPath (ctxt));
// run that mofo
if (Launcher.RunTool (bundlegen, sb.ToString (), ctxt,
"Bundlegen tool returned an error") != 0)
return true;
if (sn.StrongnameAssembly (dest, keyfile, ctxt)) {
dest.Delete (ctxt);
return true;
}
return false;
@}
} default {
debug = Config/enable_debug;
version = Project/version;
bundlegen = Config/bundlegen_binary;
keyfile = Config/mbuild_snk;
sn = Clr.Config/sn_program;
}
transform regex matcher "\\.bundle$" = BundlegenProcess;
result BundlegenFileResult : TextFile {}
sourcefile rule BundlegenFile = BundlegenFileResult;
dependency regex matcher "\\.bundle$" = BundlegenFile;
rule ExtractMBuildSnkFile : ExtractAssemblyResource {
default restype StrongnameKeypairFile;
@{
protected override string GetResourceName (IBuildContext ctxt)
{
return "mbuild.snk";
}
@}
}
}