@tsplc/build 0.2.16 → 0.2.18
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
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// What the host and the builder container exchange for controller operations: the receipt,
|
|
2
|
+
// the target a baseline is bound to, warm and login commands, and how failures are worded.
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import {
|
|
6
|
+
controllerSchema,
|
|
7
|
+
sha256Digest,
|
|
8
|
+
tcpPort,
|
|
9
|
+
type ResolvedConfig,
|
|
10
|
+
} from "@tsplc/config/build";
|
|
11
|
+
|
|
12
|
+
export const imageIdSchema = z.string().regex(/^sha256:[a-f0-9]{64}$/);
|
|
13
|
+
const endpointSchema = z.strictObject({
|
|
14
|
+
host: z.string().nonempty(),
|
|
15
|
+
port: tcpPort,
|
|
16
|
+
});
|
|
17
|
+
export const controllerResultSchema = z.strictObject({
|
|
18
|
+
schemaVersion: z.literal(1),
|
|
19
|
+
operationId: z.uuid(),
|
|
20
|
+
operation: z.enum(["download", "online-change", "inspect"]),
|
|
21
|
+
imageId: imageIdSchema,
|
|
22
|
+
templateHash: sha256Digest,
|
|
23
|
+
target: z.strictObject({
|
|
24
|
+
network: z.string().nonempty(),
|
|
25
|
+
gateway: endpointSchema,
|
|
26
|
+
device: endpointSchema,
|
|
27
|
+
controller: controllerSchema.optional(),
|
|
28
|
+
deviceTree: sha256Digest.optional(),
|
|
29
|
+
}),
|
|
30
|
+
generation: z.string().nonempty(),
|
|
31
|
+
application: z.string().nonempty(),
|
|
32
|
+
applicationGuid: z.string().nonempty(),
|
|
33
|
+
controllerIds: z.strictObject({
|
|
34
|
+
codeId: z.string().nonempty(),
|
|
35
|
+
dataId: z.string().nonempty(),
|
|
36
|
+
}),
|
|
37
|
+
state: z.string().nonempty(),
|
|
38
|
+
values: z.record(z.string(), z.string()),
|
|
39
|
+
});
|
|
40
|
+
export type ControllerResult = z.infer<typeof controllerResultSchema>;
|
|
41
|
+
export const controllerCredentialsSchema = z.strictObject({
|
|
42
|
+
username: z.string().nonempty(),
|
|
43
|
+
password: z.string().nonempty(),
|
|
44
|
+
});
|
|
45
|
+
export type ControllerCredentials = z.infer<typeof controllerCredentialsSchema>;
|
|
46
|
+
|
|
47
|
+
/** One operation for the warm builder container; `request` is the container path of its config. */
|
|
48
|
+
export const warmOperationSchema = z.strictObject({
|
|
49
|
+
operation: z.enum(["download", "online-change"]),
|
|
50
|
+
operationId: z.uuid(),
|
|
51
|
+
request: z.string().nonempty(),
|
|
52
|
+
initializeUser: z.boolean(),
|
|
53
|
+
credentials: controllerCredentialsSchema.optional(),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The failure a Python traceback ends with, as `Type: message`: everything after its last frame, so
|
|
58
|
+
* a message over several lines, such as one CODESYS error per line, stays whole. Other errors pass unchanged.
|
|
59
|
+
*/
|
|
60
|
+
export const tracebackFailure = (traceback: string) => {
|
|
61
|
+
const text = traceback.trim();
|
|
62
|
+
const lastFrame = text.lastIndexOf("\n File ");
|
|
63
|
+
if (lastFrame === -1) {
|
|
64
|
+
return text;
|
|
65
|
+
}
|
|
66
|
+
// Python prints the frame's source line under it, indented further, when it has the source.
|
|
67
|
+
const [, ...rest] = text.slice(lastFrame + 1).split("\n");
|
|
68
|
+
return (rest[0]?.startsWith(" ") ? rest.slice(1) : rest).join("\n");
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/** The message of the failure a worker traceback ends with, without its exception type. */
|
|
72
|
+
export const failureReason = (error: unknown) =>
|
|
73
|
+
tracebackFailure(
|
|
74
|
+
error instanceof Error ? error.message : String(error),
|
|
75
|
+
).replace(/^\w+: /, "");
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* What a download binds the controller to. An online change needs the same connection, controller
|
|
79
|
+
* and device tree, because it only recompiles the program into the downloaded project.
|
|
80
|
+
*/
|
|
81
|
+
export const controllerTarget = (
|
|
82
|
+
config: ResolvedConfig,
|
|
83
|
+
online: NonNullable<ResolvedConfig["online"]>,
|
|
84
|
+
) => ({
|
|
85
|
+
network: online.network,
|
|
86
|
+
gateway: online.gateway,
|
|
87
|
+
device: online.device,
|
|
88
|
+
controller: config.controller,
|
|
89
|
+
...(config.deviceTree && {
|
|
90
|
+
deviceTree: createHash("sha256")
|
|
91
|
+
.update(JSON.stringify(config.deviceTree))
|
|
92
|
+
.digest("hex"),
|
|
93
|
+
}),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
export type Baseline = Pick<
|
|
97
|
+
ControllerResult,
|
|
98
|
+
"imageId" | "templateHash" | "target"
|
|
99
|
+
>;
|
|
100
|
+
|
|
101
|
+
/** Whether two controller states share an image, template and target, so one can follow the other. */
|
|
102
|
+
export const sameBaseline = (state: Baseline, expected: Baseline) =>
|
|
103
|
+
state.imageId === expected.imageId &&
|
|
104
|
+
state.templateHash === expected.templateHash &&
|
|
105
|
+
JSON.stringify(state.target) === JSON.stringify(expected.target);
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Ends every refusal that only a full download resolves, so callers can offer one. The Python
|
|
109
|
+
* online operations end theirs with the same words.
|
|
110
|
+
*/
|
|
111
|
+
export const explicitDownload = "use an explicit download";
|
|
112
|
+
|
|
113
|
+
export const loginCommandSchema = z.discriminatedUnion("command", [
|
|
114
|
+
z.strictObject({ command: z.literal("state") }),
|
|
115
|
+
z.strictObject({
|
|
116
|
+
command: z.literal("read"),
|
|
117
|
+
expressions: z.array(z.string().nonempty()).nonempty(),
|
|
118
|
+
}),
|
|
119
|
+
z.strictObject({
|
|
120
|
+
command: z.enum(["write", "force"]),
|
|
121
|
+
values: z.record(z.string().nonempty(), z.string().nonempty()),
|
|
122
|
+
}),
|
|
123
|
+
// No expressions unforces everything; `restore` puts back the value from before forcing.
|
|
124
|
+
z.strictObject({
|
|
125
|
+
command: z.literal("unforce"),
|
|
126
|
+
expressions: z.array(z.string().nonempty()),
|
|
127
|
+
restore: z.boolean(),
|
|
128
|
+
}),
|
|
129
|
+
z.strictObject({ command: z.enum(["start", "stop"]) }),
|
|
130
|
+
z.strictObject({
|
|
131
|
+
command: z.literal("reset"),
|
|
132
|
+
kind: z.enum(["Warm", "Cold"]),
|
|
133
|
+
}),
|
|
134
|
+
]);
|
|
135
|
+
export type LoginCommand = z.infer<typeof loginCommandSchema>;
|
|
136
|
+
export const loginResultSchema = z.union([
|
|
137
|
+
z.strictObject({ values: z.record(z.string(), z.string()) }),
|
|
138
|
+
z.strictObject({ state: z.string(), forced: z.array(z.string()) }),
|
|
139
|
+
]);
|
|
140
|
+
export type LoginResult = z.infer<typeof loginResultSchema>;
|