1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.IndependentPackageBuilder = void 0;
|
4 | const path = require("path");
|
5 | const logging = require("./logging");
|
6 | const util_1 = require("./util");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | class IndependentPackageBuilder {
|
18 | constructor(targetName, targetConstructor, modules, options) {
|
19 | this.targetName = targetName;
|
20 | this.targetConstructor = targetConstructor;
|
21 | this.modules = modules;
|
22 | this.options = options;
|
23 | }
|
24 | async buildModules() {
|
25 | if (this.options.codeOnly) {
|
26 | await Promise.all((0, util_1.flatten)(this.modules).map((module) => this.generateModuleCode(module, this.options)));
|
27 | return;
|
28 | }
|
29 | for (const modules of this.modules) {
|
30 |
|
31 | await Promise.all(modules.map((module) => this.buildModule(module, this.options)));
|
32 | }
|
33 | }
|
34 | async generateModuleCode(module, options) {
|
35 | const outputDir = this.finalOutputDir(module, options);
|
36 | logging.debug(`Generating ${this.targetName} code into ${outputDir}`);
|
37 | await this.makeTarget(module, options).generateCode(outputDir, module.tarball);
|
38 | }
|
39 | async buildModule(module, options) {
|
40 | const target = this.makeTarget(module, options);
|
41 | const outputDir = this.finalOutputDir(module, options);
|
42 | const src = await util_1.Scratch.make((tmpdir) => {
|
43 | logging.debug(`Generating ${this.targetName} code into ${tmpdir}`);
|
44 | return target.generateCode(tmpdir, module.tarball);
|
45 | });
|
46 | try {
|
47 | logging.debug(`Building ${src.directory} into ${outputDir}`);
|
48 | return await target.build(src.directory, outputDir);
|
49 | }
|
50 | catch (err) {
|
51 | logging.warn(`Failed building ${this.targetName}`);
|
52 | return await Promise.reject(err);
|
53 | }
|
54 | finally {
|
55 | if (options.clean) {
|
56 | logging.debug(`Cleaning ${src.directory}`);
|
57 | await src.cleanup();
|
58 | }
|
59 | else {
|
60 | logging.info(`Generated code for ${this.targetName} retained at ${src.directory}`);
|
61 | }
|
62 | }
|
63 | }
|
64 | makeTarget(module, options) {
|
65 | return new this.targetConstructor({
|
66 | arguments: options.arguments,
|
67 | assembly: module.assembly,
|
68 | fingerprint: options.fingerprint,
|
69 | force: options.force,
|
70 | packageDir: module.moduleDirectory,
|
71 | rosetta: options.rosetta,
|
72 | runtimeTypeChecking: options.runtimeTypeChecking,
|
73 | targetName: this.targetName,
|
74 | });
|
75 | }
|
76 | finalOutputDir(module, options) {
|
77 | if (options.languageSubdirectory) {
|
78 | return path.join(module.outputDirectory, this.targetName);
|
79 | }
|
80 | return module.outputDirectory;
|
81 | }
|
82 | }
|
83 | exports.IndependentPackageBuilder = IndependentPackageBuilder;
|
84 |
|
\ | No newline at end of file |