@tsplc/build 0.5.9 → 0.5.10
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 +338 -324
- package/dist/cli.js.map +12 -12
- package/dist/index.js +478 -416
- package/dist/index.js.map +12 -12
- package/package.json +4 -4
- package/python/codesys_online.py +20 -10
- package/python/worker.py +1 -0
- package/src/controller-online.ts +117 -28
- package/src/controller-protocol.ts +35 -4
- package/src/controller-session.ts +117 -41
- package/src/host/codesys-worker.ts +4 -1
- package/src/index.ts +8 -0
- package/src/online-change-check.ts +10 -9
package/dist/cli.js
CHANGED
|
@@ -557,7 +557,7 @@ import {
|
|
|
557
557
|
} from "node:fs/promises";
|
|
558
558
|
import { resolve as resolve7 } from "node:path";
|
|
559
559
|
import { setTimeout as delay } from "node:timers/promises";
|
|
560
|
-
import { z as
|
|
560
|
+
import { z as z8 } from "zod";
|
|
561
561
|
|
|
562
562
|
// packages/build/src/controller-protocol.ts
|
|
563
563
|
import {
|
|
@@ -565,200 +565,19 @@ import {
|
|
|
565
565
|
sha256Digest,
|
|
566
566
|
tcpPort
|
|
567
567
|
} from "@tsplc/config/build";
|
|
568
|
-
import { z as z5 } from "zod";
|
|
569
|
-
var imageIdSchema = z5.string().regex(/^sha256:[a-f0-9]{64}$/);
|
|
570
|
-
var endpointSchema = z5.strictObject({
|
|
571
|
-
host: z5.string().nonempty(),
|
|
572
|
-
port: tcpPort
|
|
573
|
-
});
|
|
574
|
-
var controllerResultSchema = z5.strictObject({
|
|
575
|
-
schemaVersion: z5.literal(1),
|
|
576
|
-
operationId: z5.uuid(),
|
|
577
|
-
operation: z5.enum(["download", "online-change", "inspect"]),
|
|
578
|
-
imageId: imageIdSchema,
|
|
579
|
-
engineering: sha256Digest.optional(),
|
|
580
|
-
templateHash: sha256Digest,
|
|
581
|
-
target: z5.strictObject({
|
|
582
|
-
network: z5.string().nonempty(),
|
|
583
|
-
gateway: endpointSchema,
|
|
584
|
-
device: endpointSchema,
|
|
585
|
-
controller: controllerSchema.optional(),
|
|
586
|
-
deviceTree: sha256Digest.optional()
|
|
587
|
-
}),
|
|
588
|
-
generation: z5.string().nonempty(),
|
|
589
|
-
application: z5.string().nonempty(),
|
|
590
|
-
applicationGuid: z5.string().nonempty(),
|
|
591
|
-
controllerIds: z5.strictObject({
|
|
592
|
-
codeId: z5.string().nonempty(),
|
|
593
|
-
dataId: z5.string().nonempty()
|
|
594
|
-
}),
|
|
595
|
-
state: z5.string().nonempty(),
|
|
596
|
-
values: z5.record(z5.string(), z5.string())
|
|
597
|
-
});
|
|
598
|
-
var controllerCredentialsSchema = z5.strictObject({
|
|
599
|
-
username: z5.string().nonempty(),
|
|
600
|
-
password: z5.string().nonempty()
|
|
601
|
-
});
|
|
602
|
-
var warmOperationSchema = z5.strictObject({
|
|
603
|
-
operation: z5.enum(["download", "online-change"]),
|
|
604
|
-
operationId: z5.uuid(),
|
|
605
|
-
request: z5.string().nonempty(),
|
|
606
|
-
initializeUser: z5.boolean(),
|
|
607
|
-
credentials: controllerCredentialsSchema.optional()
|
|
608
|
-
});
|
|
609
|
-
var tracebackFailure = (traceback) => {
|
|
610
|
-
const text = traceback.trim();
|
|
611
|
-
const lastFrame = text.lastIndexOf(`
|
|
612
|
-
File `);
|
|
613
|
-
if (lastFrame === -1) {
|
|
614
|
-
return text;
|
|
615
|
-
}
|
|
616
|
-
const [, ...rest] = text.slice(lastFrame + 1).split(`
|
|
617
|
-
`);
|
|
618
|
-
return ((rest[0]?.startsWith(" ")) ? rest.slice(1) : rest).join(`
|
|
619
|
-
`);
|
|
620
|
-
};
|
|
621
|
-
var controllerTarget = (config, online) => ({
|
|
622
|
-
network: online.network,
|
|
623
|
-
gateway: online.gateway,
|
|
624
|
-
device: online.device,
|
|
625
|
-
controller: config.controller,
|
|
626
|
-
...config.deviceTree && {
|
|
627
|
-
deviceTree: deviceTreeStructure(config.deviceTree)
|
|
628
|
-
}
|
|
629
|
-
});
|
|
630
|
-
var sameBuilder = (state, expected) => state.engineering && expected.engineering ? state.engineering === expected.engineering : state.imageId === expected.imageId;
|
|
631
|
-
var sameBaseline = (state, expected) => sameBuilder(state, expected) && state.templateHash === expected.templateHash && JSON.stringify(state.target) === JSON.stringify(expected.target);
|
|
632
|
-
var rollbackSchema = z5.enum([
|
|
633
|
-
"intact",
|
|
634
|
-
"restored",
|
|
635
|
-
"failed",
|
|
636
|
-
"unavailable"
|
|
637
|
-
]);
|
|
638
|
-
var loginCommandSchema = z5.discriminatedUnion("command", [
|
|
639
|
-
z5.strictObject({ command: z5.literal("state") }),
|
|
640
|
-
z5.strictObject({
|
|
641
|
-
command: z5.literal("read"),
|
|
642
|
-
expressions: z5.array(z5.string().nonempty()).nonempty()
|
|
643
|
-
}),
|
|
644
|
-
z5.strictObject({
|
|
645
|
-
command: z5.enum(["write", "force"]),
|
|
646
|
-
values: z5.record(z5.string().nonempty(), z5.string().nonempty())
|
|
647
|
-
}),
|
|
648
|
-
z5.strictObject({
|
|
649
|
-
command: z5.literal("unforce"),
|
|
650
|
-
expressions: z5.array(z5.string().nonempty()),
|
|
651
|
-
restore: z5.boolean()
|
|
652
|
-
}),
|
|
653
|
-
z5.strictObject({ command: z5.enum(["start", "stop"]) }),
|
|
654
|
-
z5.strictObject({
|
|
655
|
-
command: z5.literal("reset"),
|
|
656
|
-
kind: z5.enum(["Warm", "Cold"])
|
|
657
|
-
})
|
|
658
|
-
]);
|
|
659
|
-
var loginResultSchema = z5.union([
|
|
660
|
-
z5.strictObject({ values: z5.record(z5.string(), z5.string()) }),
|
|
661
|
-
z5.strictObject({ state: z5.string(), forced: z5.array(z5.string()) })
|
|
662
|
-
]);
|
|
663
|
-
|
|
664
|
-
// packages/build/src/host/codesys-command.ts
|
|
665
|
-
var codesysCommand = [
|
|
666
|
-
"@echo off",
|
|
667
|
-
"setlocal DisableDelayedExpansion",
|
|
668
|
-
'"%CODESYS_BUILD_EXE%" --profile="%CODESYS_BUILD_PROFILE%" --noUI --runscript="%CODESYS_BUILD_SCRIPT%"',
|
|
669
|
-
'set "CODESYS_BUILD_STATUS=%errorlevel%"',
|
|
670
|
-
'if not "%CODESYS_BUILD_STATUS%"=="0" echo CODESYS Windows exit status: %CODESYS_BUILD_STATUS%',
|
|
671
|
-
"exit /b %CODESYS_BUILD_STATUS%",
|
|
672
|
-
""
|
|
673
|
-
].join(`\r
|
|
674
|
-
`);
|
|
675
|
-
|
|
676
|
-
// packages/build/src/host/codesys-host.ts
|
|
677
|
-
import { execFile as execFile3, spawn as spawn2 } from "node:child_process";
|
|
678
|
-
import { promisify as promisify3 } from "node:util";
|
|
679
568
|
import { z as z6 } from "zod";
|
|
680
569
|
|
|
681
|
-
// packages/build/src/
|
|
682
|
-
import {
|
|
683
|
-
import {
|
|
684
|
-
import {
|
|
685
|
-
codesysTimeouts,
|
|
686
|
-
commandArgumentSchema
|
|
687
|
-
} from "@tsplc/config/build";
|
|
688
|
-
var execute2 = promisify2(execFile2);
|
|
689
|
-
|
|
690
|
-
// packages/build/src/host/codesys-host.ts
|
|
691
|
-
var execute3 = promisify3(execFile3);
|
|
692
|
-
var exitSchema = z6.object({
|
|
693
|
-
pid: z6.int().positive(),
|
|
694
|
-
code: z6.int().nullable(),
|
|
695
|
-
signal: z6.string().nullable()
|
|
696
|
-
});
|
|
697
|
-
|
|
698
|
-
// packages/build/src/host/codesys-worker.ts
|
|
699
|
-
var pythonDirectory = resolve7(packageDirectory, "python");
|
|
700
|
-
var sessionSchema = z7.object({
|
|
701
|
-
directory: z7.string(),
|
|
702
|
-
fingerprint: z7.string(),
|
|
703
|
-
pid: z7.int().positive()
|
|
704
|
-
});
|
|
705
|
-
var phaseSchema = z7.enum(["prepare", "transfer"]);
|
|
706
|
-
var hasCode = (error, code) => error instanceof Error && ("code" in error) && error.code === code;
|
|
707
|
-
var isProcessAlive = (pid) => {
|
|
708
|
-
try {
|
|
709
|
-
process.kill(pid, 0);
|
|
710
|
-
return true;
|
|
711
|
-
} catch (error) {
|
|
712
|
-
if (hasCode(error, "ESRCH")) {
|
|
713
|
-
return false;
|
|
714
|
-
}
|
|
715
|
-
throw error;
|
|
716
|
-
}
|
|
717
|
-
};
|
|
718
|
-
var withWorkerLock = async (config, run) => {
|
|
719
|
-
await mkdir5(resolve7(config.outDir, ".codesys"), { recursive: true });
|
|
720
|
-
const path = resolve7(config.outDir, ".codesys/command.lock");
|
|
721
|
-
const deadline = Date.now() + config.timeouts.build + config.timeouts.startup;
|
|
722
|
-
while (true) {
|
|
723
|
-
const lock = await open(path, "wx").catch((error) => {
|
|
724
|
-
if (hasCode(error, "EEXIST")) {
|
|
725
|
-
return;
|
|
726
|
-
}
|
|
727
|
-
throw error;
|
|
728
|
-
});
|
|
729
|
-
if (lock) {
|
|
730
|
-
try {
|
|
731
|
-
await lock.writeFile(String(process.pid));
|
|
732
|
-
return await run();
|
|
733
|
-
} finally {
|
|
734
|
-
await lock.close();
|
|
735
|
-
await unlink(path);
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
const owner = Number(await readFile5(path, "utf8").catch((error) => {
|
|
739
|
-
if (hasCode(error, "ENOENT")) {
|
|
740
|
-
return "";
|
|
741
|
-
}
|
|
742
|
-
throw error;
|
|
743
|
-
}));
|
|
744
|
-
if (owner > 0 && !isProcessAlive(owner)) {
|
|
745
|
-
throw new Error(`An interrupted command left ${path}. Remove that lock file and retry.`);
|
|
746
|
-
}
|
|
747
|
-
if (Date.now() >= deadline) {
|
|
748
|
-
throw new Error(`Timed out waiting for another CODESYS command (${path})`);
|
|
749
|
-
}
|
|
750
|
-
await delay(200);
|
|
751
|
-
}
|
|
752
|
-
};
|
|
753
|
-
|
|
754
|
-
// packages/build/src/sources.ts
|
|
755
|
-
import { readdir as readdir2, readFile as readFile6 } from "node:fs/promises";
|
|
756
|
-
import { basename as basename4, resolve as resolve8 } from "node:path";
|
|
757
|
-
import { identifierPattern as identifierPattern3 } from "@tsplc/iec/st";
|
|
570
|
+
// packages/build/src/online-change-check.ts
|
|
571
|
+
import { elementaryType } from "@tsplc/iec";
|
|
572
|
+
import { z as z5 } from "zod";
|
|
758
573
|
|
|
759
|
-
// packages/build/src/
|
|
760
|
-
import {
|
|
761
|
-
|
|
574
|
+
// packages/build/src/st/declarations.ts
|
|
575
|
+
import {
|
|
576
|
+
conditionalDirective,
|
|
577
|
+
modifiers,
|
|
578
|
+
qualifiers,
|
|
579
|
+
variableSections
|
|
580
|
+
} from "@tsplc/iec/st";
|
|
762
581
|
|
|
763
582
|
// packages/build/src/st/lexer.ts
|
|
764
583
|
import { blockCommentEnd, lineCommentEnd, stringEnd } from "@tsplc/iec/st";
|
|
@@ -853,122 +672,6 @@ var tokenize = (source, filename = "<source>") => {
|
|
|
853
672
|
return tokens;
|
|
854
673
|
};
|
|
855
674
|
|
|
856
|
-
// packages/build/src/io.ts
|
|
857
|
-
var span = (type) => ioArray(type) ?? { element: type, length: 1 };
|
|
858
|
-
var addressSize = (type) => {
|
|
859
|
-
const bits = ioScalarBits(type);
|
|
860
|
-
return bits === undefined || bits === 64 ? undefined : sizePrefix(bits);
|
|
861
|
-
};
|
|
862
|
-
function bindStructuredTextIo(objects, bindings) {
|
|
863
|
-
const declarations = [];
|
|
864
|
-
const visit = (object) => {
|
|
865
|
-
const tokens = tokenize(object.declaration, object.source);
|
|
866
|
-
let section = false;
|
|
867
|
-
let start = 0;
|
|
868
|
-
for (const [index, token] of tokens.entries()) {
|
|
869
|
-
if (variableSections.has(token.value)) {
|
|
870
|
-
section = true;
|
|
871
|
-
start = index + 1;
|
|
872
|
-
continue;
|
|
873
|
-
}
|
|
874
|
-
if (token.value === "END_VAR") {
|
|
875
|
-
section = false;
|
|
876
|
-
continue;
|
|
877
|
-
}
|
|
878
|
-
if (!section || token.value !== ";") {
|
|
879
|
-
continue;
|
|
880
|
-
}
|
|
881
|
-
const part = tokens.slice(start, index).filter((t) => t.kind !== "pragma");
|
|
882
|
-
start = index + 1;
|
|
883
|
-
const colon = part.find((t) => t.value === ":");
|
|
884
|
-
if (!colon) {
|
|
885
|
-
continue;
|
|
886
|
-
}
|
|
887
|
-
const colonIndex = part.indexOf(colon);
|
|
888
|
-
if (colonIndex < 1) {
|
|
889
|
-
continue;
|
|
890
|
-
}
|
|
891
|
-
const names = part.slice(0, colonIndex).filter((t) => t.kind === "word" && !qualifiers.has(t.value) && t.value !== "AT");
|
|
892
|
-
const at = part.find((t) => t.value === "AT");
|
|
893
|
-
const variables = at ? names.filter((t) => t.start < at.start) : names;
|
|
894
|
-
const initializer = part.findIndex((t, index) => index > colonIndex && t.value === ":=");
|
|
895
|
-
const typeTokens = part.slice(colonIndex + 1, initializer < 0 ? undefined : initializer);
|
|
896
|
-
const [first] = typeTokens;
|
|
897
|
-
const last = typeTokens.at(-1);
|
|
898
|
-
const type = first && last ? object.declaration.slice(first.start, last.end).replace(/\s+/g, " ").toUpperCase() : "";
|
|
899
|
-
for (const name of variables) {
|
|
900
|
-
declarations.push({
|
|
901
|
-
object,
|
|
902
|
-
name: name.value,
|
|
903
|
-
names: variables,
|
|
904
|
-
colon,
|
|
905
|
-
type
|
|
906
|
-
});
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
object.children.forEach(visit);
|
|
910
|
-
};
|
|
911
|
-
objects.forEach(visit);
|
|
912
|
-
const edits = new Map;
|
|
913
|
-
for (const [symbol, binding] of Object.entries(bindings)) {
|
|
914
|
-
const parts = symbol.toUpperCase().split(".");
|
|
915
|
-
if (parts.length > 2) {
|
|
916
|
-
throw new Error(`${symbol}: direct IO maps a scalar declaration, not a nested field.`);
|
|
917
|
-
}
|
|
918
|
-
const matches = declarations.filter((d) => d.name === parts.at(-1) && (parts.length === 1 || d.object.name.toUpperCase() === parts[0]));
|
|
919
|
-
const [declaration, ...others] = matches;
|
|
920
|
-
if (!declaration || others.length) {
|
|
921
|
-
throw new Error(`${symbol}: expected one ST variable declaration, found ${matches.length}. Use Object.Variable to disambiguate.`);
|
|
922
|
-
}
|
|
923
|
-
const [variable, ...siblings] = declaration.names;
|
|
924
|
-
if (!variable || siblings.length) {
|
|
925
|
-
throw new Error(`${symbol}: declare mapped IO variables separately.`);
|
|
926
|
-
}
|
|
927
|
-
const declared = span(declaration.type);
|
|
928
|
-
const size = addressSize(declared.element);
|
|
929
|
-
if (!size || declared.length > 1 && declared.element === "BOOL" || binding.address[2] !== size) {
|
|
930
|
-
throw new Error(`${symbol}: ${declaration.type} is incompatible with ${binding.address}.`);
|
|
931
|
-
}
|
|
932
|
-
const expected = binding.type && span(binding.type.replace(/\s+/g, " ").toUpperCase());
|
|
933
|
-
if (expected && (expected.element !== declared.element || expected.length !== declared.length)) {
|
|
934
|
-
throw new Error(`${symbol}: expected ${binding.type}, found ${declaration.type}.`);
|
|
935
|
-
}
|
|
936
|
-
const list = edits.get(declaration.object) ?? [];
|
|
937
|
-
const start = variable.end;
|
|
938
|
-
if (list.some((e) => e.start === start)) {
|
|
939
|
-
throw new Error(`${symbol}: the variable has more than one IO binding.`);
|
|
940
|
-
}
|
|
941
|
-
list.push({
|
|
942
|
-
start,
|
|
943
|
-
end: declaration.colon.start,
|
|
944
|
-
text: ` AT ${binding.address} `
|
|
945
|
-
});
|
|
946
|
-
edits.set(declaration.object, list);
|
|
947
|
-
}
|
|
948
|
-
for (const [object, list] of edits) {
|
|
949
|
-
for (const edit of list.sort((a, b) => b.start - a.start)) {
|
|
950
|
-
object.declaration = object.declaration.slice(0, edit.start) + edit.text + object.declaration.slice(edit.end);
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
// packages/build/src/st/parse.ts
|
|
956
|
-
import { basename as basename3 } from "node:path";
|
|
957
|
-
import {
|
|
958
|
-
globalSections,
|
|
959
|
-
identifierPattern as identifierPattern2,
|
|
960
|
-
qualifiers as qualifiers3,
|
|
961
|
-
variableSections as variableSections3
|
|
962
|
-
} from "@tsplc/iec/st";
|
|
963
|
-
|
|
964
|
-
// packages/build/src/st/declarations.ts
|
|
965
|
-
import {
|
|
966
|
-
conditionalDirective,
|
|
967
|
-
modifiers,
|
|
968
|
-
qualifiers as qualifiers2,
|
|
969
|
-
variableSections as variableSections2
|
|
970
|
-
} from "@tsplc/iec/st";
|
|
971
|
-
|
|
972
675
|
// packages/build/src/st/reader.ts
|
|
973
676
|
var createTokenReader = (source, filename) => {
|
|
974
677
|
const tokens = tokenize(source, filename);
|
|
@@ -1028,7 +731,7 @@ var closingObjects = new Set(Object.keys(objectKinds).map((kind) => `END_${kind}
|
|
|
1028
731
|
var declarationKeywords = new Set([
|
|
1029
732
|
...Object.keys(objectKinds),
|
|
1030
733
|
...closingObjects,
|
|
1031
|
-
...
|
|
734
|
+
...variableSections,
|
|
1032
735
|
"END_VAR",
|
|
1033
736
|
"TYPE",
|
|
1034
737
|
"END_TYPE",
|
|
@@ -1132,7 +835,7 @@ var readVariableSection = (reader) => {
|
|
|
1132
835
|
const conditionals = [];
|
|
1133
836
|
while (reader.peek()?.value !== "END_VAR") {
|
|
1134
837
|
const token = reader.take();
|
|
1135
|
-
if (
|
|
838
|
+
if (variableSections.has(token.value) || closingObjects.has(token.value)) {
|
|
1136
839
|
reader.fail("Missing END_VAR", token);
|
|
1137
840
|
}
|
|
1138
841
|
const directive = token.kind === "pragma" && conditionalDirective(token.value);
|
|
@@ -1169,7 +872,7 @@ var readDeclarationSections = (reader) => {
|
|
|
1169
872
|
ahead++;
|
|
1170
873
|
}
|
|
1171
874
|
const next = reader.peek(ahead)?.value ?? "";
|
|
1172
|
-
if (
|
|
875
|
+
if (variableSections.has(next)) {
|
|
1173
876
|
readDeclarationPragmas(reader);
|
|
1174
877
|
readVariableSection(reader);
|
|
1175
878
|
continue;
|
|
@@ -1195,7 +898,326 @@ var keptSections = new Set([
|
|
|
1195
898
|
"VAR_GLOBAL"
|
|
1196
899
|
]);
|
|
1197
900
|
|
|
901
|
+
// packages/build/src/online-change-check.ts
|
|
902
|
+
var committedObjectSchema = z5.lazy(() => z5.looseObject({
|
|
903
|
+
kind: z5.string(),
|
|
904
|
+
name: z5.string(),
|
|
905
|
+
declaration: z5.string(),
|
|
906
|
+
children: z5.array(committedObjectSchema).optional()
|
|
907
|
+
}));
|
|
908
|
+
var onlineChangeFindingSchema = z5.strictObject({
|
|
909
|
+
kind: z5.enum(["type", "tasks", "restart"]),
|
|
910
|
+
refuses: z5.boolean(),
|
|
911
|
+
object: z5.string(),
|
|
912
|
+
variable: z5.string().nullable(),
|
|
913
|
+
before: z5.string().nullable(),
|
|
914
|
+
after: z5.string().nullable(),
|
|
915
|
+
advice: z5.string()
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
// packages/build/src/controller-protocol.ts
|
|
919
|
+
var imageIdSchema = z6.string().regex(/^sha256:[a-f0-9]{64}$/);
|
|
920
|
+
var endpointSchema = z6.strictObject({
|
|
921
|
+
host: z6.string().nonempty(),
|
|
922
|
+
port: tcpPort
|
|
923
|
+
});
|
|
924
|
+
var controllerResultSchema = z6.strictObject({
|
|
925
|
+
schemaVersion: z6.literal(1),
|
|
926
|
+
operationId: z6.uuid(),
|
|
927
|
+
operation: z6.enum(["download", "online-change", "inspect"]),
|
|
928
|
+
imageId: imageIdSchema,
|
|
929
|
+
engineering: sha256Digest.optional(),
|
|
930
|
+
templateHash: sha256Digest,
|
|
931
|
+
target: z6.strictObject({
|
|
932
|
+
network: z6.string().nonempty(),
|
|
933
|
+
gateway: endpointSchema,
|
|
934
|
+
device: endpointSchema,
|
|
935
|
+
controller: controllerSchema.optional(),
|
|
936
|
+
deviceTree: sha256Digest.optional()
|
|
937
|
+
}),
|
|
938
|
+
generation: z6.string().nonempty(),
|
|
939
|
+
application: z6.string().nonempty(),
|
|
940
|
+
applicationGuid: z6.string().nonempty(),
|
|
941
|
+
controllerIds: z6.strictObject({
|
|
942
|
+
codeId: z6.string().nonempty(),
|
|
943
|
+
dataId: z6.string().nonempty()
|
|
944
|
+
}),
|
|
945
|
+
state: z6.string().nonempty(),
|
|
946
|
+
values: z6.record(z6.string(), z6.string())
|
|
947
|
+
});
|
|
948
|
+
var controllerCredentialsSchema = z6.strictObject({
|
|
949
|
+
username: z6.string().nonempty(),
|
|
950
|
+
password: z6.string().nonempty()
|
|
951
|
+
});
|
|
952
|
+
var warmOperationSchema = z6.strictObject({
|
|
953
|
+
operation: z6.enum(["download", "online-change", "review"]),
|
|
954
|
+
operationId: z6.uuid(),
|
|
955
|
+
request: z6.string().nonempty(),
|
|
956
|
+
initializeUser: z6.boolean(),
|
|
957
|
+
credentials: controllerCredentialsSchema.optional()
|
|
958
|
+
});
|
|
959
|
+
var tracebackFailure = (traceback) => {
|
|
960
|
+
const text = traceback.trim();
|
|
961
|
+
const lastFrame = text.lastIndexOf(`
|
|
962
|
+
File `);
|
|
963
|
+
if (lastFrame === -1) {
|
|
964
|
+
return text;
|
|
965
|
+
}
|
|
966
|
+
const [, ...rest] = text.slice(lastFrame + 1).split(`
|
|
967
|
+
`);
|
|
968
|
+
return ((rest[0]?.startsWith(" ")) ? rest.slice(1) : rest).join(`
|
|
969
|
+
`);
|
|
970
|
+
};
|
|
971
|
+
var controllerTarget = (config, online) => ({
|
|
972
|
+
network: online.network,
|
|
973
|
+
gateway: online.gateway,
|
|
974
|
+
device: online.device,
|
|
975
|
+
controller: config.controller,
|
|
976
|
+
...config.deviceTree && {
|
|
977
|
+
deviceTree: deviceTreeStructure(config.deviceTree)
|
|
978
|
+
}
|
|
979
|
+
});
|
|
980
|
+
var sameBuilder = (state, expected) => state.engineering && expected.engineering ? state.engineering === expected.engineering : state.imageId === expected.imageId;
|
|
981
|
+
var sameBaseline = (state, expected) => sameBuilder(state, expected) && state.templateHash === expected.templateHash && JSON.stringify(state.target) === JSON.stringify(expected.target);
|
|
982
|
+
var reviewReplySchema = z6.strictObject({
|
|
983
|
+
findings: z6.array(onlineChangeFindingSchema)
|
|
984
|
+
});
|
|
985
|
+
var rollbackSchema = z6.enum([
|
|
986
|
+
"intact",
|
|
987
|
+
"restored",
|
|
988
|
+
"failed",
|
|
989
|
+
"unavailable"
|
|
990
|
+
]);
|
|
991
|
+
var loginCommandSchema = z6.discriminatedUnion("command", [
|
|
992
|
+
z6.strictObject({ command: z6.literal("state") }),
|
|
993
|
+
z6.strictObject({
|
|
994
|
+
command: z6.literal("read"),
|
|
995
|
+
expressions: z6.array(z6.string().nonempty()).nonempty()
|
|
996
|
+
}),
|
|
997
|
+
z6.strictObject({
|
|
998
|
+
command: z6.enum(["write", "force"]),
|
|
999
|
+
values: z6.record(z6.string().nonempty(), z6.string().nonempty())
|
|
1000
|
+
}),
|
|
1001
|
+
z6.strictObject({
|
|
1002
|
+
command: z6.literal("unforce"),
|
|
1003
|
+
expressions: z6.array(z6.string().nonempty()),
|
|
1004
|
+
restore: z6.boolean()
|
|
1005
|
+
}),
|
|
1006
|
+
z6.strictObject({ command: z6.enum(["start", "stop"]) }),
|
|
1007
|
+
z6.strictObject({
|
|
1008
|
+
command: z6.literal("reset"),
|
|
1009
|
+
kind: z6.enum(["Warm", "Cold"])
|
|
1010
|
+
})
|
|
1011
|
+
]);
|
|
1012
|
+
var loginResultSchema = z6.union([
|
|
1013
|
+
z6.strictObject({ values: z6.record(z6.string(), z6.string()) }),
|
|
1014
|
+
z6.strictObject({ state: z6.string(), forced: z6.array(z6.string()) })
|
|
1015
|
+
]);
|
|
1016
|
+
|
|
1017
|
+
// packages/build/src/host/codesys-command.ts
|
|
1018
|
+
var codesysCommand = [
|
|
1019
|
+
"@echo off",
|
|
1020
|
+
"setlocal DisableDelayedExpansion",
|
|
1021
|
+
'"%CODESYS_BUILD_EXE%" --profile="%CODESYS_BUILD_PROFILE%" --noUI --runscript="%CODESYS_BUILD_SCRIPT%"',
|
|
1022
|
+
'set "CODESYS_BUILD_STATUS=%errorlevel%"',
|
|
1023
|
+
'if not "%CODESYS_BUILD_STATUS%"=="0" echo CODESYS Windows exit status: %CODESYS_BUILD_STATUS%',
|
|
1024
|
+
"exit /b %CODESYS_BUILD_STATUS%",
|
|
1025
|
+
""
|
|
1026
|
+
].join(`\r
|
|
1027
|
+
`);
|
|
1028
|
+
|
|
1029
|
+
// packages/build/src/host/codesys-host.ts
|
|
1030
|
+
import { execFile as execFile3, spawn as spawn2 } from "node:child_process";
|
|
1031
|
+
import { promisify as promisify3 } from "node:util";
|
|
1032
|
+
import { z as z7 } from "zod";
|
|
1033
|
+
|
|
1034
|
+
// packages/build/src/host/windows-path.ts
|
|
1035
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
1036
|
+
import { promisify as promisify2 } from "node:util";
|
|
1037
|
+
import {
|
|
1038
|
+
codesysTimeouts,
|
|
1039
|
+
commandArgumentSchema
|
|
1040
|
+
} from "@tsplc/config/build";
|
|
1041
|
+
var execute2 = promisify2(execFile2);
|
|
1042
|
+
|
|
1043
|
+
// packages/build/src/host/codesys-host.ts
|
|
1044
|
+
var execute3 = promisify3(execFile3);
|
|
1045
|
+
var exitSchema = z7.object({
|
|
1046
|
+
pid: z7.int().positive(),
|
|
1047
|
+
code: z7.int().nullable(),
|
|
1048
|
+
signal: z7.string().nullable()
|
|
1049
|
+
});
|
|
1050
|
+
|
|
1051
|
+
// packages/build/src/host/codesys-worker.ts
|
|
1052
|
+
var pythonDirectory = resolve7(packageDirectory, "python");
|
|
1053
|
+
var sessionSchema = z8.object({
|
|
1054
|
+
directory: z8.string(),
|
|
1055
|
+
fingerprint: z8.string(),
|
|
1056
|
+
pid: z8.int().positive()
|
|
1057
|
+
});
|
|
1058
|
+
var phaseSchema = z8.enum(["prepare", "transfer"]);
|
|
1059
|
+
var hasCode = (error, code) => error instanceof Error && ("code" in error) && error.code === code;
|
|
1060
|
+
var isProcessAlive = (pid) => {
|
|
1061
|
+
try {
|
|
1062
|
+
process.kill(pid, 0);
|
|
1063
|
+
return true;
|
|
1064
|
+
} catch (error) {
|
|
1065
|
+
if (hasCode(error, "ESRCH")) {
|
|
1066
|
+
return false;
|
|
1067
|
+
}
|
|
1068
|
+
throw error;
|
|
1069
|
+
}
|
|
1070
|
+
};
|
|
1071
|
+
var withWorkerLock = async (config, run) => {
|
|
1072
|
+
await mkdir5(resolve7(config.outDir, ".codesys"), { recursive: true });
|
|
1073
|
+
const path = resolve7(config.outDir, ".codesys/command.lock");
|
|
1074
|
+
const deadline = Date.now() + config.timeouts.build + config.timeouts.startup;
|
|
1075
|
+
while (true) {
|
|
1076
|
+
const lock = await open(path, "wx").catch((error) => {
|
|
1077
|
+
if (hasCode(error, "EEXIST")) {
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1080
|
+
throw error;
|
|
1081
|
+
});
|
|
1082
|
+
if (lock) {
|
|
1083
|
+
try {
|
|
1084
|
+
await lock.writeFile(String(process.pid));
|
|
1085
|
+
return await run();
|
|
1086
|
+
} finally {
|
|
1087
|
+
await lock.close();
|
|
1088
|
+
await unlink(path);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
const owner = Number(await readFile5(path, "utf8").catch((error) => {
|
|
1092
|
+
if (hasCode(error, "ENOENT")) {
|
|
1093
|
+
return "";
|
|
1094
|
+
}
|
|
1095
|
+
throw error;
|
|
1096
|
+
}));
|
|
1097
|
+
if (owner > 0 && !isProcessAlive(owner)) {
|
|
1098
|
+
throw new Error(`An interrupted command left ${path}. Remove that lock file and retry.`);
|
|
1099
|
+
}
|
|
1100
|
+
if (Date.now() >= deadline) {
|
|
1101
|
+
throw new Error(`Timed out waiting for another CODESYS command (${path})`);
|
|
1102
|
+
}
|
|
1103
|
+
await delay(200);
|
|
1104
|
+
}
|
|
1105
|
+
};
|
|
1106
|
+
|
|
1107
|
+
// packages/build/src/sources.ts
|
|
1108
|
+
import { readdir as readdir2, readFile as readFile6 } from "node:fs/promises";
|
|
1109
|
+
import { basename as basename4, resolve as resolve8 } from "node:path";
|
|
1110
|
+
import { identifierPattern as identifierPattern3 } from "@tsplc/iec/st";
|
|
1111
|
+
|
|
1112
|
+
// packages/build/src/io.ts
|
|
1113
|
+
import { ioArray, ioScalarBits, sizePrefix } from "@tsplc/iec";
|
|
1114
|
+
import { qualifiers as qualifiers2, variableSections as variableSections2 } from "@tsplc/iec/st";
|
|
1115
|
+
var span = (type) => ioArray(type) ?? { element: type, length: 1 };
|
|
1116
|
+
var addressSize = (type) => {
|
|
1117
|
+
const bits = ioScalarBits(type);
|
|
1118
|
+
return bits === undefined || bits === 64 ? undefined : sizePrefix(bits);
|
|
1119
|
+
};
|
|
1120
|
+
function bindStructuredTextIo(objects, bindings) {
|
|
1121
|
+
const declarations = [];
|
|
1122
|
+
const visit = (object) => {
|
|
1123
|
+
const tokens = tokenize(object.declaration, object.source);
|
|
1124
|
+
let section = false;
|
|
1125
|
+
let start = 0;
|
|
1126
|
+
for (const [index, token] of tokens.entries()) {
|
|
1127
|
+
if (variableSections2.has(token.value)) {
|
|
1128
|
+
section = true;
|
|
1129
|
+
start = index + 1;
|
|
1130
|
+
continue;
|
|
1131
|
+
}
|
|
1132
|
+
if (token.value === "END_VAR") {
|
|
1133
|
+
section = false;
|
|
1134
|
+
continue;
|
|
1135
|
+
}
|
|
1136
|
+
if (!section || token.value !== ";") {
|
|
1137
|
+
continue;
|
|
1138
|
+
}
|
|
1139
|
+
const part = tokens.slice(start, index).filter((t) => t.kind !== "pragma");
|
|
1140
|
+
start = index + 1;
|
|
1141
|
+
const colon = part.find((t) => t.value === ":");
|
|
1142
|
+
if (!colon) {
|
|
1143
|
+
continue;
|
|
1144
|
+
}
|
|
1145
|
+
const colonIndex = part.indexOf(colon);
|
|
1146
|
+
if (colonIndex < 1) {
|
|
1147
|
+
continue;
|
|
1148
|
+
}
|
|
1149
|
+
const names = part.slice(0, colonIndex).filter((t) => t.kind === "word" && !qualifiers2.has(t.value) && t.value !== "AT");
|
|
1150
|
+
const at = part.find((t) => t.value === "AT");
|
|
1151
|
+
const variables = at ? names.filter((t) => t.start < at.start) : names;
|
|
1152
|
+
const initializer = part.findIndex((t, index) => index > colonIndex && t.value === ":=");
|
|
1153
|
+
const typeTokens = part.slice(colonIndex + 1, initializer < 0 ? undefined : initializer);
|
|
1154
|
+
const [first] = typeTokens;
|
|
1155
|
+
const last = typeTokens.at(-1);
|
|
1156
|
+
const type = first && last ? object.declaration.slice(first.start, last.end).replace(/\s+/g, " ").toUpperCase() : "";
|
|
1157
|
+
for (const name of variables) {
|
|
1158
|
+
declarations.push({
|
|
1159
|
+
object,
|
|
1160
|
+
name: name.value,
|
|
1161
|
+
names: variables,
|
|
1162
|
+
colon,
|
|
1163
|
+
type
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
object.children.forEach(visit);
|
|
1168
|
+
};
|
|
1169
|
+
objects.forEach(visit);
|
|
1170
|
+
const edits = new Map;
|
|
1171
|
+
for (const [symbol, binding] of Object.entries(bindings)) {
|
|
1172
|
+
const parts = symbol.toUpperCase().split(".");
|
|
1173
|
+
if (parts.length > 2) {
|
|
1174
|
+
throw new Error(`${symbol}: direct IO maps a scalar declaration, not a nested field.`);
|
|
1175
|
+
}
|
|
1176
|
+
const matches = declarations.filter((d) => d.name === parts.at(-1) && (parts.length === 1 || d.object.name.toUpperCase() === parts[0]));
|
|
1177
|
+
const [declaration, ...others] = matches;
|
|
1178
|
+
if (!declaration || others.length) {
|
|
1179
|
+
throw new Error(`${symbol}: expected one ST variable declaration, found ${matches.length}. Use Object.Variable to disambiguate.`);
|
|
1180
|
+
}
|
|
1181
|
+
const [variable, ...siblings] = declaration.names;
|
|
1182
|
+
if (!variable || siblings.length) {
|
|
1183
|
+
throw new Error(`${symbol}: declare mapped IO variables separately.`);
|
|
1184
|
+
}
|
|
1185
|
+
const declared = span(declaration.type);
|
|
1186
|
+
const size = addressSize(declared.element);
|
|
1187
|
+
if (!size || declared.length > 1 && declared.element === "BOOL" || binding.address[2] !== size) {
|
|
1188
|
+
throw new Error(`${symbol}: ${declaration.type} is incompatible with ${binding.address}.`);
|
|
1189
|
+
}
|
|
1190
|
+
const expected = binding.type && span(binding.type.replace(/\s+/g, " ").toUpperCase());
|
|
1191
|
+
if (expected && (expected.element !== declared.element || expected.length !== declared.length)) {
|
|
1192
|
+
throw new Error(`${symbol}: expected ${binding.type}, found ${declaration.type}.`);
|
|
1193
|
+
}
|
|
1194
|
+
const list = edits.get(declaration.object) ?? [];
|
|
1195
|
+
const start = variable.end;
|
|
1196
|
+
if (list.some((e) => e.start === start)) {
|
|
1197
|
+
throw new Error(`${symbol}: the variable has more than one IO binding.`);
|
|
1198
|
+
}
|
|
1199
|
+
list.push({
|
|
1200
|
+
start,
|
|
1201
|
+
end: declaration.colon.start,
|
|
1202
|
+
text: ` AT ${binding.address} `
|
|
1203
|
+
});
|
|
1204
|
+
edits.set(declaration.object, list);
|
|
1205
|
+
}
|
|
1206
|
+
for (const [object, list] of edits) {
|
|
1207
|
+
for (const edit of list.sort((a, b) => b.start - a.start)) {
|
|
1208
|
+
object.declaration = object.declaration.slice(0, edit.start) + edit.text + object.declaration.slice(edit.end);
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1198
1213
|
// packages/build/src/st/parse.ts
|
|
1214
|
+
import { basename as basename3 } from "node:path";
|
|
1215
|
+
import {
|
|
1216
|
+
globalSections,
|
|
1217
|
+
identifierPattern as identifierPattern2,
|
|
1218
|
+
qualifiers as qualifiers3,
|
|
1219
|
+
variableSections as variableSections3
|
|
1220
|
+
} from "@tsplc/iec/st";
|
|
1199
1221
|
var dutTypes = {
|
|
1200
1222
|
STRUCT: "structure",
|
|
1201
1223
|
UNION: "union",
|
|
@@ -1563,18 +1585,6 @@ import {
|
|
|
1563
1585
|
sha256Digest as sha256Digest2
|
|
1564
1586
|
} from "@tsplc/config/build";
|
|
1565
1587
|
import { z as z9 } from "zod";
|
|
1566
|
-
|
|
1567
|
-
// packages/build/src/online-change-check.ts
|
|
1568
|
-
import { elementaryType } from "@tsplc/iec";
|
|
1569
|
-
import { z as z8 } from "zod";
|
|
1570
|
-
var committedObjectSchema = z8.lazy(() => z8.looseObject({
|
|
1571
|
-
kind: z8.string(),
|
|
1572
|
-
name: z8.string(),
|
|
1573
|
-
declaration: z8.string(),
|
|
1574
|
-
children: z8.array(committedObjectSchema).optional()
|
|
1575
|
-
}));
|
|
1576
|
-
|
|
1577
|
-
// packages/build/src/controller-session.ts
|
|
1578
1588
|
var guid = z9.string().regex(/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i);
|
|
1579
1589
|
var pointerSchema = z9.strictObject({
|
|
1580
1590
|
schemaVersion: z9.literal(1),
|
|
@@ -1678,6 +1688,8 @@ var loginReplySchema = z10.discriminatedUnion("ok", [
|
|
|
1678
1688
|
ok: z10.literal(false),
|
|
1679
1689
|
error: z10.string(),
|
|
1680
1690
|
downloadRequired: z10.literal(true).optional(),
|
|
1691
|
+
findings: z10.array(onlineChangeFindingSchema).optional(),
|
|
1692
|
+
messages: z10.array(z10.string()).optional(),
|
|
1681
1693
|
rollback: rollbackSchema.optional()
|
|
1682
1694
|
})
|
|
1683
1695
|
]);
|
|
@@ -2195,6 +2207,8 @@ var loginReplySchema2 = z13.discriminatedUnion("ok", [
|
|
|
2195
2207
|
ok: z13.literal(false),
|
|
2196
2208
|
error: z13.string(),
|
|
2197
2209
|
downloadRequired: z13.literal(true).optional(),
|
|
2210
|
+
findings: z13.array(onlineChangeFindingSchema).optional(),
|
|
2211
|
+
messages: z13.array(z13.string()).optional(),
|
|
2198
2212
|
rollback: rollbackSchema.optional()
|
|
2199
2213
|
})
|
|
2200
2214
|
]);
|
|
@@ -2402,5 +2416,5 @@ try {
|
|
|
2402
2416
|
process.exitCode = 1;
|
|
2403
2417
|
}
|
|
2404
2418
|
|
|
2405
|
-
//# debugId=
|
|
2419
|
+
//# debugId=63E5F7FC312D901464756E2164756E21
|
|
2406
2420
|
//# sourceMappingURL=cli.js.map
|