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
add README.md generation in the sketch-dist folder (#17)
* add README.md generation in the `sketch-dist` folder
The generated README.md contains commands that helps on how to replicate the build environment
* apply suggestions from code review and move file creation in functions for better readability
* fix typo
Copy file name to clipboardExpand all lines: README.md
+21-6
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
# arduino-cslt
2
2
3
3
`arduino-cslt` is a convenient wrapper of [arduino-cli](https://github.com/arduino/arduino-cli), it compiles Arduino sketches outputting a precompiled library under `sketch-dist/` folder created in the current working directory.
4
-
It generates a json file in the `extras/` folder that contains information regarding libraries and core to use in order to build the sketch. The result is achieved by parsing the verbose output of `arduino-cli` and by using [GNU ar](https://sourceware.org/binutils/docs/binutils/ar.html) to generate an archive of the object files.
4
+
It generates a README.md file that contains information regarding libraries and core to use in order to build the sketch. The result is achieved by parsing the verbose output of `arduino-cli` and by using [GNU ar](https://sourceware.org/binutils/docs/binutils/ar.html) to generate an archive of the object files.
5
5
6
-
## Prequisites
6
+
## Prerequisites
7
7
In order to run this tool you have to install first the [Arduino CLI](https://github.com/arduino/arduino-cli) and have `arduino-cli` binary in your `$PATH`, otherwise `arduino-cslt` won't work.
8
8
Please use a version of the Arduino CLI that has [this](https://github.com/arduino/arduino-cli/pull/1608) change (version > 0.20.2).
9
9
@@ -15,7 +15,7 @@ In order to build `arduino-cslt` just use `task go:build`
For example, running `./arduino-cslt compile -b arduino:samd:mkrwifi1010 sketch/sketch.ino` should produce a library with the following structure, in the current working directory:
21
21
```
@@ -28,6 +28,7 @@ sketch-dist/
28
28
│ ├── cortex-m0plus
29
29
│ │ └── libsketch.a
30
30
│ └── libsketch.h
31
+
├── README.md <--contains information regarding libraries and core to install in order to reproduce the original build environment
31
32
└── sketch
32
33
└── sketch.ino <-- the actual sketch we are going to compile with the arduino-cli later
And the content of `sketch-dist/libsketch/extras/result.json` is:
57
72
```json
58
73
{
@@ -80,12 +95,12 @@ And the content of `sketch-dist/libsketch/extras/result.json` is:
80
95
```
81
96
82
97
## How to compile the precompiled sketch
83
-
In order to compile the sketch you have first to install manually the libraries and the core listed in the `sketch-dist/<libsketch>/extras/result.json` file.
84
-
85
-
You can install a library with [`arduino-cli lib install LIBRARY[@VERSION_NUMBER]`](https://arduino.github.io/arduino-cli/latest/commands/arduino-cli_lib_install/).
98
+
In order to compile the sketch you can follow the instructions listed in the `sketch-dist/README.md` file.
86
99
87
100
You can install a core with [`arduino-cli core install PACKAGER:ARCH[@VERSION]`](https://arduino.github.io/arduino-cli/latest/commands/arduino-cli_core_install/).
88
101
102
+
You can install a library with [`arduino-cli lib install LIBRARY[@VERSION_NUMBER]`](https://arduino.github.io/arduino-cli/latest/commands/arduino-cli_lib_install/).
103
+
89
104
After completing that operation you can compile it with:
// createMainCpp function, as the name suggests. will create a main.cpp file inside inoPath
221
+
// createMainCpp function will create a main.cpp file inside inoPath
222
222
// we do this because setup() and loop() functions will be replaced inside the ino file, in order to allow the linking afterwards
223
223
// creating this file is mandatory, we include also Arduino.h because it's a step done by the builder during the building phase, but only for ino files
224
224
funccreateMainCpp(inoPath*paths.Path) {
@@ -238,7 +238,7 @@ _loop();
238
238
createFile(mainCppPath, mainCpp)
239
239
}
240
240
241
-
// removeMainCpp function, as the name suggests. will remove a main.cpp file inside inoPath
241
+
// removeMainCpp function will remove a main.cpp file inside inoPath
242
242
// we do this after the compile has been completed, this way we can rerun arduino-cslt again.
243
243
// If we do not remove this file and run the compile again it will fail because a main.cpp file with the same definitions is already present
// createLib function will take care of creating the library directory structure and files required, for the precompiled library to be recognized as such.
275
275
// sketchName is the name of the sketch without the .ino extension. We use this for the name of the lib.
276
276
// buildMcu is the name of the MCU of the board we have compiled for. The library specifications (https://arduino.github.io/arduino-cli/0.20/library-specification/#precompiled-binaries) requires that the precompiled archive is stored inside a folder with the name of the MCU used during the compile.
277
+
// fqbn is required in order to generate the README.md file with instructions.
277
278
// returnJson is the ResultJson object containing informations regarding core and libraries used during the compile process.
278
279
// objFilePaths is a paths.PathList containing the paths.Paths to all the sketch related object files produced during the compile phase.
// This one will include the libsketch.h and basically is the replacement of main.cpp
365
392
// the sketch.ino contains the following:
366
393
sketchFile:=`#include <`+"lib"+sketchName+`.h>
@@ -372,8 +399,41 @@ void loop() {
372
399
}`
373
400
sketchFilePath:=sketchDir.Join(sketchName+".ino")
374
401
createFile(sketchFilePath, sketchFile)
402
+
returnsketchFilePath
403
+
}
404
+
405
+
// createReadmeMdFile is a helper function that is reposnible for the generation of the README.md file containing informations on how to reproduce the build environment
406
+
// it takes the resultJson and some paths.Paths as input to do the required calculations.. The name of the arguments should be sufficient to understand
//create the README.md file containig instructions regarding what commands to run in order to have again a working binary
422
+
// the README.md contains the following:
423
+
readmeMd:=`This package contains firmware code loaded in your product.
424
+
The firmware contains additional code licensed with LGPL clause; in order to re-compile the entire firmware bundle, please execute the following.
425
+
426
+
## Install core and libraries
427
+
`+strings.Join(readmeContent, "\n") +"\n"+`
428
+
## Compile
429
+
`+readmeCompile+"\n"
430
+
431
+
readmeMdPath:=rootDir.Join("README.md")
432
+
createFile(readmeMdPath, readmeMd)
433
+
}
375
434
376
-
// run gcc-ar to create an archive containing all the object files except the main.cpp.o (we don't need it because we have created a substitute of it before ⬆️)
435
+
// createArchiveFile function will run `gcc-ar` to create an archive containing all the object files except the main.cpp.o (we don't need it because we have created a substitute of it before: sketchfile.ino)
0 commit comments