Skip to content

add README.md generation in the sketch-dist folder #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 31, 2022

Conversation

umbynos
Copy link
Contributor

@umbynos umbynos commented Jan 28, 2022

The generated README.md contains commands that help on how to replicate the build environment

The generated README.md contains commands that helps on how to replicate the build environment
@umbynos umbynos added the topic: code Related to content of the project itself label Jan 28, 2022
@umbynos umbynos requested a review from a team January 28, 2022 15:19
@umbynos umbynos self-assigned this Jan 28, 2022
cmd/compile.go Outdated
Comment on lines 380 to 382
for _, readmeLib := range returnJson.LibsInfo {
readmeContent = append(readmeContent, "`arduino-cli lib install "+readmeLib.Name+"@"+readmeLib.Version+"`")
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for _, readmeLib := range returnJson.LibsInfo {
readmeContent = append(readmeContent, "`arduino-cli lib install "+readmeLib.Name+"@"+readmeLib.Version+"`")
}
libs := []string{}
for _, l := range returnJson.LibsInfo {
libs = append(libs, l.Name+"@"+l.Version)
}
readmeContent = append(readmeContent, fmt.Sprintf("`arduino-cli lib install %s`", strings.Join(libs, " ")))

If this change is applied you'll also need to update the example in README.md.

cmd/compile.go Outdated
Comment on lines 377 to 399
// generate the commands to run to successfully reproduce the build environment, they will be used as content for the README.md
var readmeContent []string
readmeContent = append(readmeContent, "`arduino-cli core install "+returnJson.CoreInfo.Id+"@"+returnJson.CoreInfo.Version+"`")
for _, readmeLib := range returnJson.LibsInfo {
readmeContent = append(readmeContent, "`arduino-cli lib install "+readmeLib.Name+"@"+readmeLib.Version+"`")
}
// make the paths relative, absolute paths are too long and are different on the user machine
sketchFileRelPath, _ := sketchFilePath.RelFrom(workingDir)
libRelDir, _ := libDir.RelFrom(workingDir)
readmeCompile := "`arduino-cli compile -b " + fqbn + " " + sketchFileRelPath.String() + " --library " + libRelDir.String() + "`"

//create the README.md file containig instructions regarding what commands to run in order to have again a working binary
// the README.md contains the following:
readmeMd := `This package contains firmware code loaded in your product.
The firmware contains additional code licensed with LGPL clause; in order to re-compile the entire firmware bundle, please execute the following.

## Install core and libraries
` + strings.Join(readmeContent, "\n") + "\n" + `
## Compile
` + readmeCompile + "\n"

readmeMdPath := rootDir.Join("README.md")
createFile(readmeMdPath, readmeMd)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this logic into a separate function. The createLib function is quite big already, separating parts of in different function will make it easier to understand.

Copy link

@silvanocerza silvanocerza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments.

@umbynos umbynos force-pushed the umbynos/readme_generation branch from aa54c38 to 1ace2cf Compare January 31, 2022 12:01
@umbynos umbynos requested a review from silvanocerza January 31, 2022 12:01
Copy link

@silvanocerza silvanocerza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks great.

I'd change a bit the docstrings of the newly added functions, just to make them more readable. You repeat as the name suggest in most of them, I'd just remove it, the docs wrong nicely without it.

@umbynos umbynos force-pushed the umbynos/readme_generation branch from 1ace2cf to 7b9831a Compare January 31, 2022 14:36
@umbynos umbynos merged commit 15ceb91 into main Jan 31, 2022
@umbynos umbynos deleted the umbynos/readme_generation branch January 31, 2022 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cslt-tool should generate a readme file with arduino-cli commands to reproduce the build env
2 participants