@brunoluizdesiqueira/bbuilder-cli 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/compiler.js +48 -12
- package/package.json +1 -1
package/dist/build/compiler.js
CHANGED
|
@@ -45,6 +45,7 @@ const fs = __importStar(require("fs"));
|
|
|
45
45
|
const os = __importStar(require("os"));
|
|
46
46
|
const path = __importStar(require("path"));
|
|
47
47
|
const output_1 = require("../ui/output");
|
|
48
|
+
const delphiEnvCache = new Map();
|
|
48
49
|
function buildCompilerFlags(buildType) {
|
|
49
50
|
const baseDefines = 'DEBUG;ALT_CEF133_0;EUREKALOG';
|
|
50
51
|
const releaseDefines = 'RELEASE;ALT_CEF133_0;EUREKALOG';
|
|
@@ -75,25 +76,55 @@ function buildDependencies(opts) {
|
|
|
75
76
|
// dcc64 fail to resolve paths such as the Delphi runtime library.
|
|
76
77
|
return opts.dependencyPaths.join(';');
|
|
77
78
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
function parseWindowsEnv(output) {
|
|
80
|
+
const env = {};
|
|
81
|
+
for (const line of output.split(/\r?\n/)) {
|
|
82
|
+
const separatorIndex = line.indexOf('=');
|
|
83
|
+
if (separatorIndex <= 0)
|
|
84
|
+
continue;
|
|
85
|
+
const key = line.slice(0, separatorIndex).trim();
|
|
86
|
+
const value = line.slice(separatorIndex + 1);
|
|
87
|
+
if (!key)
|
|
88
|
+
continue;
|
|
89
|
+
env[key] = value;
|
|
90
|
+
}
|
|
91
|
+
return env;
|
|
82
92
|
}
|
|
83
|
-
async function
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
async function getDelphiEnvironment(delphiDir) {
|
|
94
|
+
const cached = delphiEnvCache.get(delphiDir);
|
|
95
|
+
if (cached) {
|
|
96
|
+
return cached;
|
|
97
|
+
}
|
|
98
|
+
const rsvarsPath = path.win32.join(delphiDir, 'bin', 'rsvars.bat');
|
|
99
|
+
if (!fs.existsSync(rsvarsPath)) {
|
|
100
|
+
(0, output_1.fatal)(`Arquivo não encontrado: ${rsvarsPath}`);
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const result = await (0, execa_1.default)('cmd.exe', ['/d', '/s', '/c', `call "${rsvarsPath}" >nul && set`], {
|
|
104
|
+
env: process.env,
|
|
105
|
+
});
|
|
106
|
+
const resolved = {
|
|
107
|
+
...process.env,
|
|
108
|
+
...parseWindowsEnv(result.stdout),
|
|
109
|
+
};
|
|
110
|
+
delphiEnvCache.set(delphiDir, resolved);
|
|
111
|
+
return resolved;
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
(0, output_1.fatal)('Falha ao carregar o ambiente do Delphi via rsvars.bat.');
|
|
115
|
+
}
|
|
89
116
|
}
|
|
90
117
|
async function runCgrc(opts, projectName) {
|
|
91
118
|
const tempDir = path.join(os.tmpdir(), `BimerBuild_${projectName}`);
|
|
92
119
|
const vrcFile = path.join(tempDir, `${projectName}.vrc`);
|
|
93
120
|
const resFile = path.join(tempDir, `${projectName}.res`);
|
|
121
|
+
const delphiEnv = await getDelphiEnvironment(opts.delphiDir);
|
|
94
122
|
(0, output_1.step)('Compilando recursos e embutindo ícone...');
|
|
95
123
|
try {
|
|
96
|
-
await
|
|
124
|
+
await (0, execa_1.default)(path.win32.join(opts.delphiDir, 'bin', 'cgrc.exe'), [vrcFile, `-fo${resFile}`], {
|
|
125
|
+
env: delphiEnv,
|
|
126
|
+
stdio: 'inherit',
|
|
127
|
+
});
|
|
97
128
|
}
|
|
98
129
|
catch {
|
|
99
130
|
(0, output_1.fatal)('Falha do compilador CGRC ao gerar o arquivo de recursos .res.');
|
|
@@ -105,6 +136,7 @@ async function runDcc64(opts, projectName, workspaceDir) {
|
|
|
105
136
|
const deps = buildDependencies(opts);
|
|
106
137
|
const exeOut = path.win32.join('C:\\Temp', opts.envVersion, 'EXE');
|
|
107
138
|
const dcuOut = path.win32.join('C:\\Temp', opts.envVersion, 'DCU');
|
|
139
|
+
const delphiEnv = await getDelphiEnvironment(opts.delphiDir);
|
|
108
140
|
if (!fs.existsSync(exeOut))
|
|
109
141
|
fs.mkdirSync(exeOut, { recursive: true });
|
|
110
142
|
if (!fs.existsSync(dcuOut))
|
|
@@ -136,7 +168,11 @@ async function runDcc64(opts, projectName, workspaceDir) {
|
|
|
136
168
|
`${projectName}.dpr`,
|
|
137
169
|
];
|
|
138
170
|
try {
|
|
139
|
-
await
|
|
171
|
+
await (0, execa_1.default)(dcc64, args, {
|
|
172
|
+
cwd: workspaceDir,
|
|
173
|
+
env: delphiEnv,
|
|
174
|
+
stdio: 'inherit',
|
|
175
|
+
});
|
|
140
176
|
}
|
|
141
177
|
catch {
|
|
142
178
|
(0, output_1.fatal)('Falha na compilação do Delphi. Verifique os logs de erro acima.');
|