diff --git a/arduino/cores/cores.go b/arduino/cores/cores.go index dafeae37802..f648293209c 100644 --- a/arduino/cores/cores.go +++ b/arduino/cores/cores.go @@ -142,6 +142,17 @@ func (platform *Platform) GetLatestRelease() *PlatformRelease { return platform.FindReleaseWithVersion(latestVersion) } +// GetAllReleases returns all the releases of this platform, or an empty +// slice if no releases are available +func (platform *Platform) GetAllReleases() []*PlatformRelease { + retVal := []*PlatformRelease{} + for _, v := range platform.GetAllReleasesVersions() { + retVal = append(retVal, platform.FindReleaseWithVersion(v)) + } + + return retVal +} + // GetAllReleasesVersions returns all the version numbers in this Platform Package. func (platform *Platform) GetAllReleasesVersions() []*semver.Version { versions := []*semver.Version{} diff --git a/cli/core/search.go b/cli/core/search.go index 4d38e41a14b..f31a7eddb1f 100644 --- a/cli/core/search.go +++ b/cli/core/search.go @@ -18,7 +18,6 @@ package core import ( - "context" "os" "sort" "strings" @@ -33,15 +32,21 @@ import ( "github.com/spf13/cobra" ) +var ( + allVersions bool +) + func initSearchCommand() *cobra.Command { searchCommand := &cobra.Command{ Use: "search ", Short: "Search for a core in the package index.", Long: "Search for a core in the package index using the specified keywords.", - Example: " " + os.Args[0] + " core search MKRZero -v", + Example: " " + os.Args[0] + " core search MKRZero -a -v", Args: cobra.ArbitraryArgs, Run: runSearchCommand, } + searchCommand.Flags().BoolVarP(&allVersions, "all", "a", false, "Show all available core versions.") + return searchCommand } @@ -50,10 +55,7 @@ func runSearchCommand(cmd *cobra.Command, args []string) { logrus.Info("Executing `arduino core search`") arguments := strings.ToLower(strings.Join(args, " ")) - resp, err := core.PlatformSearch(context.Background(), &rpc.PlatformSearchReq{ - Instance: instance, - SearchArgs: arguments, - }) + resp, err := core.PlatformSearch(instance.GetId(), arguments, allVersions) if err != nil { feedback.Errorf("Error saerching for platforms: %v", err) os.Exit(errorcodes.ErrGeneric) diff --git a/commands/core/core.go b/commands/core/core.go index 75ccc736f54..08d32a048a1 100644 --- a/commands/core/core.go +++ b/commands/core/core.go @@ -59,11 +59,7 @@ func PlatformReleaseToRPC(platformRelease *cores.PlatformRelease) *rpc.Platform Website: platformRelease.Platform.Package.WebsiteURL, Email: platformRelease.Platform.Package.Email, Boards: boards, - } - - latest := platformRelease.Platform.GetLatestRelease() - if latest != nil { - result.Latest = latest.Version.String() + Latest: platformRelease.Version.String(), } return result diff --git a/commands/core/search.go b/commands/core/search.go index 961773840a4..d08300bf207 100644 --- a/commands/core/search.go +++ b/commands/core/search.go @@ -18,7 +18,6 @@ package core import ( - "context" "errors" "regexp" "strings" @@ -28,37 +27,48 @@ import ( rpc "github.com/arduino/arduino-cli/rpc/commands" ) +func match(line, searchArgs string) bool { + return strings.Contains(strings.ToLower(line), searchArgs) +} + // PlatformSearch FIXMEDOC -func PlatformSearch(ctx context.Context, req *rpc.PlatformSearchReq) (*rpc.PlatformSearchResp, error) { - pm := commands.GetPackageManager(req.GetInstance().GetId()) +func PlatformSearch(instanceID int32, searchArgs string, allVersions bool) (*rpc.PlatformSearchResp, error) { + pm := commands.GetPackageManager(instanceID) if pm == nil { return nil, errors.New("invalid instance") } - search := req.SearchArgs - res := []*cores.PlatformRelease{} - if isUsb, _ := regexp.MatchString("[0-9a-f]{4}:[0-9a-f]{4}", search); isUsb { - vid, pid := search[:4], search[5:] + if isUsb, _ := regexp.MatchString("[0-9a-f]{4}:[0-9a-f]{4}", searchArgs); isUsb { + vid, pid := searchArgs[:4], searchArgs[5:] res = pm.FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid) } else { - match := func(line string) bool { - return strings.Contains(strings.ToLower(line), search) - } for _, targetPackage := range pm.Packages { for _, platform := range targetPackage.Platforms { platformRelease := platform.GetLatestRelease() if platformRelease == nil { continue } - if match(platform.Name) || match(platform.Architecture) { - res = append(res, platformRelease) - continue - } - for _, board := range platformRelease.BoardsManifest { - if match(board.Name) { + + // platform has a release, check if it matches the search arguments + if match(platform.Name, searchArgs) || match(platform.Architecture, searchArgs) { + if allVersions { + res = append(res, platform.GetAllReleases()...) + } else { res = append(res, platformRelease) - break + } + } else { + // if we didn't find a match in the platform data, search for + // a match in the boards manifest + for _, board := range platformRelease.BoardsManifest { + if match(board.Name, searchArgs) { + if allVersions { + res = append(res, platform.GetAllReleases()...) + } else { + res = append(res, platformRelease) + } + break + } } } } diff --git a/commands/daemon/daemon.go b/commands/daemon/daemon.go index b77b8f1d5ff..525ecd1c9dc 100644 --- a/commands/daemon/daemon.go +++ b/commands/daemon/daemon.go @@ -196,7 +196,7 @@ func (s *ArduinoCoreServerImpl) PlatformUpgrade(req *rpc.PlatformUpgradeReq, str // PlatformSearch FIXMEDOC func (s *ArduinoCoreServerImpl) PlatformSearch(ctx context.Context, req *rpc.PlatformSearchReq) (*rpc.PlatformSearchResp, error) { - return core.PlatformSearch(ctx, req) + return core.PlatformSearch(req.GetInstance().GetId(), req.GetSearchArgs(), req.GetAllVersions()) } // PlatformList FIXMEDOC diff --git a/rpc/commands/core.pb.go b/rpc/commands/core.pb.go index ea34ebf1dac..8ea9e3f0ef1 100644 --- a/rpc/commands/core.pb.go +++ b/rpc/commands/core.pb.go @@ -431,6 +431,7 @@ func (m *PlatformUpgradeResp) GetTaskProgress() *TaskProgress { type PlatformSearchReq struct { Instance *Instance `protobuf:"bytes,1,opt,name=instance,proto3" json:"instance,omitempty"` SearchArgs string `protobuf:"bytes,2,opt,name=search_args,json=searchArgs,proto3" json:"search_args,omitempty"` + AllVersions bool `protobuf:"varint,3,opt,name=all_versions,json=allVersions,proto3" json:"all_versions,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -475,6 +476,13 @@ func (m *PlatformSearchReq) GetSearchArgs() string { return "" } +func (m *PlatformSearchReq) GetAllVersions() bool { + if m != nil { + return m.AllVersions + } + return false +} + type PlatformSearchResp struct { SearchOutput []*Platform `protobuf:"bytes,1,rep,name=search_output,json=searchOutput,proto3" json:"search_output,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -762,43 +770,45 @@ func init() { func init() { proto.RegisterFile("commands/core.proto", fileDescriptor_ed02318f567db566) } var fileDescriptor_ed02318f567db566 = []byte{ - // 607 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x55, 0xdf, 0x6a, 0xd4, 0x4e, - 0x14, 0x26, 0xdb, 0x76, 0xbb, 0x3d, 0xfd, 0x3f, 0x6d, 0x7f, 0xbf, 0x20, 0x52, 0x6b, 0xa0, 0xd0, - 0x22, 0xcd, 0x82, 0x82, 0x77, 0x5e, 0x58, 0x5a, 0x61, 0xa5, 0xda, 0x25, 0x5a, 0x04, 0x51, 0x96, - 0xd9, 0xc9, 0x34, 0x1d, 0x9a, 0xcc, 0x4c, 0x67, 0x26, 0x96, 0xbe, 0x8e, 0x78, 0xe1, 0x43, 0xe8, - 0x1b, 0xf9, 0x10, 0x92, 0xc9, 0x4c, 0x76, 0x4b, 0x5d, 0x11, 0xe9, 0x45, 0xbd, 0xda, 0x39, 0x5f, - 0xce, 0xf9, 0xce, 0xf7, 0x9d, 0x9c, 0xc9, 0xc2, 0x1a, 0x11, 0x45, 0x81, 0x79, 0xaa, 0xbb, 0x44, - 0x28, 0x1a, 0x4b, 0x25, 0x8c, 0x40, 0xff, 0x13, 0x12, 0x63, 0x95, 0x96, 0x8c, 0x8b, 0x98, 0xe4, - 0x2c, 0xf6, 0x39, 0xf7, 0x36, 0xc6, 0xb2, 0x8b, 0x42, 0xf0, 0x3a, 0x3f, 0xfa, 0x16, 0x00, 0xea, - 0xe7, 0xd8, 0x9c, 0x0a, 0x55, 0xf4, 0xb8, 0x36, 0x38, 0xcf, 0x13, 0x7a, 0x81, 0x9e, 0x41, 0x87, - 0x55, 0x11, 0x27, 0x34, 0x0c, 0xb6, 0x82, 0x9d, 0xf9, 0xc7, 0x0f, 0xe3, 0x09, 0xcc, 0x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0xcc, 0xf2, 0x70, 0xd6, 0xe2, 0x75, 0x80, 0x9e, 0x42, - 0x7b, 0x5f, 0x60, 0x95, 0xea, 0xb0, 0x63, 0xcd, 0x6f, 0x4e, 0x34, 0x6f, 0xd3, 0x12, 0x97, 0x1d, - 0x75, 0x61, 0xc6, 0x9e, 0x2a, 0x91, 0xbc, 0x12, 0x59, 0x9b, 0xb5, 0xe7, 0x0a, 0x3b, 0xbd, 0x18, - 0x72, 0xe7, 0xd4, 0x9e, 0xf7, 0xf7, 0xde, 0x3f, 0xca, 0x98, 0x39, 0x2b, 0x87, 0x15, 0x63, 0xd7, - 0x75, 0xf0, 0xbf, 0x7b, 0x24, 0x67, 0x5d, 0x25, 0x49, 0xd7, 0x77, 0x1b, 0xb6, 0xed, 0x9f, 0xfd, - 0x93, 0x9f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x68, 0xa0, 0xff, 0xb6, 0x33, 0x08, 0x00, 0x00, + // 628 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x56, 0xdd, 0x6a, 0x14, 0x31, + 0x14, 0x66, 0xb6, 0xed, 0x76, 0x7b, 0xba, 0xfd, 0x4b, 0x5b, 0x1d, 0x44, 0x6a, 0x3b, 0x50, 0x68, + 0x91, 0xee, 0x82, 0x82, 0x77, 0x5e, 0x58, 0x5a, 0x61, 0xa5, 0xda, 0x65, 0xb4, 0x0a, 0xa2, 0x2c, + 0xd9, 0x99, 0x74, 0x1b, 0x9a, 0x49, 0xd2, 0x24, 0x63, 0xe9, 0x8b, 0xf8, 0x00, 0xe2, 0x85, 0x0f, + 0xa1, 0x6f, 0xe4, 0x43, 0xc8, 0x64, 0x92, 0xd9, 0x2d, 0x75, 0x45, 0xa4, 0x17, 0xeb, 0xd5, 0xe6, + 0x7c, 0x73, 0xce, 0x97, 0xef, 0x3b, 0xc9, 0x09, 0x0b, 0xab, 0x89, 0xc8, 0x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, 0x7b, 0x28, 0xfa, 0x19, 0x40, 0xc3, + 0x07, 0x68, 0x11, 0x6a, 0x9d, 0x03, 0x6b, 0x69, 0x2e, 0xae, 0x75, 0x0e, 0xd0, 0x7d, 0x98, 0xeb, + 0xf8, 0x0a, 0x77, 0x36, 0x43, 0x00, 0xdd, 0x81, 0xfa, 0x11, 0x36, 0x44, 0x1b, 0x77, 0xb3, 0x5d, + 0x84, 0x10, 0x4c, 0xbf, 0xc2, 0x19, 0x71, 0x4f, 0x9f, 0x5d, 0xa3, 0x0d, 0x80, 0x97, 0x98, 0x72, + 0x83, 0x29, 0x27, 0x2a, 0x9c, 0x29, 0x8f, 0x79, 0x88, 0x14, 0x2f, 0xe6, 0x3b, 0xd2, 0xd7, 0xd4, + 0x90, 0xb0, 0x5e, 0xbe, 0x98, 0x2e, 0x44, 0x6b, 0x30, 0x73, 0x98, 0x61, 0xca, 0xc2, 0x59, 0x8b, + 0x97, 0x01, 0x7a, 0x02, 0xf5, 0x7d, 0x81, 0x55, 0xaa, 0xc3, 0x86, 0x35, 0xbf, 0x31, 0xd6, 0xbc, + 0x4d, 0x8b, 0x5d, 0x76, 0xd4, 0x86, 0x19, 0xbb, 0x2a, 0x44, 0xf2, 0x42, 0x64, 0x69, 0xd6, 0xae, + 0x0b, 0xec, 0xf4, 0xa2, 0xcf, 0x9d, 0x53, 0xbb, 0xde, 0xdf, 0x7b, 0xff, 0x70, 0x40, 0xcd, 0x59, + 0xde, 0x2f, 0x18, 0xdb, 0x6e, 0x07, 0xff, 0xbb, 0x97, 0x30, 0xda, 0x56, 0x32, 0x69, 0xfb, 0xdd, + 0xfa, 0x75, 0xfb, 0x87, 0xe0, 0xf1, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x09, 0x05, 0xe5, 0x68, + 0x57, 0x08, 0x00, 0x00, } diff --git a/rpc/commands/core.proto b/rpc/commands/core.proto index 9786f4edf3c..1449e2a5fc4 100644 --- a/rpc/commands/core.proto +++ b/rpc/commands/core.proto @@ -70,6 +70,7 @@ message PlatformUpgradeResp { message PlatformSearchReq { Instance instance = 1; string search_args = 2; + bool all_versions = 3; } message PlatformSearchResp { diff --git a/test/test_board.py b/test/test_board.py index 7bc135d69bc..ea41d69369d 100644 --- a/test/test_board.py +++ b/test/test_board.py @@ -19,7 +19,7 @@ @pytest.mark.skipif(running_on_ci(), reason="VMs have no serial ports") -def test_core_list(run_command): +def test_board_list(run_command): result = run_command("core update-index") assert result.ok result = run_command("board list --format json") @@ -33,37 +33,9 @@ def test_core_list(run_command): @pytest.mark.skipif(running_on_ci(), reason="VMs have no serial ports") -def test_core_listall(run_command): +def test_board_listall(run_command): assert run_command("core update-index") result = run_command("board listall") print(result.stderr, result.stdout) assert result.ok assert ["Board", "Name", "FQBN"] == result.stdout.splitlines()[0].strip().split() - - -def test_core_search(run_command): - url = "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/test_index.json" - assert run_command("core update-index --additional-urls={}".format(url)) - # list all - result = run_command("core search") - assert result.ok - assert 3 < len(result.stdout.splitlines()) - result = run_command("core search --format json") - assert result.ok - data = json.loads(result.stdout) - assert 1 < len(data) - # search a specific core - result = run_command("core search avr") - assert result.ok - assert 2 < len(result.stdout.splitlines()) - result = run_command("core search avr --format json") - assert result.ok - data = json.loads(result.stdout) - assert 0 < len(data) - # additional URL - result = run_command( - "core search test_core --format json --additional-urls={}".format(url) - ) - assert result.ok - data = json.loads(result.stdout) - assert 1 == len(data) diff --git a/test/test_core.py b/test/test_core.py new file mode 100644 index 00000000000..86eda27ea6e --- /dev/null +++ b/test/test_core.py @@ -0,0 +1,53 @@ +# This file is part of arduino-cli. +# +# Copyright 2019 ARDUINO SA (http://www.arduino.cc/) +# +# This software is released under the GNU General Public License version 3, +# which covers the main part of arduino-cli. +# The terms of this license can be found at: +# https://www.gnu.org/licenses/gpl-3.0.en.html +# +# You can be released from the requirements of the above licenses by purchasing +# a commercial license. Buying such a license is mandatory if you want to modify or +# otherwise use the software for commercial activities involving the Arduino +# software without disclosing the source code of your own applications. To purchase +# a commercial license, send an email to license@arduino.cc. +import pytest +import simplejson as json + +from .common import running_on_ci + + +def test_core_search(run_command): + url = "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/test_index.json" + assert run_command("core update-index --additional-urls={}".format(url)) + # list all + result = run_command("core search") + assert result.ok + assert 3 < len(result.stdout.splitlines()) + result = run_command("core search --format json") + assert result.ok + data = json.loads(result.stdout) + assert 1 < len(data) + # search a specific core + result = run_command("core search avr") + assert result.ok + assert 2 < len(result.stdout.splitlines()) + result = run_command("core search avr --format json") + assert result.ok + data = json.loads(result.stdout) + assert 0 < len(data) + # additional URL + result = run_command( + "core search test_core --format json --additional-urls={}".format(url) + ) + assert result.ok + data = json.loads(result.stdout) + assert 1 == len(data) + # show all versions + result = run_command( + "core search test_core --all --format json --additional-urls={}".format(url) + ) + assert result.ok + data = json.loads(result.stdout) + assert 2 == len(data) diff --git a/test/testdata/test_index.json b/test/testdata/test_index.json index d84277fbc13..3965c18c8a1 100644 --- a/test/testdata/test_index.json +++ b/test/testdata/test_index.json @@ -25,6 +25,25 @@ "name": "Test Board" } ] + }, + { + "category": "Test Category", + "help": { + "online": "https://github.com/Arduino/arduino-cli" + }, + "url": "https://raw.githubusercontent.com/arduino/arduino-cli/massi/additional-urls/test/testdata/core.txt", + "checksum": "SHA-256:1ba93f6aea56842dfef065c0f5eb0a34c1f78b72b3f2426c94e47ba3a359c9ff", + "name": "test_core", + "version": "2.0.0", + "architecture": "x86", + "archiveFileName": "core.txt", + "size": "2799", + "toolsDependencies": [], + "boards": [ + { + "name": "Test Board" + } + ] } ], "tools": [],