Skip to content

Commit 0e4cc3f

Browse files
committed
apply suggestions from code review
1 parent 6515654 commit 0e4cc3f

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ It generates a json file in `extra/` folder that contains information regarding
77
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 `cslt-tool` won't work.
88
Please use a version of the arduino CLI that has [this](https://github.com/arduino/arduino-cli/pull/1608) change (version > 0.20.2).
99

10-
Another requirement is o have [`gcc-ar`](https://sourceware.org/binutils/docs/binutils/ar.html) (installable with `apt-get install gcc`) in your `$PATH`.
10+
Another requirement is [`gcc-ar`](https://sourceware.org/binutils/docs/binutils/ar.html) (installable with `apt-get install gcc`) in your `$PATH`.
1111

1212
## Build it
1313
In order to build `cslt-tool` just use `go build`
@@ -80,9 +80,9 @@ And the content of `libsketch/extra/result.json` is:
8080
## How to compile the precompiled sketch
8181
In order to compile the sketch you have first to install manually the libraries and the core listed in the `<libsketch>/extra/result.json` file.
8282

83-
You can install a library with `arduino-cli lib install LIBRARY[@VERSION_NUMBER]`.
83+
You can install a library with [`arduino-cli lib install LIBRARY[@VERSION_NUMBER]`](https://arduino.github.io/arduino-cli/0.20/commands/arduino-cli_lib_install/).
8484

85-
You can install a core with `arduino-cli core install PACKAGER:ARCH[@VERSION]`.
85+
You can install a core with [`arduino-cli core install PACKAGER:ARCH[@VERSION]`](https://arduino.github.io/arduino-cli/0.20/commands/arduino-cli_core_install/).
8686

8787
After completing that operation you can compile it with:
8888

cmd/compile.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ func compileSketch(cmd *cobra.Command, args []string) {
9393
inoPath := getInoSketchPath(args[0])
9494

9595
// create a main.cpp file in the same dir of the sketch.ino
96-
createMainCpp(*inoPath)
96+
createMainCpp(inoPath)
9797

9898
// replace setup() with _setup() and loop() with _loop() in the user's sketch.ino file
99-
oldSketchContent := patchSketch(*inoPath)
99+
oldSketchContent := patchSketch(inoPath)
100100

101101
// let's call arduino-cli compile and parse the verbose output
102102
cmdArgs := []string{"compile", "-b", fqbn, inoPath.String(), "-v", "--format", "json"}
@@ -121,10 +121,10 @@ func compileSketch(cmd *cobra.Command, args []string) {
121121
buildMcu := parseCliCompileOutputShowProp(cmdOutput)
122122

123123
// remove main.cpp file, we don't need it anymore
124-
removeMainCpp(*inoPath)
124+
removeMainCpp(inoPath)
125125

126126
// restore the sketch content, this allows us to rerun cslt-tool if we want without breaking the compile process
127-
createFile(*inoPath, string(oldSketchContent))
127+
createFile(inoPath, string(oldSketchContent))
128128
logrus.Infof("restored %s", inoPath.String())
129129

130130
sketchName := strings.TrimSuffix(inoPath.Base(), inoPath.Ext())
@@ -209,7 +209,7 @@ func getInoSketchPath(argSketchPath string) (inoPath *paths.Path) {
209209
// createMainCpp function, as the name suggests. will create a main.cpp file inside inoPath
210210
// we do this because setup() and loop() functions will be replaced inside the ino file, in order to allow the linking afterwards
211211
// 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
212-
func createMainCpp(inoPath paths.Path) {
212+
func createMainCpp(inoPath *paths.Path) {
213213
// the main.cpp contains the following:
214214
mainCpp := `#include "Arduino.h"
215215
void _setup();
@@ -223,13 +223,13 @@ void loop() {
223223
_loop();
224224
}`
225225
mainCppPath := inoPath.Parent().Join("main.cpp")
226-
createFile(*mainCppPath, mainCpp)
226+
createFile(mainCppPath, mainCpp)
227227
}
228228

229229
// removeMainCpp function, as the name suggests. will remove a main.cpp file inside inoPath
230230
// we do this after the compile has been completed, this way we can rerun cslt-tool again.
231231
// 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
232-
func removeMainCpp(inoPath paths.Path) {
232+
func removeMainCpp(inoPath *paths.Path) {
233233
mainCppPath := inoPath.Parent().Join("main.cpp")
234234
if err := os.Remove(mainCppPath.String()); err != nil {
235235
logrus.Warn(err)
@@ -241,7 +241,7 @@ func removeMainCpp(inoPath paths.Path) {
241241
// patchSketch function will modify the content of the inoPath sketch passed as argument,
242242
// the old unmodified sketch content is returned as oldSketchContent,
243243
// we do this to allow the compile process to succeed
244-
func patchSketch(inoPath paths.Path) (oldSketchContent []byte) {
244+
func patchSketch(inoPath *paths.Path) (oldSketchContent []byte) {
245245
oldSketchContent, err := os.ReadFile(inoPath.String())
246246
if err != nil {
247247
logrus.Fatal(err)
@@ -318,7 +318,7 @@ version=1.0
318318
precompiled=true`
319319

320320
libraryPropertyPath := libDir.Join("library.properties")
321-
createFile(*libraryPropertyPath, libraryProperties)
321+
createFile(libraryPropertyPath, libraryProperties)
322322

323323
// we calculate the #include part to append at the beginning of the header file here with all the libraries used by the original sketch
324324
var librariesIncludes []string
@@ -337,7 +337,7 @@ void _setup();
337337
void _loop();`
338338

339339
libsketchFilePath := srcDir.Parent().Join("lib" + sketchName + ".h")
340-
createFile(*libsketchFilePath, libsketchHeader)
340+
createFile(libsketchFilePath, libsketchHeader)
341341

342342
// create the sketch file in the example dir of the lib
343343
// This one will include the libsketch.h and basically is the replacement of main.cpp
@@ -350,7 +350,7 @@ void loop() {
350350
_loop();
351351
}`
352352
sketchFilePath := exampleDir.Join(sketchName + ".ino")
353-
createFile(*sketchFilePath, sketchFile)
353+
createFile(sketchFilePath, sketchFile)
354354

355355
// 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 ⬆️)
356356
// we exclude the main.cpp.o because we are going to link the archive libsketch.a against sketchName.ino
@@ -382,7 +382,7 @@ void loop() {
382382
// it takes filePath and fileContent as arguments,
383383
// filePath points to the location where to save the file
384384
// fileContent,as the name suggests, include the content of the file
385-
func createFile(filePath paths.Path, fileContent string) {
385+
func createFile(filePath *paths.Path, fileContent string) {
386386
err := os.WriteFile(filePath.String(), []byte(fileContent), 0644)
387387
if err != nil {
388388
logrus.Fatal(err)

0 commit comments

Comments
 (0)