|
| 1 | +// This file is part of arduino-cli. |
| 2 | +// |
| 3 | +// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) |
| 4 | +// |
| 5 | +// This software is released under the GNU General Public License version 3, |
| 6 | +// which covers the main part of arduino-cli. |
| 7 | +// The terms of this license can be found at: |
| 8 | +// https://www.gnu.org/licenses/gpl-3.0.en.html |
| 9 | +// |
| 10 | +// You can be released from the requirements of the above licenses by purchasing |
| 11 | +// a commercial license. Buying such a license is mandatory if you want to |
| 12 | +// modify or otherwise use the software for commercial activities involving the |
| 13 | +// Arduino software without disclosing the source code of your own applications. |
| 14 | +// To purchase a commercial license, send an email to [email protected]. |
| 15 | + |
| 16 | +package sketch |
| 17 | + |
| 18 | +import ( |
| 19 | + "context" |
| 20 | + |
| 21 | + "github.com/arduino/arduino-cli/arduino" |
| 22 | + "github.com/arduino/arduino-cli/arduino/sketch" |
| 23 | + rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" |
| 24 | + paths "github.com/arduino/go-paths-helper" |
| 25 | +) |
| 26 | + |
| 27 | +// LoadSketch collects and returns all files composing a sketch |
| 28 | +func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketchResponse, error) { |
| 29 | + // TODO: This should be a ToRpc function for the Sketch struct |
| 30 | + sk, err := sketch.New(paths.New(req.SketchPath)) |
| 31 | + if err != nil { |
| 32 | + return nil, &arduino.CantOpenSketchError{Cause: err} |
| 33 | + } |
| 34 | + |
| 35 | + otherSketchFiles := make([]string, sk.OtherSketchFiles.Len()) |
| 36 | + for i, file := range sk.OtherSketchFiles { |
| 37 | + otherSketchFiles[i] = file.String() |
| 38 | + } |
| 39 | + |
| 40 | + additionalFiles := make([]string, sk.AdditionalFiles.Len()) |
| 41 | + for i, file := range sk.AdditionalFiles { |
| 42 | + additionalFiles[i] = file.String() |
| 43 | + } |
| 44 | + |
| 45 | + rootFolderFiles := make([]string, sk.RootFolderFiles.Len()) |
| 46 | + for i, file := range sk.RootFolderFiles { |
| 47 | + rootFolderFiles[i] = file.String() |
| 48 | + } |
| 49 | + |
| 50 | + return &rpc.LoadSketchResponse{ |
| 51 | + MainFile: sk.MainFile.String(), |
| 52 | + LocationPath: sk.FullPath.String(), |
| 53 | + OtherSketchFiles: otherSketchFiles, |
| 54 | + AdditionalFiles: additionalFiles, |
| 55 | + RootFolderFiles: rootFolderFiles, |
| 56 | + }, nil |
| 57 | +} |
0 commit comments