Fix/windows builds (#764)

* Fix windows path issues

* Few script changes to support windows

* Update build scripts

* remove duplicate call

* changelog

* Fix for telnet test runner
This commit is contained in:
Brahim Hadriche authored and GitHub committed 2025-10-22 09:38:38 -04:00
1 parent 388cad36be
commit 112bad5d42
15 files changed
+130 -88

No files matched your search

+5 -4
View File
@@ -10,6 +10,7 @@ import {
isBrsFile,
} from 'brighterscript';
import { existsSync } from 'fs-extra';
import path from 'path';
export class ImportValidationPlugin implements CompilerPlugin {
public name = 'ImportValidationPlugin';
@@ -33,13 +34,13 @@ export class ImportValidationPlugin implements CompilerPlugin {
}
generateXmlComponent(file: BscFile) {
const path = file.pkgPath;
const name = path.split('/').pop().replace('.bs', '') + `TestComponent${path.length}`;
const pkgPath = file.pkgPath;
const name = path.basename(pkgPath, '.bs') + `TestComponent${pkgPath.length}`;
const content = `<component name="${name}" extends="Node">
<script type="text/brightscript" uri="pkg:/${file.pkgPath}" />
<script type="text/brightscript" uri="pkg:/${pkgPath}" />
</component>`
file.program.setFile(`${path}.TestComponent.xml`, content);
file.program.setFile(`${pkgPath}.TestComponent.xml`, content);
}
}
+2 -1
View File
@@ -10,6 +10,7 @@ import {
FunctionStatement,
DiagnosticSeverity,
} from 'brighterscript';
import path from 'path';
export class JobSystemPlugin implements CompilerPlugin {
public name = 'JobSystemPlugin';
@@ -29,7 +30,7 @@ export class JobSystemPlugin implements CompilerPlugin {
}
const xml = this.generateJobXml(jobName, file.pkgPath)
const xmlFile = `components/JobSystem/generated/${jobName}.xml`
const xmlFile = path.join('components', 'JobSystem', 'generated', `${jobName}.xml`);
if (program.hasFile(xmlFile)) {
const currentContent = program.getFile(xmlFile).fileContents
+1 -1
View File
@@ -17,7 +17,7 @@ import {
} from 'brighterscript';
import path from 'path';
const loggingFilePath = 'source/utils/Logging.bs';
const loggingFilePath = path.join('source', 'utils', 'Logging.bs');
const logFunctions = {
LogError: {
stringLevel: 'ERROR',
+2 -1
View File
@@ -1,5 +1,6 @@
// This plugin generates a file containing functions for type checking and type casting.
import { CompilerPlugin, Program, SourceObj } from "brighterscript";
import path from "path";
const types = [
{ name: 'Bool', interface: 'ifBoolean', type: 'boolean', defaultValue: 'false' },
@@ -16,7 +17,7 @@ const types = [
const generatedCodeHeader = `' The rest of this file is generated by the TypeGenPlugin`
const typesFilePath = 'source/utils/Types.bs';
const typesFilePath = path.join("source", "utils", "Types.bs");
const isTypeTemplate = (name: string, _interface: string) => {
return `' Returns true if the given object is of type ${name}, false otherwise
+9
View File
@@ -0,0 +1,9 @@
const fs = require('fs-extra');
const [src, dest] = process.argv.slice(2);
if (!src || !dest) {
console.error('Usage: node tools/cp.js <source> <destination>');
process.exit(1);
}
fs.copySync(src, dest, { overwrite: true });
+9
View File
@@ -0,0 +1,9 @@
const fs = require('fs-extra');
const dirs = process.argv.slice(2);
if (dirs.length === 0) {
console.error('Usage: node tools/mkdir.js <dir1> [dir2] ...');
process.exit(1);
}
dirs.forEach(dir => fs.ensureDirSync(dir));
+9
View File
@@ -0,0 +1,9 @@
const fs = require('fs-extra');
const targets = process.argv.slice(2);
if (targets.length === 0) {
console.error('Usage: node tools/rm.js <target1> [target2] ...');
process.exit(1);
}
targets.forEach(target => fs.removeSync(target));
+45 -60
View File
@@ -6,7 +6,7 @@ const getEnvVars = require('./get-env-vars');
const rokuDeploy = require('roku-deploy');
const path = require('path');
const fs = require('fs');
const spawn = require('child_process').spawn;
const { Telnet } = require('telnet-client');
function getArgumentParser() {
const parser = new ArgumentParser({
@@ -20,33 +20,19 @@ function getArgumentParser() {
return parser;
}
const childProcesses = [];
function processCleanup() {
childProcesses.forEach(function (child) {
try {
child.kill();
} catch (error) {
}
});
}
function exitHandler(options, exitCode) {
if (options.cleanup) {
processCleanup();
}
if (options.exit) {
process.exit(exitCode);
}
}
process.on('exit', exitHandler.bind(null, { cleanup: true }));
process.on('SIGINT', exitHandler.bind(null, { exit: true }));
process.on('SIGUSR1', exitHandler.bind(null, { exit: true }));
process.on('SIGUSR2', exitHandler.bind(null, { exit: true }));
process.on('uncaughtException', exitHandler.bind(null, { exit: true }));
process.on('SIGINT', () => {
process.exit(1); // Exit on Ctrl+C
});
process.on('SIGUSR1', () => {
process.exit(1); // Exit on SIGUSR1
});
process.on('SIGUSR2', () => {
process.exit(1); // Exit on SIGUSR2
});
process.on('uncaughtException', (error, origin) => {
console.error(error);
process.exit(1); // Exit on uncaught exceptions
});
(async () => {
let success = false;
@@ -86,14 +72,14 @@ process.on('uncaughtException', exitHandler.bind(null, { exit: true }));
// ignored
}
console.log('Starting telnet process');
telnet = await startTelnetProcessAsync(options.host, options.telnetPort);
console.log('Starting telnet client');
telnet = await startTelnetClientAsync(options.host, options.telnetPort);
console.log('Publishing package');
await rokuDeploy.publish(options);
console.log('Waiting for test to finish');
let data = await readFromProcessUntil(telnet, timeout);
let data = await readFromTelnetUntil(telnet, timeout);
if (reportOnly) {
data = parseTestReport(data);
@@ -107,7 +93,7 @@ process.on('uncaughtException', exitHandler.bind(null, { exit: true }));
console.error(error);
}
finally {
telnet?.kill();
telnet?.end();
}
if (success) {
console.log('Tests passed!');
@@ -117,31 +103,36 @@ process.on('uncaughtException', exitHandler.bind(null, { exit: true }));
process.exit(success ? 0 : 1);
})();
function startTelnetProcessAsync(host, port, timeoutSeconds = 2) {
return new Promise((resolve, reject) => {
const telnet = spawn('telnet', [host, port]);
childProcesses.push(telnet);
function startTelnetClientAsync(host, port, timeoutSeconds = 2) {
return new Promise(async (resolve, reject) => {
const connection = new Telnet();
let timeoutID;
function timeoutReached() {
resolve(telnet);
}
const params = {
host: host,
port: port,
negotiationMandatory: false,
timeout: timeoutSeconds * 1000
};
telnet.stdout.on('data', (data) => {
clearTimeout(timeoutID);
timeoutID = setTimeout(timeoutReached, timeoutSeconds * 1000);
connection.on('close', function () {
console.log('connection closed');
});
telnet.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
reject()
})
connection.on('error', function (error) {
console.error('telnet connection error:', error);
reject(error);
});
timeoutID = setTimeout(timeoutReached, timeoutSeconds * 1000);
try {
await connection.connect(params);
resolve(connection);
} catch (error) {
reject(error);
}
});
}
function readFromProcessUntil(proc, timeoutSeconds = 20, endToken = 'AppExitComplete') {
function readFromTelnetUntil(connection, timeoutSeconds = 20, endToken = 'AppExitComplete') {
return new Promise((resolve, reject) => {
let data = '';
@@ -149,28 +140,22 @@ function readFromProcessUntil(proc, timeoutSeconds = 20, endToken = 'AppExitComp
function timeoutReached() {
reject(`Timeout of ${timeoutSeconds} seconds waiting for ${endToken}`);
proc.kill();
connection.end();
}
proc.stdout.on('data', (chunk) => {
process.stdout.write(chunk);
connection.on('data', (chunk) => {
process.stdout.write(chunk.toString());
clearTimeout(timeoutID);
data += chunk;
data += chunk.toString();
if (data.includes(endToken)) {
resolve(data);
proc.kill();
connection.end();
return;
}
timeoutID = setTimeout(timeoutReached, timeoutSeconds * 1000);
});
proc.stderr.on('data', (data) => {
clearTimeout(timeoutID);
console.error(`stderr: ${data}`);
reject()
})
timeoutID = setTimeout(timeoutReached, timeoutSeconds * 1000);
});
}
+2 -1
View File
@@ -4,6 +4,7 @@
const fs = require('fs');
const shell = require('shelljs');
const path = require('path');
if (!shell.which('git')) {
shell.echo('Sorry, this script requires git');
@@ -18,7 +19,7 @@ if (gitStatus.stdout !== '') {
const gitCommitHash = shell.exec('git rev-parse --short HEAD').stdout.trim();
["playlet-app/src/manifest", "playlet-lib/src/manifest"].forEach(function (manifestPath) {
[path.join("playlet-app", "src", "manifest"), path.join("playlet-lib", "src", "manifest")].forEach(function (manifestPath) {
let appManifestContent = fs.readFileSync(manifestPath, { encoding: 'utf8', flag: 'r' });
const gitHashPattern = /git_commit_sha=(\w+)/;
+2 -1
View File
@@ -3,6 +3,7 @@
// as well as the package.json files in the playlet-app/playlet-lib/playlet-web folders.
const fs = require('fs');
const path = require('path');
const { execSync } = require("child_process");
const semverParse = require('semver/functions/parse');
@@ -13,7 +14,7 @@ const packageJson = JSON.parse(packageJsonContent);
const version = packageJson.version;
const parsedVersion = semverParse(version);
["playlet-app/src/manifest", "playlet-lib/src/manifest"].forEach(function (manifestPath) {
[path.join("playlet-app", "src", "manifest"), path.join("playlet-lib", "src", "manifest")].forEach(function (manifestPath) {
let appManifestContent = fs.readFileSync(manifestPath, { encoding: 'utf8', flag: 'r' });
const majorPattern = /major_version=(\d+)/;