Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-cli
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-cli
Commits
ba13ab4c
Unverified
Commit
ba13ab4c
authored
Oct 12, 2020
by
Silvano Cerza
Committed by
GitHub
Oct 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix core search command not searching through package terms (#1016)
parent
1d1da069
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
449 additions
and
1 deletion
+449
-1
commands/core/search.go
commands/core/search.go
+3
-1
commands/core/search_test.go
commands/core/search_test.go
+187
-0
commands/core/testdata/package_index.json
commands/core/testdata/package_index.json
+135
-0
test/test_core.py
test/test_core.py
+31
-0
test/testdata/test_index.json
test/testdata/test_index.json
+93
-0
No files found.
commands/core/search.go
View file @
ba13ab4c
...
...
@@ -59,7 +59,9 @@ func PlatformSearch(instanceID int32, searchArgs string, allVersions bool) (*rpc
}
// platform has a valid release, check if it matches the search arguments
if
match
(
platform
.
Name
,
searchArgs
)
||
match
(
platform
.
Architecture
,
searchArgs
)
||
exactMatch
(
platform
.
String
(),
searchArgs
)
{
if
match
(
platform
.
Name
,
searchArgs
)
||
match
(
platform
.
Architecture
,
searchArgs
)
||
exactMatch
(
platform
.
String
(),
searchArgs
)
||
match
(
targetPackage
.
Name
,
searchArgs
)
||
match
(
targetPackage
.
Maintainer
,
searchArgs
)
||
match
(
targetPackage
.
WebsiteURL
,
searchArgs
)
{
if
allVersions
{
res
=
append
(
res
,
platform
.
GetAllReleases
()
...
)
}
else
{
...
...
commands/core/search_test.go
View file @
ba13ab4c
...
...
@@ -16,9 +16,15 @@
package
core
import
(
"os"
"testing"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/configuration"
"github.com/arduino/arduino-cli/rpc/commands"
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func
TestMatch
(
t
*
testing
.
T
)
{
...
...
@@ -27,3 +33,184 @@ func TestMatch(t *testing.T) {
assert
.
True
(
t
,
match
(
"this is platform Foo"
,
""
))
assert
.
False
(
t
,
match
(
"this is platform Foo"
,
"Bar"
))
}
func
TestPlatformSearch
(
t
*
testing
.
T
)
{
dataDir
:=
paths
.
TempDir
()
.
Join
(
"test"
,
"data_dir"
)
downloadDir
:=
paths
.
TempDir
()
.
Join
(
"test"
,
"staging"
)
os
.
Setenv
(
"ARDUINO_DATA_DIR"
,
dataDir
.
String
())
os
.
Setenv
(
"ARDUINO_DOWNLOADS_DIR"
,
downloadDir
.
String
())
dataDir
.
MkdirAll
()
downloadDir
.
MkdirAll
()
defer
paths
.
TempDir
()
.
Join
(
"test"
)
.
RemoveAll
()
err
:=
paths
.
New
(
"testdata"
)
.
Join
(
"package_index.json"
)
.
CopyTo
(
dataDir
.
Join
(
"package_index.json"
))
require
.
Nil
(
t
,
err
)
configuration
.
Init
(
paths
.
TempDir
()
.
Join
(
"test"
,
"arduino-cli.yaml"
)
.
String
())
inst
,
err
:=
instance
.
CreateInstance
()
require
.
Nil
(
t
,
err
)
require
.
NotNil
(
t
,
inst
)
res
,
err
:=
PlatformSearch
(
inst
.
GetId
(),
"retrokit"
,
true
)
require
.
Nil
(
t
,
err
)
require
.
NotNil
(
t
,
res
)
require
.
Len
(
t
,
res
.
SearchOutput
,
2
)
require
.
Contains
(
t
,
res
.
SearchOutput
,
&
commands
.
Platform
{
ID
:
"Retrokits-RK002:arm"
,
Installed
:
""
,
Latest
:
"1.0.5"
,
Name
:
"RK002"
,
Maintainer
:
"Retrokits (www.retrokits.com)"
,
Website
:
"https://www.retrokits.com"
,
Email
:
"info@retrokits.com"
,
Boards
:
[]
*
commands
.
Board
{{
Name
:
"RK002"
}},
})
require
.
Contains
(
t
,
res
.
SearchOutput
,
&
commands
.
Platform
{
ID
:
"Retrokits-RK002:arm"
,
Installed
:
""
,
Latest
:
"1.0.6"
,
Name
:
"RK002"
,
Maintainer
:
"Retrokits (www.retrokits.com)"
,
Website
:
"https://www.retrokits.com"
,
Email
:
"info@retrokits.com"
,
Boards
:
[]
*
commands
.
Board
{{
Name
:
"RK002"
}},
})
res
,
err
=
PlatformSearch
(
inst
.
GetId
(),
"retrokit"
,
false
)
require
.
Nil
(
t
,
err
)
require
.
NotNil
(
t
,
res
)
require
.
Len
(
t
,
res
.
SearchOutput
,
1
)
require
.
Contains
(
t
,
res
.
SearchOutput
,
&
commands
.
Platform
{
ID
:
"Retrokits-RK002:arm"
,
Installed
:
""
,
Latest
:
"1.0.6"
,
Name
:
"RK002"
,
Maintainer
:
"Retrokits (www.retrokits.com)"
,
Website
:
"https://www.retrokits.com"
,
Email
:
"info@retrokits.com"
,
Boards
:
[]
*
commands
.
Board
{{
Name
:
"RK002"
}},
})
// Search the Package Maintainer
res
,
err
=
PlatformSearch
(
inst
.
GetId
(),
"Retrokits (www.retrokits.com)"
,
true
)
require
.
Nil
(
t
,
err
)
require
.
NotNil
(
t
,
res
)
require
.
Len
(
t
,
res
.
SearchOutput
,
2
)
require
.
Contains
(
t
,
res
.
SearchOutput
,
&
commands
.
Platform
{
ID
:
"Retrokits-RK002:arm"
,
Installed
:
""
,
Latest
:
"1.0.5"
,
Name
:
"RK002"
,
Maintainer
:
"Retrokits (www.retrokits.com)"
,
Website
:
"https://www.retrokits.com"
,
Email
:
"info@retrokits.com"
,
Boards
:
[]
*
commands
.
Board
{{
Name
:
"RK002"
}},
})
require
.
Contains
(
t
,
res
.
SearchOutput
,
&
commands
.
Platform
{
ID
:
"Retrokits-RK002:arm"
,
Installed
:
""
,
Latest
:
"1.0.6"
,
Name
:
"RK002"
,
Maintainer
:
"Retrokits (www.retrokits.com)"
,
Website
:
"https://www.retrokits.com"
,
Email
:
"info@retrokits.com"
,
Boards
:
[]
*
commands
.
Board
{{
Name
:
"RK002"
}},
})
// Search using the Package name
res
,
err
=
PlatformSearch
(
inst
.
GetId
(),
"Retrokits-RK002"
,
true
)
require
.
Nil
(
t
,
err
)
require
.
NotNil
(
t
,
res
)
require
.
Len
(
t
,
res
.
SearchOutput
,
2
)
require
.
Contains
(
t
,
res
.
SearchOutput
,
&
commands
.
Platform
{
ID
:
"Retrokits-RK002:arm"
,
Installed
:
""
,
Latest
:
"1.0.5"
,
Name
:
"RK002"
,
Maintainer
:
"Retrokits (www.retrokits.com)"
,
Website
:
"https://www.retrokits.com"
,
Email
:
"info@retrokits.com"
,
Boards
:
[]
*
commands
.
Board
{{
Name
:
"RK002"
}},
})
require
.
Contains
(
t
,
res
.
SearchOutput
,
&
commands
.
Platform
{
ID
:
"Retrokits-RK002:arm"
,
Installed
:
""
,
Latest
:
"1.0.6"
,
Name
:
"RK002"
,
Maintainer
:
"Retrokits (www.retrokits.com)"
,
Website
:
"https://www.retrokits.com"
,
Email
:
"info@retrokits.com"
,
Boards
:
[]
*
commands
.
Board
{{
Name
:
"RK002"
}},
})
// Search using the Platform name
res
,
err
=
PlatformSearch
(
inst
.
GetId
(),
"rk002"
,
true
)
require
.
Nil
(
t
,
err
)
require
.
NotNil
(
t
,
res
)
require
.
Len
(
t
,
res
.
SearchOutput
,
2
)
require
.
Contains
(
t
,
res
.
SearchOutput
,
&
commands
.
Platform
{
ID
:
"Retrokits-RK002:arm"
,
Installed
:
""
,
Latest
:
"1.0.5"
,
Name
:
"RK002"
,
Maintainer
:
"Retrokits (www.retrokits.com)"
,
Website
:
"https://www.retrokits.com"
,
Email
:
"info@retrokits.com"
,
Boards
:
[]
*
commands
.
Board
{{
Name
:
"RK002"
}},
})
require
.
Contains
(
t
,
res
.
SearchOutput
,
&
commands
.
Platform
{
ID
:
"Retrokits-RK002:arm"
,
Installed
:
""
,
Latest
:
"1.0.6"
,
Name
:
"RK002"
,
Maintainer
:
"Retrokits (www.retrokits.com)"
,
Website
:
"https://www.retrokits.com"
,
Email
:
"info@retrokits.com"
,
Boards
:
[]
*
commands
.
Board
{{
Name
:
"RK002"
}},
})
// Search using a board name
res
,
err
=
PlatformSearch
(
inst
.
GetId
(),
"Yún"
,
true
)
require
.
Nil
(
t
,
err
)
require
.
NotNil
(
t
,
res
)
require
.
Len
(
t
,
res
.
SearchOutput
,
1
)
require
.
Contains
(
t
,
res
.
SearchOutput
,
&
commands
.
Platform
{
ID
:
"arduino:avr"
,
Installed
:
""
,
Latest
:
"1.8.3"
,
Name
:
"Arduino AVR Boards"
,
Maintainer
:
"Arduino"
,
Website
:
"https://www.arduino.cc/"
,
Email
:
"packages@arduino.cc"
,
Boards
:
[]
*
commands
.
Board
{
{
Name
:
"Arduino Yún"
},
{
Name
:
"Arduino Uno"
},
{
Name
:
"Arduino Uno WiFi"
},
{
Name
:
"Arduino Diecimila"
},
{
Name
:
"Arduino Nano"
},
{
Name
:
"Arduino Mega"
},
{
Name
:
"Arduino MegaADK"
},
{
Name
:
"Arduino Leonardo"
},
{
Name
:
"Arduino Leonardo Ethernet"
},
{
Name
:
"Arduino Micro"
},
{
Name
:
"Arduino Esplora"
},
{
Name
:
"Arduino Mini"
},
{
Name
:
"Arduino Ethernet"
},
{
Name
:
"Arduino Fio"
},
{
Name
:
"Arduino BT"
},
{
Name
:
"Arduino LilyPadUSB"
},
{
Name
:
"Arduino Lilypad"
},
{
Name
:
"Arduino Pro"
},
{
Name
:
"Arduino ATMegaNG"
},
{
Name
:
"Arduino Robot Control"
},
{
Name
:
"Arduino Robot Motor"
},
{
Name
:
"Arduino Gemma"
},
{
Name
:
"Adafruit Circuit Playground"
},
{
Name
:
"Arduino Yún Mini"
},
{
Name
:
"Arduino Industrial 101"
},
{
Name
:
"Linino One"
},
},
})
}
commands/core/testdata/package_index.json
0 → 100644
View file @
ba13ab4c
{
"packages"
:
[
{
"name"
:
"arduino"
,
"maintainer"
:
"Arduino"
,
"websiteURL"
:
"https://www.arduino.cc/"
,
"email"
:
"packages@arduino.cc"
,
"help"
:
{
"online"
:
"http://www.arduino.cc/en/Reference/HomePage"
},
"platforms"
:
[
{
"name"
:
"Arduino AVR Boards"
,
"architecture"
:
"avr"
,
"version"
:
"1.8.3"
,
"category"
:
"Arduino"
,
"help"
:
{
"online"
:
"http://www.arduino.cc/en/Reference/HomePage"
},
"url"
:
"http://downloads.arduino.cc/cores/avr-1.8.3.tar.bz2"
,
"archiveFileName"
:
"avr-1.8.3.tar.bz2"
,
"checksum"
:
"SHA-256:de8a9b982477762d3d3e52fc2b682cdd8ff194dc3f1d46f4debdea6a01b33c14"
,
"size"
:
"4941548"
,
"boards"
:
[
{
"name"
:
"Arduino Yún"
},
{
"name"
:
"Arduino Uno"
},
{
"name"
:
"Arduino Uno WiFi"
},
{
"name"
:
"Arduino Diecimila"
},
{
"name"
:
"Arduino Nano"
},
{
"name"
:
"Arduino Mega"
},
{
"name"
:
"Arduino MegaADK"
},
{
"name"
:
"Arduino Leonardo"
},
{
"name"
:
"Arduino Leonardo Ethernet"
},
{
"name"
:
"Arduino Micro"
},
{
"name"
:
"Arduino Esplora"
},
{
"name"
:
"Arduino Mini"
},
{
"name"
:
"Arduino Ethernet"
},
{
"name"
:
"Arduino Fio"
},
{
"name"
:
"Arduino BT"
},
{
"name"
:
"Arduino LilyPadUSB"
},
{
"name"
:
"Arduino Lilypad"
},
{
"name"
:
"Arduino Pro"
},
{
"name"
:
"Arduino ATMegaNG"
},
{
"name"
:
"Arduino Robot Control"
},
{
"name"
:
"Arduino Robot Motor"
},
{
"name"
:
"Arduino Gemma"
},
{
"name"
:
"Adafruit Circuit Playground"
},
{
"name"
:
"Arduino Yún Mini"
},
{
"name"
:
"Arduino Industrial 101"
},
{
"name"
:
"Linino One"
}
],
"toolsDependencies"
:
[
{
"packager"
:
"arduino"
,
"name"
:
"avr-gcc"
,
"version"
:
"7.3.0-atmel3.6.1-arduino7"
},
{
"packager"
:
"arduino"
,
"name"
:
"avrdude"
,
"version"
:
"6.3.0-arduino17"
},
{
"packager"
:
"arduino"
,
"name"
:
"arduinoOTA"
,
"version"
:
"1.3.0"
}
]
}
]
},
{
"name"
:
"Retrokits-RK002"
,
"maintainer"
:
"Retrokits (www.retrokits.com)"
,
"websiteURL"
:
"https://www.retrokits.com"
,
"email"
:
"info@retrokits.com"
,
"help"
:
{
"online"
:
"https://www.retrokits.com/rk002/arduino"
},
"platforms"
:
[
{
"name"
:
"RK002"
,
"architecture"
:
"arm"
,
"version"
:
"1.0.5"
,
"category"
:
"Contributed"
,
"help"
:
{
"online"
:
"https://www.retrokits.com/rk002/arduino"
},
"url"
:
"https://www.retrokits.com/rk002/arduino/retrokits-rk002-1.0.5.tar.bz2"
,
"archiveFileName"
:
"retrokits-rk002-1.0.5.tar.bz2"
,
"checksum"
:
"SHA-256:9a012867baf4bb26f656f84502e0acce6a653c3452cca4505ebac77256802fb6"
,
"size"
:
"290784"
,
"boards"
:
[{
"name"
:
"RK002"
}],
"toolsDependencies"
:
[
{
"packager"
:
"arduino"
,
"version"
:
"4.8.3-2014q1"
,
"name"
:
"arm-none-eabi-gcc"
}
]
}
],
"tools"
:
[]
},
{
"name"
:
"Retrokits-RK002"
,
"maintainer"
:
"Retrokits (www.retrokits.com)"
,
"websiteURL"
:
"https://www.retrokits.com"
,
"email"
:
"info@retrokits.com"
,
"help"
:
{
"online"
:
"https://www.retrokits.com/rk002/arduino"
},
"platforms"
:
[
{
"name"
:
"RK002"
,
"architecture"
:
"arm"
,
"version"
:
"1.0.6"
,
"category"
:
"Contributed"
,
"help"
:
{
"online"
:
"https://www.retrokits.com/rk002/arduino"
},
"url"
:
"https://www.retrokits.com/rk002/arduino/retrokits-rk002-1.0.6.tar.bz2"
,
"archiveFileName"
:
"retrokits-rk002-1.0.6.tar.bz2"
,
"checksum"
:
"SHA-256:8a3b63efcf4dfaed047a37844861387e542d8519485b5305d5979630cb3feb20"
,
"size"
:
"291631"
,
"boards"
:
[{
"name"
:
"RK002"
}],
"toolsDependencies"
:
[
{
"packager"
:
"arduino"
,
"version"
:
"4.8.3-2014q1"
,
"name"
:
"arm-none-eabi-gcc"
}
]
}
],
"tools"
:
[]
}
]
}
test/test_core.py
View file @
ba13ab4c
...
...
@@ -45,6 +45,37 @@ def test_core_search(run_command, httpserver):
data
=
json
.
loads
(
result
.
stdout
)
assert
2
==
len
(
data
)
# Search all Retrokit platforms
result
=
run_command
(
f"core search retrokit --all --additional-urls=
{
url
}
"
)
assert
result
.
ok
assert
3
==
len
(
result
.
stdout
.
strip
().
splitlines
())
lines
=
[
l
.
split
(
maxsplit
=
2
)
for
l
in
result
.
stdout
.
strip
().
splitlines
()]
assert
[
"Retrokits-RK002:arm"
,
"1.0.5"
,
"RK002"
]
in
lines
assert
[
"Retrokits-RK002:arm"
,
"1.0.6"
,
"RK002"
]
in
lines
# Search using Retrokit Package Maintainer
result
=
run_command
(
f"core search Retrokits-RK002 --all --additional-urls=
{
url
}
"
)
assert
result
.
ok
assert
3
==
len
(
result
.
stdout
.
strip
().
splitlines
())
lines
=
[
l
.
split
(
maxsplit
=
2
)
for
l
in
result
.
stdout
.
strip
().
splitlines
()]
assert
[
"Retrokits-RK002:arm"
,
"1.0.5"
,
"RK002"
]
in
lines
assert
[
"Retrokits-RK002:arm"
,
"1.0.6"
,
"RK002"
]
in
lines
# Search using the Retrokit Platform name
result
=
run_command
(
f"core search rk002 --all --additional-urls=
{
url
}
"
)
assert
result
.
ok
assert
3
==
len
(
result
.
stdout
.
strip
().
splitlines
())
lines
=
[
l
.
split
(
maxsplit
=
2
)
for
l
in
result
.
stdout
.
strip
().
splitlines
()]
assert
[
"Retrokits-RK002:arm"
,
"1.0.5"
,
"RK002"
]
in
lines
assert
[
"Retrokits-RK002:arm"
,
"1.0.6"
,
"RK002"
]
in
lines
# Search using a board name
result
=
run_command
(
f"core search myboard --all --additional-urls=
{
url
}
"
)
assert
result
.
ok
assert
2
==
len
(
result
.
stdout
.
strip
().
splitlines
())
lines
=
[
l
.
split
(
maxsplit
=
2
)
for
l
in
result
.
stdout
.
strip
().
splitlines
()]
assert
[
"Package:x86"
,
"1.2.3"
,
"Platform"
]
in
lines
def
test_core_search_no_args
(
run_command
,
httpserver
):
"""
...
...
test/testdata/test_index.json
View file @
ba13ab4c
...
...
@@ -111,6 +111,99 @@
]
}
]
},
{
"name"
:
"Retrokits-RK002"
,
"maintainer"
:
"Retrokits (www.retrokits.com)"
,
"websiteURL"
:
"https://www.retrokits.com"
,
"email"
:
"info@retrokits.com"
,
"help"
:
{
"online"
:
"https://www.retrokits.com/rk002/arduino"
},
"platforms"
:
[
{
"name"
:
"RK002"
,
"architecture"
:
"arm"
,
"version"
:
"1.0.5"
,
"category"
:
"Contributed"
,
"help"
:
{
"online"
:
"https://www.retrokits.com/rk002/arduino"
},
"url"
:
"https://www.retrokits.com/rk002/arduino/retrokits-rk002-1.0.5.tar.bz2"
,
"archiveFileName"
:
"retrokits-rk002-1.0.5.tar.bz2"
,
"checksum"
:
"SHA-256:9a012867baf4bb26f656f84502e0acce6a653c3452cca4505ebac77256802fb6"
,
"size"
:
"290784"
,
"boards"
:
[{
"name"
:
"RK002"
}],
"toolsDependencies"
:
[
{
"packager"
:
"arduino"
,
"version"
:
"4.8.3-2014q1"
,
"name"
:
"arm-none-eabi-gcc"
}
]
}
],
"tools"
:
[]
},
{
"name"
:
"Retrokits-RK002"
,
"maintainer"
:
"Retrokits (www.retrokits.com)"
,
"websiteURL"
:
"https://www.retrokits.com"
,
"email"
:
"info@retrokits.com"
,
"help"
:
{
"online"
:
"https://www.retrokits.com/rk002/arduino"
},
"platforms"
:
[
{
"name"
:
"RK002"
,
"architecture"
:
"arm"
,
"version"
:
"1.0.6"
,
"category"
:
"Contributed"
,
"help"
:
{
"online"
:
"https://www.retrokits.com/rk002/arduino"
},
"url"
:
"https://www.retrokits.com/rk002/arduino/retrokits-rk002-1.0.6.tar.bz2"
,
"archiveFileName"
:
"retrokits-rk002-1.0.6.tar.bz2"
,
"checksum"
:
"SHA-256:8a3b63efcf4dfaed047a37844861387e542d8519485b5305d5979630cb3feb20"
,
"size"
:
"291631"
,
"boards"
:
[{
"name"
:
"RK002"
}],
"toolsDependencies"
:
[
{
"packager"
:
"arduino"
,
"version"
:
"4.8.3-2014q1"
,
"name"
:
"arm-none-eabi-gcc"
}
]
}
],
"tools"
:
[]
},
{
"name"
:
"Package"
,
"tools"
:
[],
"email"
:
"test@example.com"
,
"maintainer"
:
"Arduino"
,
"help"
:
{
"online"
:
"https://github.com/Arduino/arduino-cli"
},
"websiteURL"
:
"https://github.com/Arduino/arduino-cli"
,
"platforms"
:
[
{
"category"
:
"Test"
,
"help"
:
{
"online"
:
"https://github.com/Arduino/arduino-cli"
},
"url"
:
"https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/core.zip"
,
"checksum"
:
"SHA-256:6a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092"
,
"name"
:
"Platform"
,
"version"
:
"1.2.3"
,
"architecture"
:
"x86"
,
"archiveFileName"
:
"core.zip"
,
"size"
:
"486"
,
"toolsDependencies"
:
[],
"boards"
:
[
{
"name"
:
"MyBoard"
}
]
}
]
}
]
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment