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
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
-
## Export subsystem structure
7
+
# What is an exporter
8
+
9
+
An exporter is a python plugin to the mbed OS tools that convert a project using mbed CLI into one specialized for a particular IDE. For the best user experience, an exporter should:
10
+
- Take input from the resource scan.
11
+
- Use the flags in the build profiles.
12
+
- Have 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.
13
+
- Not call mbed CLI. It is possible to export from the website, which will not include mbed CLI in the resulting zip.
14
+
15
+
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
20
The **common code** is contained in four 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.
19
27
20
-
###Common code
28
+
## Common code
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,15 +41,15 @@ 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
40
48
*`gen_file` use Jinja2 to generate a file from a template.
41
49
*`get_source_paths` returns a list of directories that contain assembly, C, C++ files and so on.
42
50
*`group_project_files` group all files passed in by their containing directory. The groups are suitable for an IDE.
43
51
44
-
###Plugin code
52
+
## Plugin code
45
53
46
54
Plugin code is contained within a subdirectory of the `tools/export` directory named after the IDE or toolchain that the plugin is exporting for.
47
55
For example, the uVision exporter's templates and Python code is contained within the directory `tools/export/uvision` and the Makefile exporter's code and templates within `tools/export/makefile`.
@@ -52,39 +60,39 @@ 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.
76
84
77
85
This method runs after `generate` on an object that inherits from `Exporter`. It is responsible for invoking the build tools that the IDE or toolchain needs when a user instructs it to compile. It must return `0` on success or `-1` on failure.
78
86
79
-
##Implementing an example plugin
87
+
# Implementing an example plugin
80
88
81
89
In this section, we walk through implementing a simple exporter, `my_makefile`, which is a simplified Makefile using one template.
82
90
83
91
We will create two files and discuss their contents: `__init__.py` with the Python plugin code, and `Makefile.tmpl` with the template.
84
92
85
93
As this plugin is named `my_makefile`, all of the support code will be placed into `tools/export/my_makefile`.
86
94
87
-
###Python code for `__init__.py`
95
+
## Python code for `__init__.py`
88
96
89
97
First, we will make our class a subclass of Exporter:
90
98
```python
@@ -118,7 +126,7 @@ TARGETS = [target for target, obj in TARGET_MAP.iteritems()
118
126
if"GCC_ARM"in obj.supported_toolchains]
119
127
```
120
128
121
-
####Implementing the `generate` method
129
+
### Implementing the `generate` method
122
130
123
131
To generate our Makefile, we need a list of object files the executable will use. We can construct the list from the sources if we replace the extensions with `.o`.
124
132
@@ -158,7 +166,7 @@ To render our template, we pass the template file name, the context and the dest
Now that we have a context object, and we have passed off control to the Jinja2 template rendering engine, we can look at the template Makefile, `tools/export/my_makefile/Makefile.tmpl`.
0 commit comments