You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/cont/adding_exporters.md
+95-11Lines changed: 95 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,26 @@
1
1
# Adding exporters
2
2
3
-
This is a guide for adding exporters to the mbed-os tools. It covers the structure of the export subsystem and the individual exporter.
3
+
This is a guide for adding exporters to the mbed OS tools. First, this document describes what an exporter is and what rules it follows. Then, it covers the structure of the export subsystem and the individual exporter. Finally, this document gives some implementation suggestions.
4
4
5
5
<spanclass="notes">**Note:** All paths are relative to [https://github.com/ARMmbed/mbed-os/](https://github.com/ARMmbed/mbed-os/).</span>
6
6
7
+
## What an exporter is
8
+
9
+
An exporter is a Python plugin to the mbed OS tools that converts a project using mbed CLI into one specialized for a particular IDE. For the best user experience, an exporter:
10
+
11
+
- Takes input from the resource scan.
12
+
- Uses the flags in the build profiles.
13
+
- Has a single template file for each file type they produce. For example, an eclipse CDT project would have one template for `.project` files and one for `.cproject` files.
14
+
- Does not call mbed CLI. It is possible to export from the website, which will not include mbed CLI in the resulting zip.
15
+
7
16
## Export subsystem structure
8
17
9
18
The export subsystem is organized as a group of common code and a group of IDE or toolchain specific plugins.
10
19
11
-
The **common code** is contained in four files:
20
+
The **common code** is contained in three files:
12
21
13
22
*`tools/project.py` contains the command-line interface and handles the differences between mbed OS 2 tests and mbed OS 5 projects.
14
-
*`tools/project_api.py` contains a high-level API for use by the mbed Online Compiler and mbed CLI. Responsible for doing boilerplate-like things, such as scanning for resources.
15
-
*`tools/export/__init__.py` contains the mapping of exporter names to plugin classes, and handles printing of toolchain support information.
23
+
*`tools/export/__init__.py` contains a high-level API for use by the mbed Online Compiler and mbed CLI. Responsible for doing boilerplate-like things, such as scanning for resources.
16
24
*`tools/export/exporters.py` contains the base class for all plugins. It offers useful exporter-specific actions.
17
25
18
26
An **IDE or toolchain specific plugin** is a Python class that inherits from the `Exporter` class and is listed in the `tools/export/__init__.py` exporter map.
@@ -21,7 +29,7 @@ An **IDE or toolchain specific plugin** is a Python class that inherits from the
21
29
22
30
The common code does two things: setting things up for the plugins, and providing a library of useful tools for plugins to use.
23
31
24
-
___Setup___
32
+
#### Setup
25
33
26
34
The setup code scans for the resources used in the export process and collects the configuration required to build the project at hand.
27
35
@@ -33,7 +41,7 @@ These steps construct an object of one of the exporter plugin classes listed in
33
41
*`flags` the flags that the mbedToolchain instance will use to compile the `c/cpp/asm` files if invoked.
34
42
*`resources` a `Resources` object that contains many lists of files that an exporter will find useful, such as C and Cpp sources and header search paths. The plugin should use only the attributes of the Resources object because the methods are only used during setup time. You can view all available Resources class attributes in `tools/toolchains/__init__.py`.
35
43
36
-
___Plugin tools___
44
+
#### Plugin tools
37
45
38
46
The other half of the common code is a library for use by a plugin. This API includes:
39
47
@@ -52,25 +60,25 @@ The Python code for the plugin should be:
52
60
1. Imported into `tools/export/__init__.py`.
53
61
1. Added to the exporter map.
54
62
55
-
___The `generate`method___
63
+
#### The `generate`method
56
64
57
65
Each exporter is expected to implement one method, `generate`, which is responsible for creating all of the required project files for the IDE or toolchain that the plugin targets.
58
66
59
67
This method may use any of the attributes and APIs included by the common code.
60
68
61
-
___The `TARGETS` class variable___
69
+
#### The `TARGETS` class variable
62
70
63
71
Each exporter reports its specific target support through a class varibale, `TARGETS`. This class variable is simply a list of targets to which you can export. Requesting an export to a target that's not on the list will generate an error.
64
72
65
-
___The `TOOLCHAIN` class variable___
73
+
#### The `TOOLCHAIN` class variable
66
74
67
75
Each exporter reports its specific toolchain it will use to compile the source code through a class variable `TOOLCHAIN`.
68
76
69
-
___The `NAME` class variable___
77
+
#### The `NAME` class variable
70
78
71
79
Each exporter reports the name of the exporter through the class variable `NAME`. This matches the key in the `tools/export/__init__.py` exporter map.
72
80
73
-
___The `build`method___
81
+
#### The `build`method
74
82
75
83
A plugin that would like to be tested by CI may implement the `build` method.
from tools.export.exporters.gnuarmeclipse import GNUARMEcilpse
274
+
275
+
classKDS(GNUARMEcilpse):
276
+
NAME = 'Kinetis Design Studio'
277
+
TOOLCHAIN = 'GCC_ARM'
278
+
...
279
+
280
+
defgenerate(self):
281
+
"""Generate eclipes project files, and some KDS specific files"""
282
+
super(KDS, self).generate()
283
+
...
284
+
285
+
```
286
+
287
+
After inheriting from the `GNUARMEclipse` class, specialize the generate method
288
+
in any way you need.
289
+
290
+
### Eclipse + Make
291
+
292
+
If your IDE uses Eclipse and does not use the GNU ARM Eclipse plugin, you
293
+
can use the "Unmanaged makefile" Eclipse exporter classes, `EclipseGcc`,
294
+
`EclipseArmc5` and `EclipseIar`. Much like the GNU ARM Eclipse section, you may
295
+
decide to alias or specialize.
296
+
297
+
### Make
298
+
299
+
If your IDE is not Eclipse based but can still use a Makefile, then you can specialize the Makefile exporter. Specializing the Makefile is actually how ARM mbed implemented the Eclipse + Make exporter.
300
+
301
+
Creating an exporter based on the Makefile exporter is a two step process: inherit from the appropriate Makefile class, and call its generate method. Taking Eclipse + Make using GCC_ARM as an example, your exporter will look like:
0 commit comments