@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
package/package.json
CHANGED
|
@@ -1,55 +1,56 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
2
|
+
"name": "@tsplc/build",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"description": "Build tsPLC and Structured Text projects with CODESYS in Docker: library installs, compilation, runtime download and online changes.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"plc",
|
|
7
|
+
"codesys",
|
|
8
|
+
"docker",
|
|
9
|
+
"structured-text"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/livingforjesus/tsplc#readme",
|
|
12
|
+
"bugs": "https://github.com/livingforjesus/tsplc/issues",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/livingforjesus/tsplc.git",
|
|
16
|
+
"directory": "packages/build"
|
|
17
|
+
},
|
|
18
|
+
"version": "0.2.18",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./src/index.ts",
|
|
23
|
+
"bun": "./src/index.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./libraries": {
|
|
27
|
+
"types": "./src/libraries.ts",
|
|
28
|
+
"bun": "./src/libraries.ts",
|
|
29
|
+
"default": "./dist/libraries.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"src",
|
|
35
|
+
"python",
|
|
36
|
+
"docker",
|
|
37
|
+
"runtime",
|
|
38
|
+
"!**/*.test.ts",
|
|
39
|
+
"!**/*.fixtures.ts"
|
|
40
|
+
],
|
|
41
|
+
"engines": {
|
|
42
|
+
"bun": ">=1.4.3"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"zod": "4.3.6",
|
|
46
|
+
"@tsplc/config": "0.2.18",
|
|
47
|
+
"@tsplc/typegen": "0.2.18",
|
|
48
|
+
"@tsplc/iec": "0.2.18"
|
|
49
|
+
},
|
|
50
|
+
"bin": {
|
|
51
|
+
"tsplc-build": "./dist/cli.js"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
}
|
|
55
56
|
}
|
package/python/build.py
CHANGED
|
@@ -17,6 +17,15 @@ import time
|
|
|
17
17
|
|
|
18
18
|
from hardware import apply_controller, configure_device_tree, import_device_description, verify_pinned
|
|
19
19
|
|
|
20
|
+
# create_symbol_config's client-side layout calculator; the image check in docker/install/verify.py uses it too.
|
|
21
|
+
SYMBOL_LAYOUT_CALCULATOR = "{0141eb75-141b-4ea1-9a8c-75f952b22a6c}"
|
|
22
|
+
NANOSECONDS_PER_MILLISECOND = 1000000
|
|
23
|
+
# A task interval is a TIME, which counts milliseconds in 32 bits.
|
|
24
|
+
MAX_INTERVAL_NANOSECONDS = 0xFFFFFFFF * NANOSECONDS_PER_MILLISECOND
|
|
25
|
+
MAX_TASK_PRIORITY = 31
|
|
26
|
+
# How a task reads back an interval written in milliseconds, such as T#20ms.
|
|
27
|
+
TIME_MILLISECONDS = re.compile(r"^(?:T|TIME)#([0-9]+(?:\.[0-9]+)?)MS$", re.I)
|
|
28
|
+
|
|
20
29
|
|
|
21
30
|
class CompilerError(RuntimeError):
|
|
22
31
|
def __init__(self, diagnostics):
|
|
@@ -95,6 +104,19 @@ def fail_on_errors(engine):
|
|
|
95
104
|
raise CompilerError(errors)
|
|
96
105
|
|
|
97
106
|
|
|
107
|
+
def clear_diagnostics(engine):
|
|
108
|
+
# Check diagnostics from this compilation, not cached editor-load messages.
|
|
109
|
+
for category in engine.system.get_message_categories():
|
|
110
|
+
engine.system.clear_messages(category)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def write_progress(path, stage):
|
|
114
|
+
with io.open(path, "a", encoding="utf-8") as log:
|
|
115
|
+
log.write(u"{0}Z {1}\n".format(
|
|
116
|
+
time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime()), stage,
|
|
117
|
+
))
|
|
118
|
+
|
|
119
|
+
|
|
98
120
|
def object_key(spec):
|
|
99
121
|
return (spec["kind"], spec["name"], bool(spec.get("persistent")), tuple(spec.get("folder", [])),
|
|
100
122
|
tuple(object_key(child) for child in spec.get("children", [])))
|
|
@@ -184,10 +206,16 @@ def import_object(engine, parent, spec, previous):
|
|
|
184
206
|
return written
|
|
185
207
|
|
|
186
208
|
|
|
209
|
+
def library_references(manager, managed):
|
|
210
|
+
"""The application's references to the managed library's title and company, placeholders excluded."""
|
|
211
|
+
return [reference for reference in list(manager.references) if not unicode(reference.name).startswith("#")
|
|
212
|
+
and unicode(reference.managed_library.title) == unicode(managed.title)
|
|
213
|
+
and unicode(reference.managed_library.company) == unicode(managed.company)]
|
|
214
|
+
|
|
215
|
+
|
|
187
216
|
def install_project_libraries(engine, application, libraries, progress):
|
|
188
217
|
if not libraries:
|
|
189
218
|
return
|
|
190
|
-
import hashlib
|
|
191
219
|
manager = application.get_library_manager()
|
|
192
220
|
# SP22's scripting bridge passes a null repository when the optional argument
|
|
193
221
|
# is omitted. Select the configured first repository explicitly.
|
|
@@ -205,13 +233,7 @@ def install_project_libraries(engine, application, libraries, progress):
|
|
|
205
233
|
for key in ("company", "version"):
|
|
206
234
|
if library.get(key) is not None and unicode(getattr(managed, key)) != library[key]:
|
|
207
235
|
raise RuntimeError("Library " + key + " does not match dependency: " + library["title"])
|
|
208
|
-
matches =
|
|
209
|
-
for reference in list(manager.references):
|
|
210
|
-
if unicode(reference.name).startswith("#"):
|
|
211
|
-
continue
|
|
212
|
-
existing = reference.managed_library
|
|
213
|
-
if unicode(existing.title) == unicode(managed.title) and unicode(existing.company) == unicode(managed.company):
|
|
214
|
-
matches.append(reference)
|
|
236
|
+
matches = library_references(manager, managed)
|
|
215
237
|
if len(matches) > 1:
|
|
216
238
|
raise RuntimeError("Ambiguous existing library reference: " + library["title"])
|
|
217
239
|
exact = matches and unicode(matches[0].managed_library.version) == unicode(managed.version)
|
|
@@ -220,14 +242,12 @@ def install_project_libraries(engine, application, libraries, progress):
|
|
|
220
242
|
for reference in matches:
|
|
221
243
|
manager.remove_library(unicode(reference.name))
|
|
222
244
|
manager.add_library(managed)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
and unicode(reference.managed_library.version) == unicode(managed.version)]
|
|
227
|
-
if len(refs) != 1:
|
|
245
|
+
installed = [reference for reference in library_references(manager, managed)
|
|
246
|
+
if unicode(reference.managed_library.version) == unicode(managed.version)]
|
|
247
|
+
if len(installed) != 1:
|
|
228
248
|
raise RuntimeError("Installed library reference could not be verified: " + library["title"])
|
|
229
249
|
if namespace:
|
|
230
|
-
|
|
250
|
+
installed[0].namespace = namespace
|
|
231
251
|
|
|
232
252
|
|
|
233
253
|
def same_kind(old, fresh):
|
|
@@ -279,6 +299,54 @@ def reconcile(application, previous, current):
|
|
|
279
299
|
return gone
|
|
280
300
|
|
|
281
301
|
|
|
302
|
+
def source_folder(application, path):
|
|
303
|
+
"""The folder at `path` under the application, creating the folders it lacks."""
|
|
304
|
+
parent = application
|
|
305
|
+
for name in path:
|
|
306
|
+
folder = unique_child(parent, name)
|
|
307
|
+
if folder is None:
|
|
308
|
+
# create_folder returns None in CODESYS; resolve the inserted object.
|
|
309
|
+
parent.create_folder(name)
|
|
310
|
+
folder = unique_child(parent, name)
|
|
311
|
+
if folder is None:
|
|
312
|
+
raise RuntimeError("Could not create source folder " + name)
|
|
313
|
+
elif not folder.is_folder:
|
|
314
|
+
raise RuntimeError("Source folder conflicts with IEC object " + name)
|
|
315
|
+
parent = folder
|
|
316
|
+
return parent
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
def clear_template(application, request):
|
|
320
|
+
"""Removes the template's objects the request names for removal or brings from source."""
|
|
321
|
+
for name in request["removeObjects"]:
|
|
322
|
+
for obj in application.find_ignore_transient_objects(name, True):
|
|
323
|
+
obj.remove()
|
|
324
|
+
# Source objects own their complete subtree, including removed methods.
|
|
325
|
+
for spec in request["objects"]:
|
|
326
|
+
existing = application.find_ignore_transient_objects(spec["name"], True)
|
|
327
|
+
if len(existing) > 1:
|
|
328
|
+
raise RuntimeError("Ambiguous IEC object " + spec["name"])
|
|
329
|
+
for obj in existing:
|
|
330
|
+
obj.remove()
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
def configure_entry_task(application, name, entry):
|
|
334
|
+
matches = application.find_ignore_transient_objects(name, True)
|
|
335
|
+
if len(matches) != 1 or not getattr(matches[0], "is_task", False):
|
|
336
|
+
raise RuntimeError("Template must contain one task named " + name)
|
|
337
|
+
task = matches[0]
|
|
338
|
+
# Only this configured task is rewired; its timing and watchdog stay in the template.
|
|
339
|
+
if list(task.pous) == [entry]:
|
|
340
|
+
return
|
|
341
|
+
# Task calls are transient children. Remove the call objects themselves;
|
|
342
|
+
# ScriptPouObjectList.remove can change its list without removing those objects.
|
|
343
|
+
for call in list(task.get_children()):
|
|
344
|
+
call.remove()
|
|
345
|
+
task.pous.add(entry)
|
|
346
|
+
if list(task.pous) != [entry]:
|
|
347
|
+
raise RuntimeError("Could not configure the entry task: " + repr(list(task.pous)))
|
|
348
|
+
|
|
349
|
+
|
|
282
350
|
def import_objects(engine, application, request, previous, progress):
|
|
283
351
|
"""`previous` lists the source objects the project already holds, reconciled with this request;
|
|
284
352
|
None imports every object afresh."""
|
|
@@ -289,49 +357,18 @@ def import_objects(engine, application, request, previous, progress):
|
|
|
289
357
|
manager.add_library(reference)
|
|
290
358
|
progress("Importing source objects")
|
|
291
359
|
if previous is None:
|
|
292
|
-
|
|
293
|
-
for obj in application.find_ignore_transient_objects(name, True):
|
|
294
|
-
obj.remove()
|
|
295
|
-
# Source objects own their complete subtree, including removed methods.
|
|
296
|
-
for spec in request["objects"]:
|
|
297
|
-
existing = application.find_ignore_transient_objects(spec["name"], True)
|
|
298
|
-
if len(existing) > 1:
|
|
299
|
-
raise RuntimeError("Ambiguous IEC object " + spec["name"])
|
|
300
|
-
for obj in existing:
|
|
301
|
-
obj.remove()
|
|
360
|
+
clear_template(application, request)
|
|
302
361
|
held = dict(((tuple(item["folder"]), item["name"].lower()), item) for item in previous or [])
|
|
303
362
|
written = 0
|
|
304
363
|
for spec in request["objects"]:
|
|
305
|
-
parent = application
|
|
306
|
-
for name in spec["folder"]:
|
|
307
|
-
folder = unique_child(parent, name)
|
|
308
|
-
if folder is None:
|
|
309
|
-
# create_folder returns None in CODESYS; resolve the inserted object.
|
|
310
|
-
parent.create_folder(name)
|
|
311
|
-
folder = unique_child(parent, name)
|
|
312
|
-
if folder is None:
|
|
313
|
-
raise RuntimeError("Could not create source folder " + name)
|
|
314
|
-
elif not folder.is_folder:
|
|
315
|
-
raise RuntimeError("Source folder conflicts with IEC object " + name)
|
|
316
|
-
parent = folder
|
|
364
|
+
parent = source_folder(application, spec["folder"])
|
|
317
365
|
written += import_object(engine, parent, spec, held.get((tuple(spec["folder"]), spec["name"].lower())))
|
|
318
366
|
progress("Wrote {0} source objects".format(written))
|
|
319
367
|
if "tasks" in request:
|
|
320
368
|
return configure_tasks(engine, application, request["tasks"], request["objects"])
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
task = matches[0]
|
|
325
|
-
# Only this configured task is rewired; its timing and watchdog stay in the template.
|
|
326
|
-
if list(task.pous) == [request["entry"]]:
|
|
327
|
-
return
|
|
328
|
-
# Task calls are transient children. Remove the call objects themselves;
|
|
329
|
-
# ScriptPouObjectList.remove can change its list without removing those objects.
|
|
330
|
-
for call in list(task.get_children()):
|
|
331
|
-
call.remove()
|
|
332
|
-
task.pous.add(request["entry"])
|
|
333
|
-
if list(task.pous) != [request["entry"]]:
|
|
334
|
-
raise RuntimeError("Could not configure the entry task: " + repr(list(task.pous)))
|
|
369
|
+
configure_entry_task(application, request["task"], request["entry"])
|
|
370
|
+
return None
|
|
371
|
+
|
|
335
372
|
|
|
336
373
|
def device_tasks(application, configuration):
|
|
337
374
|
"""Tasks that only call devices' cycles, such as the EtherNet/IP scanner's, which belong to the device tree."""
|
|
@@ -343,9 +380,8 @@ def device_tasks(application, configuration):
|
|
|
343
380
|
and list(child.pous) and all(unicode(call).split(".")[0] in devices for call in child.pous))
|
|
344
381
|
|
|
345
382
|
|
|
346
|
-
def
|
|
347
|
-
|
|
348
|
-
# Unspecified tasks are removed so template programs cannot execute implicitly; the device tree keeps its own.
|
|
383
|
+
def validate_task_plan(tasks, objects):
|
|
384
|
+
"""Returns the plan's lowercase task names."""
|
|
349
385
|
if not tasks:
|
|
350
386
|
raise RuntimeError("Explicit task plan must not be empty")
|
|
351
387
|
available = set(spec["name"] for spec in objects if spec["kind"] == "program")
|
|
@@ -356,7 +392,7 @@ def configure_tasks(engine, application, tasks, objects):
|
|
|
356
392
|
if name in names or not re.match(r"^[A-Za-z][A-Za-z0-9_]*$", spec["name"]):
|
|
357
393
|
raise RuntimeError("Invalid or duplicate task name " + spec["name"])
|
|
358
394
|
names.add(name)
|
|
359
|
-
if ns <= 0 or ns %
|
|
395
|
+
if ns <= 0 or ns % NANOSECONDS_PER_MILLISECOND or ns > MAX_INTERVAL_NANOSECONDS or isinstance(priority, bool) or not isinstance(priority, int) or not 0 <= priority <= MAX_TASK_PRIORITY:
|
|
360
396
|
raise RuntimeError("Invalid cyclic interval or priority for " + spec["name"])
|
|
361
397
|
if not spec["programs"]:
|
|
362
398
|
raise RuntimeError("Task must schedule at least one PROGRAM: " + spec["name"])
|
|
@@ -364,6 +400,43 @@ def configure_tasks(engine, application, tasks, objects):
|
|
|
364
400
|
if program not in available or program.lower() in scheduled:
|
|
365
401
|
raise RuntimeError("Missing or multiply scheduled source PROGRAM " + program)
|
|
366
402
|
scheduled.add(program.lower())
|
|
403
|
+
return names
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
def configure_task(engine, application, configuration, spec):
|
|
407
|
+
"""Writes only the settings that differ, then reads the task back."""
|
|
408
|
+
matches = application.find_ignore_transient_objects(spec["name"], True)
|
|
409
|
+
if len(matches) > 1 or matches and not getattr(matches[0], "is_task", False):
|
|
410
|
+
raise RuntimeError("Ambiguous or conflicting task name " + spec["name"])
|
|
411
|
+
task = matches[0] if matches else configuration.create_task(spec["name"])
|
|
412
|
+
if task.kind_of_task != engine.KindOfTask.Cyclic:
|
|
413
|
+
task.kind_of_task = engine.KindOfTask.Cyclic
|
|
414
|
+
if str(task.priority) != str(spec["priority"]):
|
|
415
|
+
task.priority = str(spec["priority"])
|
|
416
|
+
if str(task.interval_unit).lower() != "ms":
|
|
417
|
+
task.interval_unit = "ms"
|
|
418
|
+
milliseconds = str(int(spec["intervalNanoseconds"]) // NANOSECONDS_PER_MILLISECOND)
|
|
419
|
+
current = str(task.interval).strip()
|
|
420
|
+
match = TIME_MILLISECONDS.match(current)
|
|
421
|
+
if not match or Decimal(match.group(1)) != Decimal(milliseconds):
|
|
422
|
+
task.interval = milliseconds
|
|
423
|
+
# Preserve call-object GUIDs across source-only online changes.
|
|
424
|
+
if list(task.pous) != spec["programs"]:
|
|
425
|
+
for call in list(task.get_children()):
|
|
426
|
+
call.remove()
|
|
427
|
+
for program in spec["programs"]:
|
|
428
|
+
task.pous.add(program)
|
|
429
|
+
observed = str(task.interval).strip()
|
|
430
|
+
match = TIME_MILLISECONDS.match(observed)
|
|
431
|
+
interval = Decimal(match.group(1) if match else observed)
|
|
432
|
+
if task.kind_of_task != engine.KindOfTask.Cyclic or int(task.priority) != spec["priority"] or str(task.interval_unit).lower() != "ms" or interval != Decimal(milliseconds) or list(task.pous) != spec["programs"]:
|
|
433
|
+
raise RuntimeError("Task configuration readback differs for {0}: {1}, {2}, {3}, {4}".format(spec["name"], task.priority, task.interval, task.interval_unit, list(task.pous)))
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def configure_tasks(engine, application, tasks, objects):
|
|
437
|
+
# An explicit task plan owns the entire schedule in this private project copy.
|
|
438
|
+
# Unspecified tasks are removed so template programs cannot execute implicitly; the device tree keeps its own.
|
|
439
|
+
names = validate_task_plan(tasks, objects)
|
|
367
440
|
configurations = [child for child in application.get_children() if getattr(child, "is_task_configuration", False)]
|
|
368
441
|
if len(configurations) > 1:
|
|
369
442
|
raise RuntimeError("Application contains ambiguous task configurations")
|
|
@@ -373,32 +446,7 @@ def configure_tasks(engine, application, tasks, objects):
|
|
|
373
446
|
if getattr(child, "is_task", False) and child.get_name().lower() not in names | kept:
|
|
374
447
|
child.remove()
|
|
375
448
|
for spec in tasks:
|
|
376
|
-
|
|
377
|
-
if len(matches) > 1 or matches and not getattr(matches[0], "is_task", False):
|
|
378
|
-
raise RuntimeError("Ambiguous or conflicting task name " + spec["name"])
|
|
379
|
-
task = matches[0] if matches else configuration.create_task(spec["name"])
|
|
380
|
-
if task.kind_of_task != engine.KindOfTask.Cyclic:
|
|
381
|
-
task.kind_of_task = engine.KindOfTask.Cyclic
|
|
382
|
-
if str(task.priority) != str(spec["priority"]):
|
|
383
|
-
task.priority = str(spec["priority"])
|
|
384
|
-
if str(task.interval_unit).lower() != "ms":
|
|
385
|
-
task.interval_unit = "ms"
|
|
386
|
-
milliseconds = str(int(spec["intervalNanoseconds"]) // 1000000)
|
|
387
|
-
current = str(task.interval).strip()
|
|
388
|
-
match = re.match(r"^(?:T|TIME)#([0-9]+(?:\.[0-9]+)?)MS$", current, re.I)
|
|
389
|
-
if not match or Decimal(match.group(1)) != Decimal(milliseconds):
|
|
390
|
-
task.interval = milliseconds
|
|
391
|
-
# Preserve call-object GUIDs across source-only online changes.
|
|
392
|
-
if list(task.pous) != spec["programs"]:
|
|
393
|
-
for call in list(task.get_children()):
|
|
394
|
-
call.remove()
|
|
395
|
-
for program in spec["programs"]:
|
|
396
|
-
task.pous.add(program)
|
|
397
|
-
observed = str(task.interval).strip()
|
|
398
|
-
match = re.match(r"^(?:T|TIME)#([0-9]+(?:\.[0-9]+)?)MS$", observed, re.I)
|
|
399
|
-
interval = Decimal(match.group(1) if match else observed)
|
|
400
|
-
if task.kind_of_task != engine.KindOfTask.Cyclic or int(task.priority) != spec["priority"] or str(task.interval_unit).lower() != "ms" or interval != Decimal(milliseconds) or list(task.pous) != spec["programs"]:
|
|
401
|
-
raise RuntimeError("Task configuration readback differs for {0}: {1}, {2}, {3}, {4}".format(spec["name"], task.priority, task.interval, task.interval_unit, list(task.pous)))
|
|
449
|
+
configure_task(engine, application, configuration, spec)
|
|
402
450
|
actual = [child.get_name().lower() for child in configuration.get_children() if getattr(child, "is_task", False)
|
|
403
451
|
and child.get_name().lower() not in kept]
|
|
404
452
|
if set(actual) != names or len(actual) != len(names):
|
|
@@ -406,6 +454,22 @@ def configure_tasks(engine, application, tasks, objects):
|
|
|
406
454
|
return tasks
|
|
407
455
|
|
|
408
456
|
|
|
457
|
+
def import_source(engine, application, request, previous, progress):
|
|
458
|
+
"""Brings the application's source objects to the request's; `previous` lists those it already
|
|
459
|
+
holds, None for a template. Returns the configured task plan, None when the request rewires the template's entry task."""
|
|
460
|
+
gone = reconcile(application, previous, request["objects"]) if previous is not None else []
|
|
461
|
+
configured_tasks = import_objects(engine, application, request, previous, progress)
|
|
462
|
+
for obj in gone:
|
|
463
|
+
obj.remove()
|
|
464
|
+
if request["symbols"] and not any(
|
|
465
|
+
getattr(child, "is_symbol_config", False)
|
|
466
|
+
for child in application.get_children()
|
|
467
|
+
):
|
|
468
|
+
from System import Guid
|
|
469
|
+
application.create_symbol_config(True, True, Guid(SYMBOL_LAYOUT_CALCULATOR))
|
|
470
|
+
return configured_tasks
|
|
471
|
+
|
|
472
|
+
|
|
409
473
|
def scripts_hash(*names):
|
|
410
474
|
"""A cached project is only as current as the scripts that made it."""
|
|
411
475
|
digest = hashlib.sha256()
|
|
@@ -509,14 +573,41 @@ def open_project(engine, request, workspace, progress):
|
|
|
509
573
|
return project, None, pinned, generated
|
|
510
574
|
|
|
511
575
|
|
|
576
|
+
def compile_application(engine, application, progress):
|
|
577
|
+
progress("Clearing previous diagnostics")
|
|
578
|
+
clear_diagnostics(engine)
|
|
579
|
+
progress("Rebuilding application")
|
|
580
|
+
application.clean()
|
|
581
|
+
application.rebuild()
|
|
582
|
+
fail_on_errors(engine)
|
|
583
|
+
progress("Generating application code")
|
|
584
|
+
application.generate_code()
|
|
585
|
+
fail_on_errors(engine)
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
def publish_build(engine, request, project, application, progress):
|
|
589
|
+
"""Writes the compiled project, its archive when it has a device tree, and the boot application."""
|
|
590
|
+
# Keep the open file private to the worker; the published project can be
|
|
591
|
+
# opened interactively without conflicting with this persistent compiler.
|
|
592
|
+
shutil.copyfile(project.path, request["project"])
|
|
593
|
+
if request.get("deviceTree"):
|
|
594
|
+
# An IDE resolves devices from its own repository; the archive carries
|
|
595
|
+
# the generated descriptions and offers to install them on open.
|
|
596
|
+
progress("Saving project archive")
|
|
597
|
+
project.save_archive(os.path.join(os.path.dirname(request["receipt"]), request["archive"]),
|
|
598
|
+
engine.ArchiveCategories.devices, engine.ArchiveCategories.libraries)
|
|
599
|
+
progress("Exporting boot application")
|
|
600
|
+
application.create_boot_application(request["output"], False, False)
|
|
601
|
+
fail_on_errors(engine)
|
|
602
|
+
if not os.path.isfile(request["output"]) or os.path.getsize(request["output"]) == 0:
|
|
603
|
+
raise RuntimeError("Compiler did not produce a non-empty boot application")
|
|
604
|
+
|
|
605
|
+
|
|
512
606
|
def build(engine, request, loaded, workspace):
|
|
513
607
|
progress_path = os.path.join(os.path.dirname(request["receipt"]), "progress.log")
|
|
514
608
|
|
|
515
609
|
def progress(stage):
|
|
516
|
-
|
|
517
|
-
log.write(u"{0}Z {1}\n".format(
|
|
518
|
-
time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime()), stage,
|
|
519
|
-
))
|
|
610
|
+
write_progress(progress_path, stage)
|
|
520
611
|
|
|
521
612
|
# Reopen when the template or object membership changes, so removed/renamed
|
|
522
613
|
# declarations cannot survive from an earlier build. Text changes are imported below.
|
|
@@ -537,54 +628,22 @@ def build(engine, request, loaded, workspace):
|
|
|
537
628
|
application = project.active_application
|
|
538
629
|
if application is None:
|
|
539
630
|
raise RuntimeError("Template must have an active Application")
|
|
540
|
-
|
|
541
|
-
configured_tasks = import_objects(engine, application, request, previous, progress)
|
|
542
|
-
for obj in gone:
|
|
543
|
-
obj.remove()
|
|
544
|
-
if request["symbols"] and not any(
|
|
545
|
-
getattr(child, "is_symbol_config", False)
|
|
546
|
-
for child in application.get_children()
|
|
547
|
-
):
|
|
548
|
-
from System import Guid
|
|
549
|
-
application.create_symbol_config(True, True, Guid("{0141eb75-141b-4ea1-9a8c-75f952b22a6c}"))
|
|
631
|
+
configured_tasks = import_source(engine, application, request, previous, progress)
|
|
550
632
|
progress("Saving generated project")
|
|
551
633
|
project.save()
|
|
552
|
-
|
|
553
|
-
# Check diagnostics from this compilation, not cached editor-load messages.
|
|
554
|
-
for category in engine.system.get_message_categories():
|
|
555
|
-
engine.system.clear_messages(category)
|
|
556
|
-
progress("Rebuilding application")
|
|
557
|
-
application.clean()
|
|
558
|
-
application.rebuild()
|
|
559
|
-
fail_on_errors(engine)
|
|
560
|
-
progress("Generating application code")
|
|
561
|
-
application.generate_code()
|
|
562
|
-
fail_on_errors(engine)
|
|
634
|
+
compile_application(engine, application, progress)
|
|
563
635
|
verify_pinned(pinned)
|
|
564
636
|
project.save()
|
|
565
|
-
|
|
566
|
-
# opened interactively without conflicting with this persistent compiler.
|
|
567
|
-
shutil.copyfile(project.path, request["project"])
|
|
568
|
-
if request.get("deviceTree"):
|
|
569
|
-
# An IDE resolves devices from its own repository; the archive carries
|
|
570
|
-
# the generated descriptions and offers to install them on open.
|
|
571
|
-
progress("Saving project archive")
|
|
572
|
-
project.save_archive(os.path.join(os.path.dirname(request["receipt"]), request["archive"]),
|
|
573
|
-
engine.ArchiveCategories.devices, engine.ArchiveCategories.libraries)
|
|
574
|
-
progress("Exporting boot application")
|
|
575
|
-
application.create_boot_application(request["output"], False, False)
|
|
576
|
-
fail_on_errors(engine)
|
|
577
|
-
if not os.path.isfile(request["output"]) or os.path.getsize(request["output"]) == 0:
|
|
578
|
-
raise RuntimeError("Compiler did not produce a non-empty boot application")
|
|
637
|
+
publish_build(engine, request, project, application, progress)
|
|
579
638
|
if generated:
|
|
580
639
|
keep_device_tree(*generated)
|
|
581
640
|
keep_build(project.path, request["objects"], build_cache(request, os.path.dirname(workspace)))
|
|
582
641
|
progress("Build complete")
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
))
|
|
642
|
+
receipt = {"mode": request["mode"], "application": application.get_name()}
|
|
643
|
+
if configured_tasks is not None:
|
|
644
|
+
receipt["tasks"] = configured_tasks
|
|
645
|
+
with io.open(request["receipt"], "w", encoding="utf-8") as output:
|
|
646
|
+
output.write(json.dumps(receipt, ensure_ascii=False))
|
|
588
647
|
loaded.update({"key": key, "objects": request["objects"], "project": project})
|
|
589
648
|
except Exception:
|
|
590
649
|
loaded.clear()
|