a | b/codesys-ide/scripts/buildtest.py | ||
---|---|---|---|
1 | import sys, os |
||
2 | import helper |
||
3 | |||
4 | # disable prompts, as those are enabled in UI mode by default |
||
5 | system.prompt_handling = PromptHandling.None |
||
6 | |||
7 | def createtest(filename): |
||
8 | destination = filename + ".app" |
||
9 | devId = None |
||
10 | devices = device_repository.get_all_devices("CODESYS Control for Linux SL") |
||
11 | for device in devices: |
||
12 | devId = device.device_id |
||
13 | proj = projects.primary |
||
14 | |||
15 | # check if this is a unit test project |
||
16 | prg_runtest = proj.find('PRG_RUNTEST') |
||
17 | if len(prg_runtest) == 0: |
||
18 | proj.close() |
||
19 | return None |
||
20 | |||
21 | # delete existing testdev device |
||
22 | existing = proj.find('testdev') |
||
23 | if len(existing) > 0: |
||
24 | existing[0].remove() |
||
25 | |||
26 | # add device |
||
27 | proj.add('testdev', devId) |
||
28 | apps = proj.find('Application', True) |
||
29 | if len(apps) > 0: |
||
30 | app = apps[0] |
||
31 | tc = app.create_task_configuration() |
||
32 | |||
33 | # add task to call PRG_RUNTEST |
||
34 | task = tc.create_task('Task') |
||
35 | task.pous.add('PRG_RUNTEST') |
||
36 | |||
37 | helper.install_missing_libraries(proj, librarymanager) |
||
38 | # proj.save() |
||
39 | print("create bootapp '%s'" % destination) |
||
40 | proj.active_application.create_boot_application(destination) |
||
41 | proj.close() |
||
42 | return destination |
||
43 | |||
44 | |||
45 | class SearchBuildDo(helper.SearchBuild): |
||
46 | # Test rules for: |
||
47 | # - *.library |
||
48 | def doit(self, filename): |
||
49 | artifacts = list() |
||
50 | helper.install_requirements(filename, librarymanager) |
||
51 | |||
52 | if filename.endswith(".library"): |
||
53 | print("\n\n*** Create test application for: %s" % filename) |
||
54 | proj = projects.open(filename) |
||
55 | artifact = createtest(filename) |
||
56 | if artifact != None: |
||
57 | artifacts.append(artifact) |
||
58 | |||
59 | return artifacts |
||
60 | |||
61 | scriptpath = os.path.abspath(os.path.dirname(sys.argv[0])) |
||
62 | |||
63 | sb = SearchBuildDo() |
||
64 | sb.search(".library", ".") |
||
65 | sb.save(".", ".drone-artifacts") |
||
66 |