-
Notifications
You must be signed in to change notification settings - Fork 27
/
.emanate
299 lines (231 loc) · 8.97 KB
/
.emanate
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
"use strict";
//sudo emanate --miner --miner-debug
//const KASPA_DEFAULT_BRANCH = 'v0.11.7-dev'; //'master';
const KASPA_DEFAULT_BRANCH = 'master';
const MINER_DEFAULT_BRANCH = 'main';
const E = new Emanator(__dirname, {
type : argv.includes('build') || flags.innosetup ? 'NODE+NWJS' : 'UTIL',
guid : 'c1072045-6d98-44d8-9aa5-e9be6c79bd01',
group : 'Kaspa',
ident : 'kdx',
suffix : flags.full ? '-dev' : '',
title : 'KDX',
banner : 'KDX',
git : '[email protected]:aspectron/kdx',
author : "ASPECTRON Inc.",
url : "http://aspectron.com",
//archive : true,
folder : true,
standalone : true,
production: true,
//DMG: true,
nwjs : { version : '0.55.0' },
resources : 'resources/setup',
manifest : (manifest) => {
if(E.flags['with-perfmon'] && !E.flags['no-perfmon']) {
if(E.PLATFORM != 'macos') {
Object.assign(manifest.dependencies,{
"@aspectron/process-list": "*",
})
}
}
// if(E.PLATFORM == 'macos')
// manifest.files.push('apps');
return manifest;
},
})
E.flags['with-perfmon'] = true;
if(E.flags.miner){
E.flags.nonpm = true;
E.options.nonpm = true;
}
E.aux_dmg_files = async (root) => {
if(fs.existsSync(path.join(E.BUILD,'apps')))
await E.copy(path.join(E.BUILD,'apps'),path.join(root,'apps'));
// E.copy(process.argv[0], root);
}
const go = await E.modules.go('go1.16.0');
const cargo = await E.modules.cargo('1.59.0');
const git = await E.modules.git();
const gcc = await E.modules.gcc();
const npm = await E.modules.npm({ production : true });
const kaspad = E.task('kaspad', ['origin'], async () => {
//return true;
if(E.PLATFORM == 'windows') {
process.env.PATH = ['C:\\TDM-GCC-64\\bin', ...process.env.PATH.split(';')].join(';');
}
let dest = path.join(go.SRC,'github.com/kaspanet/');
if((E.flags.reset || E.flags.clean) && fs.existsSync(dest))
await E.emptyDir(dest);
const branch = E.flags['branch'] || KASPA_DEFAULT_BRANCH || 'master';
console.log('branch:',branch);
//const repos = { };
const repos = [`kaspad:${branch}`];
if(E.flags['with-extras']) {
repos.push(`txgen:${branch}`,`kasparov:${KASPA_DEFAULT_BRANCH}`);
}
console.log("REPOS:".brightMagenta,repos);
for(const repo of repos) {
let [name, git_branch] = repo.split(':');
console.log(`git clone https://github.com/kaspanet/${name} branch: ${git_branch || 'master'}`.brightYellow);
await git.clone(`https://github.com/kaspanet/${name}`,dest, {branch : git_branch || 'master'});
}
let targets = [
'kaspad',
...fs.readdirSync(path.join(dest,'kaspad/cmd')).map(f => `kaspad/cmd/${f}`),
];
let rename = {}
console.log('Starting target processing...')
let folders = []
for(let target of targets) {
let folder = path.join(dest,target);
console.log('builing',folder);
await go.build(folder);
console.log('done',folder);
folders.push(folder);
}
folders.forEach((folder) => {
let file = path.basename(folder);
let name = `${E.title} ${file}`;
let dest = rename[file] || file;
file += E.PLATFORM_BINARY_EXTENSION;
dest += E.PLATFORM_BINARY_EXTENSION;
if(!fs.existsSync(path.join(folder,file))) {
console.log(`Unable to locate source file: ${path.join(folder,file)}`);
console.log(`...giving up`);
process.exit(1);
}
console.log("E.copy:", path.join(folder,file)," -> ",path.join(E.BIN,dest))
E.copy(path.join(folder,file),path.join(E.BIN,dest));
E.registerFirewallRule({ name, file : dest, binary : true });
})
//E.copy(path.join(dest,'kasparov','database','migrations'),path.join(E.BIN,'database','migrations'));
});
const miner = E.task('miner', ['origin'], async () => {
//return true;
if(E.PLATFORM == 'windows') {
process.env.PATH = ['C:\\TDM-GCC-64\\bin', ...process.env.PATH.split(';')].join(';');
}
let account = 'aspectron';//'tmrlvi';
let dest = path.join(cargo.SRCGITHUB, account);
if((E.flags.reset || E.flags.clean) && fs.existsSync(dest))
await E.emptyDir(dest);
const branch = E.flags['miner-branch'] || MINER_DEFAULT_BRANCH || 'main';
console.log('miner branch:', branch);
console.log('miner dest:', dest);
//const repos = { };
const repos = [`kaspa-miner:${branch}`];
console.log("REPOS:".brightMagenta,repos);
for(const repo of repos) {
let [name, git_branch] = repo.split(':');
console.log(`git clone https://github.com/${account}/${name} branch: ${git_branch || 'master'}`.brightYellow);
await git.clone(`https://github.com/${account}/${name}`, dest, {branch : git_branch || 'master'});
}
let minerDest = path.join(dest, "kaspa-miner");
console.log('Starting miner build processing...')
let release = !E.flags['miner-debug'];
let args = {
release,
p:['kaspa-miner']
}
// if(E.PLATFORM != 'macos'){
// args.p.push('kaspacuda', 'kaspaopencl');
// if(E.flags['miner-overclock'])
// args.features = "default,kaspacuda/overclock";
// }
await cargo.build(minerDest, args);
let targetFolder = path.join(minerDest, 'target', release?'release':'debug');
let file = 'kaspa-miner';
let name = `${E.title} ${file}`;
file += E.PLATFORM_BINARY_EXTENSION;
let rename = "gpuminer"+E.PLATFORM_BINARY_EXTENSION;
let files = new Map();
files.set(file, rename)
// if(E.PLATFORM == 'windows'){
// files.set('kaspacuda.dll', 0)
// files.set('kaspaopencl.dll', 0)
// }else if(E.PLATFORM == 'linux'){
// files.set('kaspacuda.so', 0)
// files.set('kaspaopencl.so', 0)
// }
files.forEach((destName, srcName)=>{
if(!destName)
destName = srcName;
let src = path.join(targetFolder, srcName);
let dest = path.join(E.BIN, destName);
//console.log("src", src)
//console.log("dest", dest)
if(!fs.existsSync(src)) {
console.log(`Unable to locate source file: ${src}`);
console.log(`...giving up`);
process.exit(1);
}
console.log("E.copy:", src, " -> ", dest)
E.copy(src, dest);
E.registerFirewallRule({ name, file : destName, binary : true });
})
//E.copy(path.join(dest,'kasparov','database','migrations'),path.join(E.BIN,'database','migrations'));
});
E.task('remote', ['origin'], async () => {
let files = (E.manifest.files||[]).map(f=>{
// console.log(E.REPO,'->',E.BUILD, f);
return E.copy(path.join(E.REPO,f), path.join(E.BUILD, f));
})
E.log(`copying ${files.length} items...`);
await Promise.all(files);
fs.writeFileSync(path.join(E.BUILD,'i18n.lock'),'');
console.log(`i18n.lock`);
})
if(!E.flags.miner){
const aux_deps = E.flags.auxiliary ? ['kaspad','remote'] : ['kaspad', 'miner']
E.task('done', aux_deps, async () => {
})
}
E.task('aptitude', null, async () => {
if(E.PLATFORM != 'linux')
return;
})
E.flags.docker && E.task('docker', null, async () => {
E.manifest_read();
const relay = ['no-cache'];
const args = ['-s','docker','build'].concat(relay.map(k=>E.flags[k]?`--${k}`:null)).filter(v=>v);
args.push('-t',`kdx:latest`,'.');
const ts0 = Date.now();
await E.utils.spawn('sudo', args, { cwd : __dirname, stdio: 'inherit' });
await E.utils.spawn('sudo',['docker','tag','kdx:latest',`kdx:${E.manifest.version}`], { cwd : __dirname, stdio: 'inherit' });
console.log('Docker build complete at',new Date());
const ts1 = Date.now();
console.log('Docker build took'.brightBlue,`${((ts1-ts0)/1000/60).toFixed(1)}`.brightWhite,'minutes'.brightBlue)
});
if(E.flags.i18n){
E.task('i18n', null, async () => {
E.utils.sortAndSaveI18nFiles();
E.utils.mergeI18nEntries2Data();
})
}
if(E.flags['local-binaries'] || E.flags['kaspa'] || E.flags.miner) {
E.BIN = path.join(E.appFolder,'bin', E.PLATFORM_ARCH);
mkdirp.sync(E.BIN);
}
if(E.flags.link) {
let list = ['flow-ux','flow-app','flow-utils','flow-rpc','flow-async'];
while(list.length) {
let ident = list.shift();
await npm.link(`@aspectron/${ident}`, { cwd : __dirname, stdio : 'inherit' });
}
}
else if(E.flags.docker) {
E.runTask('docker');
}else if(E.flags.i18n) {
E.runTask('i18n');
}else if(E.flags['kaspa']) {
await kaspad();
}else if(E.flags.miner){
await miner();
}
else if(E.flags['local-binaries']) {
E.runTask('kaspad');
E.runTask('aptitude');
}
else
E.run();