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/creating_apps/adding_exporters.md
+32-32Lines changed: 32 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
-
# Adding exporters
1
+
##Adding exporters
2
2
3
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
7
+
###What an exporter is
8
8
9
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
10
@@ -13,7 +13,7 @@ An exporter is a Python plugin to the mbed OS tools that converts a project usin
13
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
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
15
16
-
## Export subsystem structure
16
+
###Export subsystem structure
17
17
18
18
The export subsystem is organized as a group of common code and a group of IDE or toolchain specific plugins.
19
19
@@ -25,11 +25,11 @@ The **common code** is contained in three files:
25
25
26
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.
27
27
28
-
### Common code
28
+
####Common code
29
29
30
30
The common code does two things: setting things up for the plugins, and providing a library of useful tools for plugins to use.
31
31
32
-
#### Setup
32
+
#####Setup
33
33
34
34
The setup code scans for the resources used in the export process and collects the configuration required to build the project at hand.
35
35
@@ -41,15 +41,15 @@ These steps construct an object of one of the exporter plugin classes listed in
41
41
*`flags` the flags that the mbedToolchain instance will use to compile the `c/cpp/asm` files if invoked.
42
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`.
43
43
44
-
#### Plugin tools
44
+
#####Plugin tools
45
45
46
46
The other half of the common code is a library for use by a plugin. This API includes:
47
47
48
48
*`gen_file` use Jinja2 to generate a file from a template.
49
49
*`get_source_paths` returns a list of directories that contain assembly, C, C++ files and so on.
50
-
*`group_project_files` group all files passed in by their containing directory. The groups are suitable for an IDE.
50
+
*`group_project_files` group all files passed in by their containing directory. The groups are suitable for an IDE.
51
51
52
-
### Plugin code
52
+
####Plugin code
53
53
54
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.
55
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`.
@@ -60,39 +60,39 @@ The Python code for the plugin should be:
60
60
1. Imported into `tools/export/__init__.py`.
61
61
1. Added to the exporter map.
62
62
63
-
#### The `generate` method
63
+
#####The `generate` method
64
64
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.
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.
66
66
67
67
This method may use any of the attributes and APIs included by the common code.
68
68
69
-
#### The `TARGETS` class variable
69
+
#####The `TARGETS` class variable
70
70
71
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.
72
72
73
-
#### The `TOOLCHAIN` class variable
73
+
#####The `TOOLCHAIN` class variable
74
74
75
75
Each exporter reports its specific toolchain it will use to compile the source code through a class variable `TOOLCHAIN`.
76
76
77
-
#### The `NAME` class variable
77
+
#####The `NAME` class variable
78
78
79
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.
80
80
81
-
#### The `build` method
81
+
#####The `build` method
82
82
83
-
A plugin that would like to be tested by CI may implement the `build` method.
83
+
A plugin that would like to be tested by CI may implement the `build` method.
84
84
85
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.
86
86
87
-
## Implementing an example plugin
87
+
###Implementing an example plugin
88
88
89
89
In this section, we walk through implementing a simple exporter, `my_makefile`, which is a simplified Makefile using one template.
90
90
91
91
We will create two files and discuss their contents: `__init__.py` with the Python plugin code, and `Makefile.tmpl` with the template.
92
92
93
93
As this plugin is named `my_makefile`, all of the support code will be placed into `tools/export/my_makefile`.
94
94
95
-
### Python code for `__init__.py`
95
+
####Python code for `__init__.py`
96
96
97
97
First, we will make our class a subclass of Exporter:
98
98
```python
@@ -126,7 +126,7 @@ TARGETS = [target for target, obj in TARGET_MAP.iteritems()
126
126
if"GCC_ARM"in obj.supported_toolchains]
127
127
```
128
128
129
-
#### Implementing the `generate` method
129
+
#####Implementing the `generate` method
130
130
131
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`.
132
132
@@ -166,9 +166,9 @@ 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`.
171
+
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`.
172
172
173
173
Find documentation on what is available within a Jinja2 template [here](http://jinja.pocoo.org/docs/dev/templates/).
from tools.export.gnuarmeclipse import GNUARMEcilpse
274
-
274
+
275
275
classKDS(GNUARMEcilpse):
276
276
NAME = 'Kinetis Design Studio'
277
277
TOOLCHAIN = 'GCC_ARM'
@@ -281,22 +281,22 @@ class KDS(GNUARMEcilpse):
281
281
"""Generate eclipes project files, and some KDS specific files"""
282
282
super(KDS, self).generate()
283
283
...
284
-
284
+
285
285
```
286
286
287
287
After inheriting from the `GNUARMEclipse` class, specialize the generate method
288
288
in any way you need.
289
289
290
-
### Eclipse + Make
290
+
####Eclipse + Make
291
291
292
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
293
+
can use the "Unmanaged makefile" Eclipse exporter classes, `EclipseGcc`,
294
+
`EclipseArmc5` and `EclipseIar`. Much like the GNU ARM Eclipse section, you may
295
295
decide to alias or specialize.
296
296
297
-
### Make
297
+
####Make
298
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.
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
300
301
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:
### Unable to import Mercurial (mbed.org) programs or libraries.
5
-
1. Check whether you have Mercurial installed in your system path by running `hg` in command prompt. If you're receiving "command not found" or a similar message, then you need to install Mercurial, and add it to your system path.
2
+
### Troubleshooting with mbed CLI
6
3
7
-
2. Try to clone a Mercurial repository directly. For example, `hg clone https://developer.mbed.org/teams/mbed/code/mbed_blinky/`. If you receive an error similar to `abort: error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.:590)`, then your system certificates are out of date. You need to update your system certificates and possibly add the host certificate fingerprint of `mbed.com` and `mbed.org`. Read more about Mercurial's certificate management [here](https://www.mercurial-scm.org/wiki/CACertificates).
4
+
**Unable to import Mercurial (mbed.org) programs or libraries**
8
5
9
-
### Various issues when running mbed CLI in Cygwin environment
10
-
Currently mbed CLI is not compatible with Cygwin environment and cannot be executed inside it (https://github.com/ARMmbed/mbed-cli/issues/299).
6
+
: 1. Check whether you have Mercurial installed in your system path by running `hg` in command prompt. If you're receiving "command not found" or a similar message, then you need to install Mercurial, and add it to your system path.
7
+
8
+
: 2. Try to clone a Mercurial repository directly. For example, `hg clone https://developer.mbed.org/teams/mbed/code/mbed_blinky/`. If you receive an error similar to `abort: error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.:590)`, then your system certificates are out of date. You need to update your system certificates and possibly add the host certificate fingerprint of `mbed.com` and `mbed.org`. Read more about Mercurial's certificate management [here](https://www.mercurial-scm.org/wiki/CACertificates).
9
+
10
+
**Various issues when running mbed CLI in Cygwin environment**
11
+
12
+
: Currently mbed CLI is not compatible with Cygwin environment and cannot be executed inside it (https://github.com/ARMmbed/mbed-cli/issues/299).
@@ -97,7 +97,7 @@ mbed CLI can create and import programs based on both mbed OS 2 and mbed OS 5.
97
97
98
98
#### Creating a new program for mbed OS 5
99
99
100
-
When you create a new program, mbed CLI automatically imports the latest [mbed OS release](https://github.com/ARMmbed/mbed-os/). Each release includes all the components: code, build tools and IDE exporters.
100
+
When you create a new program, mbed CLI automatically imports the latest [mbed OS release](https://github.com/ARMmbed/mbed-os/). Each release includes all the components: code, build tools and IDE exporters.
101
101
102
102
With this in mind, let's create a new program (we'll call it `mbed-os-program`):
103
103
@@ -163,13 +163,13 @@ $ cd mbed-os-example-blinky
163
163
```
164
164
165
165
You can use the "import" command without specifying a full URL; mbed CLI adds a prefix (https://github.com/ARMmbed) to the URL if one is not present. For example, this command:
While working on your code, you may need to add another library to your application or remove existing libraries.
194
+
While working on your code, you may need to add another library to your application or remove existing libraries.
195
195
196
196
Adding a new library to your program is not the same as cloning the repository. Don't clone a library using `hg` or `git`; use `mbed add` to add the library. This ensures that all libraries and sublibraries are populated as well.
0 commit comments