Skip to content

Commit c3a83e2

Browse files
author
Amanda Butler
authored
Merge pull request #162 from theotherjimmy/update-exporter-docs
Improve detail of exporter addition docs
2 parents 748db79 + dae96b2 commit c3a83e2

File tree

1 file changed

+95
-11
lines changed

1 file changed

+95
-11
lines changed

docs/cont/adding_exporters.md

Lines changed: 95 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
# Adding exporters
22

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.
44

55
<span class="notes">**Note:** All paths are relative to [https://github.com/ARMmbed/mbed-os/](https://github.com/ARMmbed/mbed-os/).</span>
66

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+
716
## Export subsystem structure
817

918
The export subsystem is organized as a group of common code and a group of IDE or toolchain specific plugins.
1019

11-
The **common code** is contained in four files:
20+
The **common code** is contained in three files:
1221

1322
* `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.
1624
* `tools/export/exporters.py` contains the base class for all plugins. It offers useful exporter-specific actions.
1725

1826
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
2129

2230
The common code does two things: setting things up for the plugins, and providing a library of useful tools for plugins to use.
2331

24-
___Setup___
32+
#### Setup
2533

2634
The setup code scans for the resources used in the export process and collects the configuration required to build the project at hand.
2735

@@ -33,7 +41,7 @@ These steps construct an object of one of the exporter plugin classes listed in
3341
* `flags` the flags that the mbedToolchain instance will use to compile the `c/cpp/asm` files if invoked.
3442
* `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`.
3543

36-
___Plugin tools___
44+
#### Plugin tools
3745

3846
The other half of the common code is a library for use by a plugin. This API includes:
3947

@@ -52,25 +60,25 @@ The Python code for the plugin should be:
5260
1. Imported into `tools/export/__init__.py`.
5361
1. Added to the exporter map.
5462

55-
___The `generate` method___
63+
#### The `generate` method
5664

5765
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.
5866

5967
This method may use any of the attributes and APIs included by the common code.
6068

61-
___The `TARGETS` class variable___
69+
#### The `TARGETS` class variable
6270

6371
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.
6472

65-
___The `TOOLCHAIN` class variable___
73+
#### The `TOOLCHAIN` class variable
6674

6775
Each exporter reports its specific toolchain it will use to compile the source code through a class variable `TOOLCHAIN`.
6876

69-
___The `NAME` class variable___
77+
#### The `NAME` class variable
7078

7179
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.
7280

73-
___The `build` method___
81+
#### The `build` method
7482

7583
A plugin that would like to be tested by CI may implement the `build` method.
7684

@@ -230,3 +238,79 @@ $(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS) $(LINKER_SCRIPT)
230238
+@echo "link: $(notdir $@)"
231239
@$(LD) -T $(filter %{{link_script_ext}}, $^) $(LIBRARY_PATHS) --output $@ $(filter %.o, $^) $(LIBRARIES)
232240
```
241+
242+
## Suggested implementation
243+
244+
There are several paths forward that can lead to an easily maintained exporter:
245+
- Specialize or alias the GNU ARM Eclipse exporter.
246+
- Specialize or alias the Eclipse + Make exporter.
247+
- Specialize the Make exporter.
248+
249+
### GNU ARM Eclipse
250+
251+
If your IDE uses Eclipse and uses the GNU ARM Eclipse plugin, then specialize or alias your exporter with the generic GNU ARM Eclipse.
252+
253+
#### Alias
254+
255+
If you do not need any specialization of the export, then replace your exporters class in the `EXPORT_MAP` with the `GNUARMEclipse` class. For example, if KDS met all of these requirements, we could:
256+
257+
```diff
258+
EXPORTERS = {
259+
'iar': iar.IAR,
260+
'embitz' : embitz.EmBitz,
261+
'coide' : coide.CoIDE,
262+
+ 'kds' : gnuarmeclipse.GNUARMEclipse,
263+
'simplicityv3' : simplicity.SimplicityV3,
264+
'atmelstudio' : atmelstudio.AtmelStudio,
265+
'sw4stm32' : sw4stm32.Sw4STM32,
266+
```
267+
268+
#### Specialization
269+
270+
If you need more specialization and are using an Eclipse based IDE and the GNU ARM Eclipse plugin, then your exporter class inherits from the `GNUARMEclipse` class. For example (with KDS again):
271+
272+
```python
273+
from tools.export.exporters.gnuarmeclipse import GNUARMEcilpse
274+
275+
class KDS(GNUARMEcilpse):
276+
NAME = 'Kinetis Design Studio'
277+
TOOLCHAIN = 'GCC_ARM'
278+
...
279+
280+
def generate(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:
302+
303+
```python
304+
class EclipseGcc(GccArm):
305+
NAME = "Eclipse-GCC-ARM"
306+
```
307+
308+
Your generate method will look similar to:
309+
```python
310+
def generate(self):
311+
"""Generate Makefile, .cproject & .project Eclipse project file,
312+
py_ocd_settings launch file, and software link .p2f file
313+
"""
314+
super(EclipseGcc, self).generate()
315+
...
316+
```

0 commit comments

Comments
 (0)