pyalamake 0.0.1__tar.gz

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.
Files changed (69) hide show
  1. pyalamake-0.0.1/LICENSE.txt +21 -0
  2. pyalamake-0.0.1/MANIFEST.in +2 -0
  3. pyalamake-0.0.1/PKG-INFO +203 -0
  4. pyalamake-0.0.1/README.md +182 -0
  5. pyalamake-0.0.1/pyalamake/__init__.py +0 -0
  6. pyalamake-0.0.1/pyalamake/lib/.gitignore +2 -0
  7. pyalamake-0.0.1/pyalamake/lib/__init__.py +0 -0
  8. pyalamake-0.0.1/pyalamake/lib/arduino_shared.py +114 -0
  9. pyalamake-0.0.1/pyalamake/lib/boards.json +457 -0
  10. pyalamake-0.0.1/pyalamake/lib/build_info.py +10 -0
  11. pyalamake-0.0.1/pyalamake/lib/gbl.py +7 -0
  12. pyalamake-0.0.1/pyalamake/lib/logger.py +158 -0
  13. pyalamake-0.0.1/pyalamake/lib/pyalamake.py +175 -0
  14. pyalamake-0.0.1/pyalamake/lib/svc.py +24 -0
  15. pyalamake-0.0.1/pyalamake/lib/target_arduino.py +162 -0
  16. pyalamake-0.0.1/pyalamake/lib/target_arduino_core.py +133 -0
  17. pyalamake-0.0.1/pyalamake/lib/target_base.py +124 -0
  18. pyalamake-0.0.1/pyalamake/lib/target_cpp.py +115 -0
  19. pyalamake-0.0.1/pyalamake/lib/target_gtest.py +165 -0
  20. pyalamake-0.0.1/pyalamake/lib/version.json +3 -0
  21. pyalamake-0.0.1/pyalamake.egg-info/PKG-INFO +203 -0
  22. pyalamake-0.0.1/pyalamake.egg-info/SOURCES.txt +68 -0
  23. pyalamake-0.0.1/pyalamake.egg-info/dependency_links.txt +1 -0
  24. pyalamake-0.0.1/pyalamake.egg-info/requires.txt +2 -0
  25. pyalamake-0.0.1/pyalamake.egg-info/top_level.txt +3 -0
  26. pyalamake-0.0.1/setup.cfg +45 -0
  27. pyalamake-0.0.1/setup.py +47 -0
  28. pyalamake-0.0.1/tools/__init__.py +0 -0
  29. pyalamake-0.0.1/tools/arduino_parsing.py +173 -0
  30. pyalamake-0.0.1/tools/install/__init__.py +0 -0
  31. pyalamake-0.0.1/tools/setup_template.py +47 -0
  32. pyalamake-0.0.1/tools/xplat_utils/__init__.py +1 -0
  33. pyalamake-0.0.1/tools/xplat_utils/cfg.py +415 -0
  34. pyalamake-0.0.1/tools/xplat_utils/do_build.py +97 -0
  35. pyalamake-0.0.1/tools/xplat_utils/do_check.py +910 -0
  36. pyalamake-0.0.1/tools/xplat_utils/do_clean.py +70 -0
  37. pyalamake-0.0.1/tools/xplat_utils/do_coverage.py +113 -0
  38. pyalamake-0.0.1/tools/xplat_utils/do_cpip.py +318 -0
  39. pyalamake-0.0.1/tools/xplat_utils/do_doc.py +158 -0
  40. pyalamake-0.0.1/tools/xplat_utils/do_lint.py +110 -0
  41. pyalamake-0.0.1/tools/xplat_utils/do_post_ver.py +89 -0
  42. pyalamake-0.0.1/tools/xplat_utils/do_publish.py +72 -0
  43. pyalamake-0.0.1/tools/xplat_utils/do_upload.py +60 -0
  44. pyalamake-0.0.1/tools/xplat_utils/do_ver_info.py +70 -0
  45. pyalamake-0.0.1/tools/xplat_utils/gen_build_info.py +207 -0
  46. pyalamake-0.0.1/tools/xplat_utils/gen_files.py +138 -0
  47. pyalamake-0.0.1/tools/xplat_utils/main.py +8 -0
  48. pyalamake-0.0.1/tools/xplat_utils/os_specific.py +416 -0
  49. pyalamake-0.0.1/tools/xplat_utils/svc.py +57 -0
  50. pyalamake-0.0.1/tools/xplat_utils/utils.py +327 -0
  51. pyalamake-0.0.1/tools/xplat_utils/utils_fs.py +151 -0
  52. pyalamake-0.0.1/tools/xplat_utils/utils_logger.py +171 -0
  53. pyalamake-0.0.1/tools/xplat_utils/utils_ps.py +77 -0
  54. pyalamake-0.0.1/tools/xplat_utils/utils_val.py +33 -0
  55. pyalamake-0.0.1/ver/__init__.py +0 -0
  56. pyalamake-0.0.1/ver/helpers/__init__.py +0 -0
  57. pyalamake-0.0.1/ver/helpers/cmd_runner.py +139 -0
  58. pyalamake-0.0.1/ver/helpers/gen_report.py +6 -0
  59. pyalamake-0.0.1/ver/helpers/helper.py +77 -0
  60. pyalamake-0.0.1/ver/helpers/logger_mock.py +28 -0
  61. pyalamake-0.0.1/ver/helpers/svc.py +10 -0
  62. pyalamake-0.0.1/ver/test_tp001_cpp_target.py +104 -0
  63. pyalamake-0.0.1/ver/test_tp002_target_base.py +99 -0
  64. pyalamake-0.0.1/ver/test_tp003_logger.py +127 -0
  65. pyalamake-0.0.1/ver/test_tp004_gtest_target.py +95 -0
  66. pyalamake-0.0.1/ver/test_tp005_arduino_shared.py +164 -0
  67. pyalamake-0.0.1/ver/test_tp006_arduino_core_target.py +69 -0
  68. pyalamake-0.0.1/ver/test_tp007_arduino_target.py +89 -0
  69. pyalamake-0.0.1/ver/test_tp008_pyalamake.py +110 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) since 2024: pyalamake Module
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ graft pyalamake
2
+ global-exclude *.py[cod]
@@ -0,0 +1,203 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyalamake
3
+ Version: 0.0.1
4
+ Summary: Base Class for $module-name$
5
+ Home-page: https://bitbucket.org/arrizza-public/pyalamake/src/master
6
+ Download-URL: https://bitbucket.org/arrizza-public/pyalamake/get/master.zip
7
+ Author: JA
8
+ Author-email: cppgent0@gmail.com
9
+ License: MIT
10
+ Keywords: gui,test,verification
11
+ Classifier: Development Status :: 2 - Pre-Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Topic :: Utilities
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE.txt
19
+ Requires-Dist: medver-pytest
20
+ Requires-Dist: pytest
21
+
22
+ website: <https://arrizza.com/python-alamake>
23
+
24
+ ## Summary
25
+
26
+ This Python module generates a multi-target Makefile for cross-platform projects all of which is compatible with JetBrain's Clion IDE.
27
+
28
+ For example, see gen.py for a Python script (gen.py) that generates:
29
+
30
+ * two Arduino projects and an Arduino core for them
31
+ * a GTest project to run UTs against an Arduino Project
32
+ * a C/++ project
33
+
34
+ all into one Makefile, and all recognized by CLion.
35
+
36
+ See also gen_3cores.py that shows how to build 3 Arduino on 3 different boards in the same project and same Makefile.
37
+
38
+ ## Why not CMake?
39
+
40
+ I use JetBrain's CLion. Ut can handle only a CMake or Makefile based project.
41
+
42
+ Also, I like to use GTest to UT my Arduino projects (if possible). But CMake can't handle a project that uses
43
+ two compilers i.e. avr-gcc for Arduino and gcc for GTest. It tried some different CMake techniques
44
+ to allow that but they either didn't work or CLion still didn't recognize the components being used.
45
+
46
+ The only option then was to use Python to generate a Makefile that CLion was compatible with.
47
+
48
+ ## Why not ninja instead of make?
49
+
50
+ Because CLion can't use that to self-configure. CMake in CLion can be configured to use
51
+ Ninja, but the IDE uses CMake to configure itself for the project. Therefore, Makefile.
52
+
53
+ ## Why?
54
+
55
+ Currently, I have relatively simple projects using one Arduino and some GTest UTs. But I do have some
56
+ projects that could use multiple Arduino's communicating with each other. And possibly some other
57
+ microcontrollers e.g. STM32, ESP32, etc. that communicate with Arduino's or themselves.
58
+
59
+ CLion can't handle that.
60
+
61
+ But (finger crossed) I should be able to extend pyalamake to build STM32 and ESP32 targets relatively easily, still allow
62
+ GTests for those microcontrollers, etc.
63
+
64
+ ## How to use
65
+
66
+ ```bash
67
+ ./gen.py # to generate/update the Makefile
68
+
69
+ make help # to show the list of makefile targets
70
+
71
+ make # build all targets: Arduino core, both blink targets, GTest UT, and sample C++ app
72
+
73
+ make blink-upload # upload the blink app to an Arduino;
74
+ # should blink random times (2 - 15) and random rate (0 - 255ms);
75
+ make blink2-upload # upload the blink2 app to an Arduino;
76
+ # should blink 2 times
77
+ make core # build the Arduino Core
78
+
79
+ make ut-run # run the GTEST unit tests
80
+ make ut-cov # show the source code coverage of the GTEST UTs
81
+ # open debug/ut.html in a browser for a gcov HTML report
82
+
83
+ make hello-run # run C++ hello world app
84
+ make hello-run s="john" # to pass a CLI args to hello world
85
+
86
+ make clean # clean all
87
+ make <tgt>-clean # clean a specific target
88
+ ```
89
+
90
+ ## updating gen.py
91
+
92
+ ```python
93
+ from pyalamake.lib.pyalamake import alamake
94
+
95
+ # specify all components to be added to the makefile
96
+ # ... skip see below ...
97
+
98
+ # === generate makefile for all targets
99
+ alamake.makefile()
100
+
101
+ ```
102
+
103
+ At this point, the Makefile should contain all targets specified
104
+
105
+ #### Arduino targets
106
+
107
+ Creating an Arduino .hex requires 3 steps:
108
+
109
+ 1) gen an Arduino Shared component
110
+ * holds common, shared information like boardid, serial port, etc.
111
+ 2) gen an Arduino Core
112
+ * use the same shared component created above
113
+ * holds the Arduino Core library compiled for the same boardid, etc.
114
+ 3) gen the Arduino App
115
+ * use the same shared component created above
116
+ * holds the Arduino app compiled for the same boardid etc.
117
+
118
+ A shared component and core can be used with multiple Arduino targets.
119
+
120
+ Example generation of an Arduino shared component:
121
+
122
+ ```python
123
+ sh1 = alamake.create_arduino_shared()
124
+ sh1.set_boardid('nano-atmega328old')
125
+ # sh1.set_boardid('uno')
126
+ # sh1.set_boardid('megaadk')
127
+
128
+ # on Ubuntu, different boards use different serial ports
129
+ if sh1.boardid in ['uno', 'megaadk']:
130
+ sh1.set_avrdude_port('/dev/ttyACM0')
131
+ else:
132
+ sh1.set_avrdude_port('/dev/ttyUSB0')
133
+
134
+ # at this point sh1 is only missing core related settings
135
+ ```
136
+
137
+ Example generation of an Arduino core:
138
+
139
+ ```python
140
+ # share the same component created above
141
+ core = alamake.create('core', 'arduino-core', shared=sh1)
142
+ # no additional directories, libs, etc. needed
143
+ core.check()
144
+ ```
145
+
146
+ Example generation of an Arduino target:
147
+
148
+ ```python
149
+ # share the same component created above
150
+ blink = alamake.create('blink', 'arduino', shared=sh1)
151
+ blink.add_sources([
152
+ 'src/blink.cpp',
153
+ 'src/common.cpp',
154
+ ])
155
+ blink.add_include_directories(['src'])
156
+ ```
157
+
158
+ #### GTest target
159
+
160
+ Example generation of a GTest target that tests an Arduino app
161
+
162
+ ```python
163
+ ut = alamake.create('ut', 'gtest')
164
+
165
+ # tests the blink2.cpp (Arduino) in src2 directory
166
+ ut.add_include_directories([
167
+ 'src2',
168
+ 'ut/mock_arduino',
169
+ ])
170
+
171
+ # uses a Mock Arduino libary to check blink2 behavior
172
+ ut.add_sources([
173
+ 'ut/mock_arduino/mock_arduino.cpp',
174
+ 'ut/ut_test1.cpp',
175
+ ])
176
+
177
+ # specify the directory(s) that should be part of the coverage report
178
+ ut.add_coverage(['src2'])
179
+
180
+ ```
181
+
182
+ #### C++ targets
183
+
184
+ Example generation of a C++ target
185
+
186
+ ```python
187
+ hello = alamake.create('hello', 'cpp')
188
+ hello.add_include_directories(['src'])
189
+ hello.add_sources([
190
+ 'src/hello.cpp',
191
+ ])
192
+ ```
193
+
194
+ ## Limitations
195
+
196
+ * works only on Ubuntu. There will likely be additional work needed for macOS and Windows.
197
+ * Arduino libraries can not be added to a target.
198
+ * See todo.md for more work to be done.
199
+ * tested with an Arduino Nano (boardid: nano-atmega328old), Arduino MegaADK (boardid: megaadk) and Arduino Uno (boardid: uno).
200
+ Other boards should work correctly, but there is always a possibility it fails.
201
+ * I have not tested using an Arduino programmer
202
+ * I have not tested an app that requires Arduino EEPROM uploads.
203
+
@@ -0,0 +1,182 @@
1
+ website: <https://arrizza.com/python-alamake>
2
+
3
+ ## Summary
4
+
5
+ This Python module generates a multi-target Makefile for cross-platform projects all of which is compatible with JetBrain's Clion IDE.
6
+
7
+ For example, see gen.py for a Python script (gen.py) that generates:
8
+
9
+ * two Arduino projects and an Arduino core for them
10
+ * a GTest project to run UTs against an Arduino Project
11
+ * a C/++ project
12
+
13
+ all into one Makefile, and all recognized by CLion.
14
+
15
+ See also gen_3cores.py that shows how to build 3 Arduino on 3 different boards in the same project and same Makefile.
16
+
17
+ ## Why not CMake?
18
+
19
+ I use JetBrain's CLion. Ut can handle only a CMake or Makefile based project.
20
+
21
+ Also, I like to use GTest to UT my Arduino projects (if possible). But CMake can't handle a project that uses
22
+ two compilers i.e. avr-gcc for Arduino and gcc for GTest. It tried some different CMake techniques
23
+ to allow that but they either didn't work or CLion still didn't recognize the components being used.
24
+
25
+ The only option then was to use Python to generate a Makefile that CLion was compatible with.
26
+
27
+ ## Why not ninja instead of make?
28
+
29
+ Because CLion can't use that to self-configure. CMake in CLion can be configured to use
30
+ Ninja, but the IDE uses CMake to configure itself for the project. Therefore, Makefile.
31
+
32
+ ## Why?
33
+
34
+ Currently, I have relatively simple projects using one Arduino and some GTest UTs. But I do have some
35
+ projects that could use multiple Arduino's communicating with each other. And possibly some other
36
+ microcontrollers e.g. STM32, ESP32, etc. that communicate with Arduino's or themselves.
37
+
38
+ CLion can't handle that.
39
+
40
+ But (finger crossed) I should be able to extend pyalamake to build STM32 and ESP32 targets relatively easily, still allow
41
+ GTests for those microcontrollers, etc.
42
+
43
+ ## How to use
44
+
45
+ ```bash
46
+ ./gen.py # to generate/update the Makefile
47
+
48
+ make help # to show the list of makefile targets
49
+
50
+ make # build all targets: Arduino core, both blink targets, GTest UT, and sample C++ app
51
+
52
+ make blink-upload # upload the blink app to an Arduino;
53
+ # should blink random times (2 - 15) and random rate (0 - 255ms);
54
+ make blink2-upload # upload the blink2 app to an Arduino;
55
+ # should blink 2 times
56
+ make core # build the Arduino Core
57
+
58
+ make ut-run # run the GTEST unit tests
59
+ make ut-cov # show the source code coverage of the GTEST UTs
60
+ # open debug/ut.html in a browser for a gcov HTML report
61
+
62
+ make hello-run # run C++ hello world app
63
+ make hello-run s="john" # to pass a CLI args to hello world
64
+
65
+ make clean # clean all
66
+ make <tgt>-clean # clean a specific target
67
+ ```
68
+
69
+ ## updating gen.py
70
+
71
+ ```python
72
+ from pyalamake.lib.pyalamake import alamake
73
+
74
+ # specify all components to be added to the makefile
75
+ # ... skip see below ...
76
+
77
+ # === generate makefile for all targets
78
+ alamake.makefile()
79
+
80
+ ```
81
+
82
+ At this point, the Makefile should contain all targets specified
83
+
84
+ #### Arduino targets
85
+
86
+ Creating an Arduino .hex requires 3 steps:
87
+
88
+ 1) gen an Arduino Shared component
89
+ * holds common, shared information like boardid, serial port, etc.
90
+ 2) gen an Arduino Core
91
+ * use the same shared component created above
92
+ * holds the Arduino Core library compiled for the same boardid, etc.
93
+ 3) gen the Arduino App
94
+ * use the same shared component created above
95
+ * holds the Arduino app compiled for the same boardid etc.
96
+
97
+ A shared component and core can be used with multiple Arduino targets.
98
+
99
+ Example generation of an Arduino shared component:
100
+
101
+ ```python
102
+ sh1 = alamake.create_arduino_shared()
103
+ sh1.set_boardid('nano-atmega328old')
104
+ # sh1.set_boardid('uno')
105
+ # sh1.set_boardid('megaadk')
106
+
107
+ # on Ubuntu, different boards use different serial ports
108
+ if sh1.boardid in ['uno', 'megaadk']:
109
+ sh1.set_avrdude_port('/dev/ttyACM0')
110
+ else:
111
+ sh1.set_avrdude_port('/dev/ttyUSB0')
112
+
113
+ # at this point sh1 is only missing core related settings
114
+ ```
115
+
116
+ Example generation of an Arduino core:
117
+
118
+ ```python
119
+ # share the same component created above
120
+ core = alamake.create('core', 'arduino-core', shared=sh1)
121
+ # no additional directories, libs, etc. needed
122
+ core.check()
123
+ ```
124
+
125
+ Example generation of an Arduino target:
126
+
127
+ ```python
128
+ # share the same component created above
129
+ blink = alamake.create('blink', 'arduino', shared=sh1)
130
+ blink.add_sources([
131
+ 'src/blink.cpp',
132
+ 'src/common.cpp',
133
+ ])
134
+ blink.add_include_directories(['src'])
135
+ ```
136
+
137
+ #### GTest target
138
+
139
+ Example generation of a GTest target that tests an Arduino app
140
+
141
+ ```python
142
+ ut = alamake.create('ut', 'gtest')
143
+
144
+ # tests the blink2.cpp (Arduino) in src2 directory
145
+ ut.add_include_directories([
146
+ 'src2',
147
+ 'ut/mock_arduino',
148
+ ])
149
+
150
+ # uses a Mock Arduino libary to check blink2 behavior
151
+ ut.add_sources([
152
+ 'ut/mock_arduino/mock_arduino.cpp',
153
+ 'ut/ut_test1.cpp',
154
+ ])
155
+
156
+ # specify the directory(s) that should be part of the coverage report
157
+ ut.add_coverage(['src2'])
158
+
159
+ ```
160
+
161
+ #### C++ targets
162
+
163
+ Example generation of a C++ target
164
+
165
+ ```python
166
+ hello = alamake.create('hello', 'cpp')
167
+ hello.add_include_directories(['src'])
168
+ hello.add_sources([
169
+ 'src/hello.cpp',
170
+ ])
171
+ ```
172
+
173
+ ## Limitations
174
+
175
+ * works only on Ubuntu. There will likely be additional work needed for macOS and Windows.
176
+ * Arduino libraries can not be added to a target.
177
+ * See todo.md for more work to be done.
178
+ * tested with an Arduino Nano (boardid: nano-atmega328old), Arduino MegaADK (boardid: megaadk) and Arduino Uno (boardid: uno).
179
+ Other boards should work correctly, but there is always a possibility it fails.
180
+ * I have not tested using an Arduino programmer
181
+ * I have not tested an app that requires Arduino EEPROM uploads.
182
+
File without changes
@@ -0,0 +1,2 @@
1
+ /build_info.py
2
+ /version.json
File without changes
@@ -0,0 +1,114 @@
1
+ import json
2
+ import os
3
+
4
+ from .svc import svc
5
+
6
+
7
+ # --------------------
8
+ class ArduinoShared:
9
+ # set by user
10
+ boardid = None
11
+ avrdude_port = None
12
+
13
+ # these are from /usr/share/arduino/hardware/arduino/avr/boards.txt
14
+ f_cpu = None
15
+ mcu = None
16
+ avrdude = None
17
+ avrdude_baudrate = None
18
+ avrdude_protocol = None
19
+ # these are derived from the above
20
+ common_flags = None
21
+ cpp_flags = None
22
+ cc_flags = None
23
+
24
+ arduino_dir = '/usr/share/arduino'
25
+ cpp = 'avr-g++'
26
+ cc = 'avr-gcc'
27
+ ar = 'avr-ar'
28
+ obj_copy = 'avr-objcopy'
29
+ avrdude_dir = '/usr/share/arduino/hardware/tools'
30
+
31
+ # core related
32
+ core_tgt = None # name of core target
33
+ corelib = None # path to core lib
34
+ corelib_name = None # name of the lib
35
+ coredir = None # the build dir
36
+ core_includes = [
37
+ f'{arduino_dir}/hardware/arduino/avr/cores/arduino',
38
+ f'{arduino_dir}/hardware/arduino/avr/variants/standard',
39
+ ]
40
+
41
+ # --------------------
42
+ def set_avrdude_port(self, val):
43
+ self.avrdude_port = val
44
+
45
+ # --------------------
46
+ def print_board_list(self):
47
+ boards = self._get_board_json()
48
+ svc.log.line('Available boards:')
49
+ for name, info in boards.items():
50
+ svc.log.line(f' {name: <20}: {info["fullname"]}')
51
+
52
+ # --------------------
53
+ def check(self):
54
+ errs = 0
55
+ errs = self._check_arg(errs, 'boardid')
56
+ errs = self._check_arg(errs, 'avrdude_port')
57
+ errs = self._check_arg(errs, 'f_cpu')
58
+ errs = self._check_arg(errs, 'mcu')
59
+ errs = self._check_arg(errs, 'avrdude')
60
+ errs = self._check_arg(errs, 'avrdude_baudrate')
61
+ errs = self._check_arg(errs, 'avrdude_protocol')
62
+ errs = self._check_arg(errs, 'common_flags')
63
+ errs = self._check_arg(errs, 'cpp_flags')
64
+ errs = self._check_arg(errs, 'cc_flags')
65
+
66
+ errs = self._check_arg(errs, 'core_tgt')
67
+ errs = self._check_arg(errs, 'coredir')
68
+ errs = self._check_arg(errs, 'corelib')
69
+ errs = self._check_arg(errs, 'corelib_name')
70
+
71
+ if errs > 0:
72
+ svc.abort('arduino: resolve errors')
73
+
74
+ # --------------------
75
+ def _check_arg(self, errs, arg):
76
+ selfarg = getattr(self, arg, None)
77
+ if selfarg is None:
78
+ errs += 1
79
+ svc.log.err(f'arduino: {arg} is not set')
80
+ return errs
81
+
82
+ # --------------------
83
+ def set_boardid(self, boardid):
84
+ info = self._get_board_info(boardid)
85
+ self.boardid = boardid
86
+
87
+ # set values based on board id
88
+ self.f_cpu = info['build.f_cpu']
89
+ self.mcu = info['build.mcu']
90
+ self.avrdude = info['upload.tool']
91
+ self.avrdude_baudrate = info['upload.speed']
92
+ self.avrdude_protocol = info['upload.protocol']
93
+
94
+ self.common_flags = f'-c -g -Os -Wall -ffunction-sections -fdata-sections ' \
95
+ f'-mmcu={self.mcu} -DF_CPU={self.f_cpu}L ' \
96
+ '-MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106'
97
+ self.cpp_flags = f'{self.common_flags} -fno-exceptions -std=c++11'
98
+ self.cc_flags = self.common_flags
99
+
100
+ # --------------------
101
+ def _get_board_info(self, boardid):
102
+ boards = self._get_board_json()
103
+ if boardid not in boards:
104
+ svc.abort(f'ardunio: invalid boardid: {boardid}')
105
+
106
+ info = boards[boardid]
107
+ return info
108
+
109
+ # --------------------
110
+ def _get_board_json(self):
111
+ path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'boards.json')
112
+ with open(path, 'r', encoding='utf-8') as fp:
113
+ boards = json.load(fp)
114
+ return boards