Skip to content

Commit e7293b3

Browse files
authored
Merge branch 'master' into discoveries_fix
2 parents 6cee326 + e7ba99f commit e7293b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3075
-2363
lines changed

Diff for: .github/PULL_REQUEST_TEMPLATE.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ See [how to contribute](https://arduino.github.io/arduino-cli/latest/CONTRIBUTIN
99
- [ ] Tests for the changes have been added (for bug fixes / features)
1010
- [ ] Docs have been added / updated (for bug fixes / features)
1111
- [ ] `UPGRADING.md` has been updated with a migration guide (for breaking changes)
12+
- [ ] `configuration.schema.json` updated if new parameters are added.
1213

1314
## What kind of change does this PR introduce?
1415

Diff for: .github/workflows/publish-go-nightly-task.yml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
- Linux_ARM64
3737
- macOS_64bit
3838
- macOS_ARM64
39+
- jsonschema
3940

4041
steps:
4142
- name: Checkout repository

Diff for: .github/workflows/publish-go-tester-task.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ jobs:
111111
- task: protoc:collect
112112
path: "*_proto.zip"
113113
name: rpc-protocol-files
114+
- task: dist:jsonschema
115+
path: "*configuration.schema.json"
116+
name: configuration-schema
114117

115118
steps:
116119
- name: Checkout repository
@@ -146,7 +149,6 @@ jobs:
146149
steps:
147150
- name: Download build artifacts
148151
uses: actions/download-artifact@v3
149-
150152
- name: Output checksum
151153
run: |
152154
TAG="${{ needs.package-name-prefix.outputs.prefix }}git-snapshot"

Diff for: .github/workflows/release-go-task.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,11 @@ jobs:
253253
- name: Collect proto files
254254
run: task protoc:collect
255255

256+
- name: Add configuration JSON schema
257+
run: task dist:jsonschema
258+
256259
- name: Create checksum file
257-
working-directory: ${{ env.DIST_DIR}}
260+
working-directory: ${{ env.DIST_DIR }}
258261
run: |
259262
TAG=${{ needs.create-release-artifacts.outputs.version }}
260263
sha256sum ${{ env.PROJECT_NAME }}_${TAG}* > ${TAG}-checksums.txt

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ venv
2828
/docsgen/arduino-cli.exe
2929
/docs/rpc/*.md
3030
/docs/commands/*.md
31+
/docs/configuration.schema.json
3132

3233
# Delve debugger binary file
3334
__debug_bin

Diff for: DistTasks.yml

+6
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,9 @@ tasks:
251251
CONTAINER_TAG: "{{.GO_VERSION}}-darwin-arm64-debian10"
252252
PACKAGE_PLATFORM: "macOS_ARM64"
253253
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"
254+
255+
jsonschema:
256+
desc: Copy the JSON schema to dist folder
257+
cmds:
258+
- mkdir --parents {{.DIST_DIR}}
259+
- cp ./configuration/configuration.schema.json {{.DIST_DIR}}/{{.PROJECT_NAME}}_{{.VERSION}}_configuration.schema.json

Diff for: Taskfile.yml

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ tasks:
99
deps:
1010
- task: go:cli-docs
1111
- task: protoc:docs
12+
- task: docs:include-configuration-json-schema
1213
cmds:
1314
- task: general:format-prettier
1415

@@ -218,6 +219,11 @@ tasks:
218219
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,settings.md --proto_path=rpc ./rpc/cc/arduino/cli/settings/v1/*.proto'
219220
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,debug.md --proto_path=rpc ./rpc/cc/arduino/cli/debug/v1/*.proto'
220221

222+
docs:include-configuration-json-schema:
223+
desc: Copy configuration JSON schema to make it available in documentation
224+
cmds:
225+
- cp ./configuration/configuration.schema.json ./docs/configuration.schema.json
226+
221227
protoc:check:
222228
desc: Perform linting of the protobuf definitions
223229
cmds:

Diff for: arduino/cores/packagemanager/install_uninstall.go

+26-10
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (pme *Explorer) DownloadAndInstallPlatformAndTools(
102102

103103
// Install tools first
104104
for _, tool := range toolsToInstall {
105-
if err := pme.InstallTool(tool, taskCB); err != nil {
105+
if err := pme.InstallTool(tool, taskCB, skipPostInstall); err != nil {
106106
return err
107107
}
108108
}
@@ -171,7 +171,10 @@ func (pme *Explorer) DownloadAndInstallPlatformAndTools(
171171
if !skipPostInstall {
172172
log.Info("Running post_install script")
173173
taskCB(&rpc.TaskProgress{Message: tr("Configuring platform.")})
174-
if err := pme.RunPostInstallScript(platformRelease); err != nil {
174+
if !platformRelease.IsInstalled() {
175+
return errors.New(tr("platform not installed"))
176+
}
177+
if err := pme.RunPostInstallScript(platformRelease.InstallDir); err != nil {
175178
taskCB(&rpc.TaskProgress{Message: tr("WARNING cannot configure platform: %s", err)})
176179
}
177180
} else {
@@ -222,22 +225,19 @@ func (pme *Explorer) cacheInstalledJSON(platformRelease *cores.PlatformRelease)
222225
}
223226

224227
// RunPostInstallScript runs the post_install.sh (or post_install.bat) script for the
225-
// specified platformRelease.
226-
func (pme *Explorer) RunPostInstallScript(platformRelease *cores.PlatformRelease) error {
227-
if !platformRelease.IsInstalled() {
228-
return errors.New(tr("platform not installed"))
229-
}
228+
// specified platformRelease or toolRelease.
229+
func (pme *Explorer) RunPostInstallScript(installDir *paths.Path) error {
230230
postInstallFilename := "post_install.sh"
231231
if runtime.GOOS == "windows" {
232232
postInstallFilename = "post_install.bat"
233233
}
234-
postInstall := platformRelease.InstallDir.Join(postInstallFilename)
234+
postInstall := installDir.Join(postInstallFilename)
235235
if postInstall.Exist() && postInstall.IsNotDir() {
236236
cmd, err := executils.NewProcessFromPath(pme.GetEnvVarsForSpawnedProcess(), postInstall)
237237
if err != nil {
238238
return err
239239
}
240-
cmd.SetDirFromPath(platformRelease.InstallDir)
240+
cmd.SetDirFromPath(installDir)
241241
if err := cmd.Run(); err != nil {
242242
return err
243243
}
@@ -299,7 +299,7 @@ func (pme *Explorer) UninstallPlatform(platformRelease *cores.PlatformRelease, t
299299
}
300300

301301
// InstallTool installs a specific release of a tool.
302-
func (pme *Explorer) InstallTool(toolRelease *cores.ToolRelease, taskCB rpc.TaskProgressCB) error {
302+
func (pme *Explorer) InstallTool(toolRelease *cores.ToolRelease, taskCB rpc.TaskProgressCB, skipPostInstall bool) error {
303303
log := pme.log.WithField("Tool", toolRelease)
304304

305305
if toolRelease.IsInstalled() {
@@ -325,6 +325,22 @@ func (pme *Explorer) InstallTool(toolRelease *cores.ToolRelease, taskCB rpc.Task
325325
log.WithError(err).Warn("Cannot install tool")
326326
return &arduino.FailedInstallError{Message: tr("Cannot install tool %s", toolRelease), Cause: err}
327327
}
328+
if d, err := destDir.Abs(); err == nil {
329+
toolRelease.InstallDir = d
330+
} else {
331+
return err
332+
}
333+
// Perform post install
334+
if !skipPostInstall {
335+
log.Info("Running tool post_install script")
336+
taskCB(&rpc.TaskProgress{Message: tr("Configuring tool.")})
337+
if err := pme.RunPostInstallScript(toolRelease.InstallDir); err != nil {
338+
taskCB(&rpc.TaskProgress{Message: tr("WARNING cannot configure tool: %s", err)})
339+
}
340+
} else {
341+
log.Info("Skipping tool configuration.")
342+
taskCB(&rpc.TaskProgress{Message: tr("Skipping tool configuration.")})
343+
}
328344
log.Info("Tool installed")
329345
taskCB(&rpc.TaskProgress{Message: tr("%s installed", toolRelease), Completed: true})
330346

Diff for: arduino/errors.go

+26-2
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func (e *MissingProgrammerError) ToRPCStatus() *status.Status {
293293
return status.New(codes.InvalidArgument, e.Error())
294294
}
295295

296-
// ProgrammerRequiredForUploadError is returned then the upload can be done only using a programmer
296+
// ProgrammerRequiredForUploadError is returned when the upload can be done only using a programmer
297297
type ProgrammerRequiredForUploadError struct{}
298298

299299
func (e *ProgrammerRequiredForUploadError) Error() string {
@@ -308,6 +308,28 @@ func (e *ProgrammerRequiredForUploadError) ToRPCStatus() *status.Status {
308308
return st
309309
}
310310

311+
// InitFailedError is returned when the instance initialization fails
312+
type InitFailedError struct {
313+
Code codes.Code
314+
Cause error
315+
Reason rpc.FailedInstanceInitReason
316+
}
317+
318+
func (ife *InitFailedError) Error() string {
319+
return ife.Cause.Error()
320+
}
321+
322+
// ToRPCStatus converts the error into a *status.Status
323+
func (ife *InitFailedError) ToRPCStatus() *status.Status {
324+
st, _ := status.
325+
New(ife.Code, ife.Cause.Error()).
326+
WithDetails(&rpc.FailedInstanceInitError{
327+
Reason: ife.Reason,
328+
Message: ife.Cause.Error(),
329+
})
330+
return st
331+
}
332+
311333
// ProgrammerNotFoundError is returned when the programmer is not found
312334
type ProgrammerNotFoundError struct {
313335
Programmer string
@@ -405,7 +427,9 @@ func (e *PlatformLoadingError) Error() string {
405427

406428
// ToRPCStatus converts the error into a *status.Status
407429
func (e *PlatformLoadingError) ToRPCStatus() *status.Status {
408-
return status.New(codes.FailedPrecondition, e.Error())
430+
s, _ := status.New(codes.FailedPrecondition, e.Error()).
431+
WithDetails(&rpc.PlatformLoadingError{})
432+
return s
409433
}
410434

411435
func (e *PlatformLoadingError) Unwrap() error {

Diff for: commands/instances.go

+31-11
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func installTool(pm *packagemanager.PackageManager, tool *cores.ToolRelease, dow
138138
return fmt.Errorf(tr("downloading %[1]s tool: %[2]s"), tool, err)
139139
}
140140
taskCB(&rpc.TaskProgress{Completed: true})
141-
if err := pme.InstallTool(tool, taskCB); err != nil {
141+
if err := pme.InstallTool(tool, taskCB, true); err != nil {
142142
return fmt.Errorf(tr("installing %[1]s tool: %[2]s"), tool, err)
143143
}
144144
return nil
@@ -307,23 +307,35 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
307307
for _, u := range urls {
308308
URL, err := utils.URLParse(u)
309309
if err != nil {
310-
s := status.Newf(codes.InvalidArgument, tr("Invalid additional URL: %v"), err)
311-
responseError(s)
310+
e := &arduino.InitFailedError{
311+
Code: codes.InvalidArgument,
312+
Cause: fmt.Errorf(tr("Invalid additional URL: %v", err)),
313+
Reason: rpc.FailedInstanceInitReason_FAILED_INSTANCE_INIT_REASON_INVALID_INDEX_URL,
314+
}
315+
responseError(e.ToRPCStatus())
312316
continue
313317
}
314318

315319
if URL.Scheme == "file" {
316320
_, err := pmb.LoadPackageIndexFromFile(paths.New(URL.Path))
317321
if err != nil {
318-
s := status.Newf(codes.FailedPrecondition, tr("Loading index file: %v"), err)
319-
responseError(s)
322+
e := &arduino.InitFailedError{
323+
Code: codes.FailedPrecondition,
324+
Cause: fmt.Errorf(tr("Loading index file: %v", err)),
325+
Reason: rpc.FailedInstanceInitReason_FAILED_INSTANCE_INIT_REASON_INDEX_LOAD_ERROR,
326+
}
327+
responseError(e.ToRPCStatus())
320328
}
321329
continue
322330
}
323331

324332
if err := pmb.LoadPackageIndex(URL); err != nil {
325-
s := status.Newf(codes.FailedPrecondition, tr("Loading index file: %v"), err)
326-
responseError(s)
333+
e := &arduino.InitFailedError{
334+
Code: codes.FailedPrecondition,
335+
Cause: fmt.Errorf(tr("Loading index file: %v", err)),
336+
Reason: rpc.FailedInstanceInitReason_FAILED_INSTANCE_INIT_REASON_INDEX_LOAD_ERROR,
337+
}
338+
responseError(e.ToRPCStatus())
327339
}
328340
}
329341

@@ -335,8 +347,12 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
335347
for name, tool := range pmb.GetOrCreatePackage("builtin").Tools {
336348
latest := tool.LatestRelease()
337349
if latest == nil {
338-
s := status.Newf(codes.Internal, tr("can't find latest release of tool %s", name))
339-
responseError(s)
350+
e := &arduino.InitFailedError{
351+
Code: codes.Internal,
352+
Cause: fmt.Errorf(tr("can't find latest release of tool %s", name)),
353+
Reason: rpc.FailedInstanceInitReason_FAILED_INSTANCE_INIT_REASON_TOOL_LOAD_ERROR,
354+
}
355+
responseError(e.ToRPCStatus())
340356
} else if !latest.IsInstalled() {
341357
builtinToolsToInstall = append(builtinToolsToInstall, latest)
342358
}
@@ -346,8 +362,12 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
346362
if len(builtinToolsToInstall) > 0 {
347363
for _, toolRelease := range builtinToolsToInstall {
348364
if err := installTool(pmb.Build(), toolRelease, downloadCallback, taskCallback); err != nil {
349-
s := status.Newf(codes.Internal, err.Error())
350-
responseError(s)
365+
e := &arduino.InitFailedError{
366+
Code: codes.Internal,
367+
Cause: err,
368+
Reason: rpc.FailedInstanceInitReason_FAILED_INSTANCE_INIT_REASON_TOOL_LOAD_ERROR,
369+
}
370+
responseError(e.ToRPCStatus())
351371
}
352372
}
353373

Diff for: commands/lib/install.go

+3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
103103
if installTask.ReplacedLib != nil {
104104
downloadReason = "upgrade"
105105
}
106+
if installLocation == libraries.IDEBuiltIn {
107+
downloadReason += "-builtin"
108+
}
106109
}
107110
if err := downloadLibrary(lm, libRelease, downloadCB, taskCB, downloadReason); err != nil {
108111
return err

Diff for: configuration/configuration.go

+2-20
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ func GetDefaultBuiltinLibrariesDir() string {
136136
return filepath.Join(getDefaultArduinoDataDir(), "libraries")
137137
}
138138

139-
// FindConfigFileInArgsOrWorkingDirectory returns the config file path using the
139+
// FindConfigFileInArgs returns the config file path using the
140140
// argument '--config-file' (if specified) or looking in the current working dir
141-
func FindConfigFileInArgsOrWorkingDirectory(args []string) string {
141+
func FindConfigFileInArgs(args []string) string {
142142
// Look for '--config-file' argument
143143
for i, arg := range args {
144144
if arg == "--config-file" {
@@ -147,23 +147,5 @@ func FindConfigFileInArgsOrWorkingDirectory(args []string) string {
147147
}
148148
}
149149
}
150-
151-
// Look into current working directory
152-
if cwd, err := paths.Getwd(); err != nil {
153-
return ""
154-
} else if configFile := searchConfigTree(cwd); configFile != nil {
155-
return configFile.Join("arduino-cli.yaml").String()
156-
}
157150
return ""
158151
}
159-
160-
func searchConfigTree(cwd *paths.Path) *paths.Path {
161-
// go back up to root and search for the config file
162-
for _, path := range cwd.Parents() {
163-
if path.Join("arduino-cli.yaml").Exist() {
164-
return path
165-
}
166-
}
167-
168-
return nil
169-
}

0 commit comments

Comments
 (0)