@tsplc/build 0.2.17 → 0.2.19
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/cli.js +628 -352
- package/dist/cli.js.map +30 -28
- package/dist/index.js +548 -387
- package/dist/index.js.map +27 -25
- package/dist/libraries.js +68 -27
- package/dist/libraries.js.map +3 -3
- package/docker/Dockerfile +2 -0
- package/docker/Dockerfile.dockerignore +4 -1
- package/docker/Dockerfile.source +3 -0
- package/docker/config.ts +10 -5
- package/docker/runner.ts +140 -127
- package/package.json +54 -53
- package/python/build.py +183 -124
- package/python/codesys_online.py +44 -45
- package/python/hardware.py +9 -9
- package/python/test_build.py +3 -3
- package/python/test_codesys_online.py +18 -12
- package/python/test_installer_packages.py +1 -0
- package/python/worker.py +11 -7
- package/src/artifacts.ts +82 -60
- package/src/build.ts +71 -62
- package/src/cli.ts +109 -100
- package/src/controller-online.ts +400 -425
- package/src/controller-protocol.ts +140 -0
- package/src/controller-session.ts +466 -397
- package/src/device-tree.ts +19 -15
- package/src/diagnostics.ts +59 -49
- package/src/docker-build.ts +217 -156
- package/src/docker-context.ts +49 -27
- package/src/docker-run.ts +137 -111
- package/src/engineering-settings.ts +42 -0
- package/src/host/codesys-command.ts +35 -34
- package/src/host/codesys-host.ts +157 -129
- package/src/host/codesys-worker.ts +318 -301
- package/src/host/windows-path.ts +63 -59
- package/src/import-request.ts +24 -0
- package/src/index.ts +37 -31
- package/src/io.ts +152 -116
- package/src/libraries.ts +214 -146
- package/src/package-path.ts +3 -1
- package/src/run.ts +132 -108
- package/src/runtime-status.ts +25 -19
- package/src/sources.ts +264 -225
- package/src/st/declarations.ts +181 -193
- package/src/st/lexer.ts +102 -118
- package/src/st/parse.ts +193 -171
- package/src/st/reader.ts +47 -42
- package/src/__tests__/fixtures/xml/fb-simple.xml +0 -40
- package/src/__tests__/fixtures/xml/fb-state-machine.xml +0 -86
- package/src/__tests__/fixtures/xml/prg-cyclic.xml +0 -44
- package/src/config.ts +0 -12
package/src/build.ts
CHANGED
|
@@ -1,76 +1,85 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
access,
|
|
4
|
+
copyFile,
|
|
5
|
+
mkdir,
|
|
6
|
+
readFile,
|
|
7
|
+
rm,
|
|
8
|
+
writeFile,
|
|
9
|
+
} from "node:fs/promises";
|
|
3
10
|
import { resolve } from "node:path";
|
|
4
11
|
import { buildFiles, publishBuild, readBuild } from "./artifacts";
|
|
5
|
-
import { dockerImage, type ResolvedConfig } from "
|
|
12
|
+
import { dockerImage, type ResolvedConfig } from "@tsplc/config/build";
|
|
6
13
|
import { buildInDocker } from "./docker-build";
|
|
7
14
|
import { writeDeviceTree } from "./device-tree";
|
|
8
15
|
import { createCodesysWorker, withWorkerLock } from "./host/codesys-worker";
|
|
16
|
+
import { importRequest } from "./import-request";
|
|
9
17
|
import { loadSources } from "./sources";
|
|
10
|
-
import { toWindowsPath } from "./host/windows-path.ts";
|
|
11
18
|
|
|
12
19
|
export const buildProject = async (config: ResolvedConfig) => {
|
|
13
|
-
|
|
14
|
-
|
|
20
|
+
if (!config.docker) {
|
|
21
|
+
throw new Error("Builds require a Docker builder image.");
|
|
22
|
+
}
|
|
23
|
+
return buildInDocker(config, dockerImage);
|
|
15
24
|
};
|
|
16
25
|
|
|
17
26
|
/** The container runner owns Wine; this operation is not a public host build. */
|
|
18
27
|
export const buildInContainer = async (config: ResolvedConfig) => {
|
|
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
|
-
|
|
28
|
+
return withWorkerLock(config, async () => {
|
|
29
|
+
// Invalidate the previous build before validation, so run cannot deploy stale
|
|
30
|
+
// output after a failed rebuild. Keep the last project available for inspection.
|
|
31
|
+
await rm(resolve(config.outDir, buildFiles.receipt), { force: true });
|
|
32
|
+
const sources = await loadSources(config);
|
|
33
|
+
await access(config.template);
|
|
34
|
+
const worker = createCodesysWorker(config);
|
|
35
|
+
const session = await worker.launch();
|
|
36
|
+
const directory = resolve(config.outDir, ".codesys/build");
|
|
37
|
+
await rm(directory, { recursive: true, force: true });
|
|
38
|
+
await mkdir(resolve(directory, "runtime"), { recursive: true });
|
|
39
|
+
const template = resolve(directory, "Template.project");
|
|
40
|
+
await copyFile(config.template, template);
|
|
41
|
+
const deviceTree =
|
|
42
|
+
config.deviceTree &&
|
|
43
|
+
(await writeDeviceTree(config.deviceTree, directory));
|
|
44
|
+
const request = {
|
|
45
|
+
libraryReferences: config.libraryReferences,
|
|
46
|
+
...(await importRequest(config, sources)),
|
|
47
|
+
...(deviceTree && { deviceTree }),
|
|
48
|
+
...(config.controller && { controller: config.controller }),
|
|
49
|
+
mode: "build",
|
|
50
|
+
output: buildFiles.output,
|
|
51
|
+
project: buildFiles.project,
|
|
52
|
+
archive: buildFiles.archive,
|
|
53
|
+
receipt: buildFiles.receipt,
|
|
54
|
+
template: "Template.project",
|
|
55
|
+
templateHash: createHash("sha256")
|
|
56
|
+
.update(await readFile(template))
|
|
57
|
+
.digest("hex"),
|
|
58
|
+
};
|
|
59
|
+
await writeFile(
|
|
60
|
+
resolve(directory, "request.json"),
|
|
61
|
+
JSON.stringify(request, null, 2),
|
|
62
|
+
);
|
|
63
|
+
console.log(`CODESYS build: ${config.outDir}`);
|
|
64
|
+
try {
|
|
65
|
+
await worker.request(session, { action: "build" }, config.timeouts.build);
|
|
66
|
+
const compiled = await readBuild(directory);
|
|
67
|
+
if (
|
|
68
|
+
config.tasks &&
|
|
69
|
+
JSON.stringify(compiled.tasks) !== JSON.stringify(config.tasks)
|
|
70
|
+
) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
"CODESYS build receipt does not match the requested task plan",
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
// Builds and runs share the lock. Removing the receipt above keeps a failed
|
|
76
|
+
// publication from looking complete even if only some files were replaced.
|
|
77
|
+
return await publishBuild(compiled, config.outDir);
|
|
78
|
+
} catch (cause) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`CODESYS build failed. Inspect ${directory}/progress.log, error.txt and ${session.directory}/codesys.log`,
|
|
81
|
+
{ cause },
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
76
85
|
};
|
package/src/cli.ts
CHANGED
|
@@ -1,116 +1,125 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
|
-
import { deviceTree } from "@tsplc/typegen";
|
|
4
3
|
import { loadHardware, resolveIo } from "@tsplc/typegen/hardware";
|
|
5
4
|
import { controllerFor, loadTsplcConfig, rawBuildConfig } from "@tsplc/config";
|
|
5
|
+
import { z } from "zod";
|
|
6
6
|
import { buildProject } from "./build.ts";
|
|
7
|
-
import { resolveConfig } from "
|
|
7
|
+
import { resolveConfig } from "@tsplc/config/build";
|
|
8
8
|
import { inspectController, updateController } from "./controller-online.ts";
|
|
9
9
|
import { configureDocker, configureRuntime } from "./docker-build.ts";
|
|
10
|
+
import { rawEngineeringSettings } from "./engineering-settings.ts";
|
|
10
11
|
import { installLibraries } from "./libraries.ts";
|
|
11
12
|
import { runProject } from "./run.ts";
|
|
12
13
|
import { loadSources } from "./sources.ts";
|
|
13
14
|
|
|
15
|
+
const commandSchema = z.enum([
|
|
16
|
+
"configure",
|
|
17
|
+
"install",
|
|
18
|
+
"check",
|
|
19
|
+
"build",
|
|
20
|
+
"run",
|
|
21
|
+
"download",
|
|
22
|
+
"online-change",
|
|
23
|
+
"inspect",
|
|
24
|
+
]);
|
|
25
|
+
|
|
14
26
|
async function main() {
|
|
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
|
-
initializeUser: values["initialize-user"],
|
|
108
|
-
read: values.read,
|
|
109
|
-
});
|
|
27
|
+
const { values, positionals } = parseArgs({
|
|
28
|
+
allowPositionals: true,
|
|
29
|
+
options: {
|
|
30
|
+
config: { type: "string" },
|
|
31
|
+
help: { type: "boolean", short: "h" },
|
|
32
|
+
read: { type: "string", multiple: true },
|
|
33
|
+
"initialize-user": { type: "boolean" },
|
|
34
|
+
"frozen-lockfile": { type: "boolean" },
|
|
35
|
+
runtime: { type: "boolean" },
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
const [name] = positionals;
|
|
39
|
+
if (positionals.length > 1) {
|
|
40
|
+
throw new Error("Specify one command.");
|
|
41
|
+
}
|
|
42
|
+
if (!name || values.help) {
|
|
43
|
+
console.log(
|
|
44
|
+
"tsplc-build configure|install|check|build|run|download|online-change|inspect [--config tsplc.config.ts] [--read symbol] [--runtime]",
|
|
45
|
+
);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const parsed = commandSchema.safeParse(name);
|
|
49
|
+
if (!parsed.success) {
|
|
50
|
+
throw new Error(`Unknown command ${name}.`);
|
|
51
|
+
}
|
|
52
|
+
const command = parsed.data;
|
|
53
|
+
if (values.runtime && command !== "configure") {
|
|
54
|
+
throw new Error("--runtime applies only to configure.");
|
|
55
|
+
}
|
|
56
|
+
if (command === "configure") {
|
|
57
|
+
await (values.runtime ? configureRuntime() : configureDocker());
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const loaded = await loadTsplcConfig(values.config);
|
|
61
|
+
const { config, configFile, root } = loaded;
|
|
62
|
+
if (command === "install") {
|
|
63
|
+
const libraries = await installLibraries(config.dependencies, root, {
|
|
64
|
+
frozen: values["frozen-lockfile"],
|
|
65
|
+
});
|
|
66
|
+
console.log(`Installed ${libraries.length} CODESYS libraries.`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (!config.build) {
|
|
70
|
+
throw new Error("Configure build options in tsplc.config.ts.");
|
|
71
|
+
}
|
|
72
|
+
if (command === "inspect") {
|
|
73
|
+
// Inspection only needs connection/baseline settings; it remains usable
|
|
74
|
+
// without sources, EDS descriptors or installed library payloads.
|
|
75
|
+
console.log(
|
|
76
|
+
JSON.stringify(
|
|
77
|
+
await inspectController(
|
|
78
|
+
resolveConfig(
|
|
79
|
+
{ ...config.build, controller: controllerFor(config, command) },
|
|
80
|
+
configFile,
|
|
81
|
+
),
|
|
82
|
+
values.read,
|
|
83
|
+
),
|
|
84
|
+
null,
|
|
85
|
+
2,
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (config.compiler) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
"Use tsplc for TypeScript projects. tsplc-build accepts raw Structured Text.",
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
if (command === "check") {
|
|
96
|
+
const build = rawBuildConfig(config);
|
|
97
|
+
const hardware = await loadHardware(config, root);
|
|
98
|
+
const sources = await loadSources(
|
|
99
|
+
resolveConfig({ ...build, io: resolveIo(config, hardware) }, configFile),
|
|
100
|
+
);
|
|
101
|
+
console.log(`Validated ${sources.objects.length} Structured Text objects.`);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const settings = await rawEngineeringSettings(loaded, {
|
|
105
|
+
command,
|
|
106
|
+
frozenLockfile: values["frozen-lockfile"],
|
|
107
|
+
});
|
|
108
|
+
if (command === "build") {
|
|
109
|
+
await buildProject(settings);
|
|
110
|
+
} else if (command === "run") {
|
|
111
|
+
await buildProject(settings);
|
|
112
|
+
await runProject(settings, config.name);
|
|
113
|
+
} else {
|
|
114
|
+
await updateController(settings, command, {
|
|
115
|
+
initializeUser: values["initialize-user"],
|
|
116
|
+
read: values.read,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
110
119
|
}
|
|
111
120
|
try {
|
|
112
|
-
|
|
121
|
+
await main();
|
|
113
122
|
} catch (cause) {
|
|
114
|
-
|
|
115
|
-
|
|
123
|
+
console.error(cause instanceof Error ? cause.message : String(cause));
|
|
124
|
+
process.exitCode = 1;
|
|
116
125
|
}
|