Skip to content

Commit

Permalink
Added builtin:mdns-discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Jul 21, 2021
1 parent c5159d1 commit 1ab82ed
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 1 deletion.
1 change: 1 addition & 0 deletions arduino/cores/packagemanager/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ func (pm *PackageManager) loadPlatformRelease(platform *cores.PlatformRelease, p
platform.PluggableDiscoveryAware = true
} else {
platform.Properties.Set("discovery.required.0", "builtin:serial-discovery")
platform.Properties.Set("discovery.required.1", "builtin:mdns-discovery")
}

if platform.Platform.Name == "" {
Expand Down
109 changes: 109 additions & 0 deletions commands/bundled_tools_mdns_discovery.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// This file is part of arduino-cli.
//
// Copyright 2021 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.

package commands

import (
"fmt"

"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/arduino/resources"
semver "go.bug.st/relaxed-semver"
)

var (
mdnsDiscoveryVersion = semver.ParseRelaxed("1.0.0")
mdnsDiscoveryFlavors = []*cores.Flavor{
{
OS: "i686-pc-linux-gnu",
Resource: &resources.DownloadResource{
ArchiveFileName: fmt.Sprintf("mdns-discovery_v%s_Linux_32bit.tar.bz2", mdnsDiscoveryVersion),
URL: fmt.Sprintf("https://downloads.arduino.cc/discovery/mdns-discovery/mdns-discovery_v%s_Linux_32bit.tar.gz", mdnsDiscoveryVersion),
Size: 0,
Checksum: "SHA-256:",
CachePath: "tools",
},
},
{
OS: "x86_64-pc-linux-gnu",
Resource: &resources.DownloadResource{
ArchiveFileName: fmt.Sprintf("mdns-discovery_v%s_Linux_64bit.tar.bz2", mdnsDiscoveryVersion),
URL: fmt.Sprintf("https://downloads.arduino.cc/discovery/mdns-discovery/mdns-discovery_v%s_Linux_64bit.tar.gz", mdnsDiscoveryVersion),
Size: 0,
Checksum: "SHA-256:",
CachePath: "tools",
},
},
{
OS: "i686-mingw32",
Resource: &resources.DownloadResource{
ArchiveFileName: fmt.Sprintf("mdns-discovery_v%s_Windows_32bit.zip", mdnsDiscoveryVersion),
URL: fmt.Sprintf("https://downloads.arduino.cc/discovery/mdns-discovery/mdns-discovery_v%s_Windows_32bit.zip", mdnsDiscoveryVersion),
Size: 0,
Checksum: "SHA-256:",
CachePath: "tools",
},
},
{
OS: "x86_64-mingw32",
Resource: &resources.DownloadResource{
ArchiveFileName: fmt.Sprintf("mdns-discovery_v%s_Windows_64bit.zip", mdnsDiscoveryVersion),
URL: fmt.Sprintf("https://downloads.arduino.cc/discovery/mdns-discovery/mdns-discovery_v%s_Windows_64bit.zip", mdnsDiscoveryVersion),
Size: 0,
Checksum: "SHA-256:",
CachePath: "tools",
},
},
{
OS: "x86_64-apple-darwin",
Resource: &resources.DownloadResource{
ArchiveFileName: fmt.Sprintf("mdns-discovery_v%s_macOS_64bit.tar.bz2", mdnsDiscoveryVersion),
URL: fmt.Sprintf("https://downloads.arduino.cc/discovery/mdns-discovery/mdns-discovery_v%s_macOS_64bit.tar.gz", mdnsDiscoveryVersion),
Size: 0,
Checksum: "SHA-256:",
CachePath: "tools",
},
},
{
OS: "arm-linux-gnueabihf",
Resource: &resources.DownloadResource{
ArchiveFileName: fmt.Sprintf("mdns-discovery_v%s_Linux_ARMv6.tar.bz2", mdnsDiscoveryVersion),
URL: fmt.Sprintf("https://downloads.arduino.cc/discovery/mdns-discovery/mdns-discovery_v%s_Linux_ARMv6.tar.gz", mdnsDiscoveryVersion),
Size: 0,
Checksum: "SHA-256:",
CachePath: "tools",
},
},
{
OS: "arm64-linux-gnueabihf",
Resource: &resources.DownloadResource{
ArchiveFileName: fmt.Sprintf("mdns-discovery_v%s_Linux_ARM64.tar.bz2", mdnsDiscoveryVersion),
URL: fmt.Sprintf("https://downloads.arduino.cc/discovery/mdns-discovery/mdns-discovery_v%s_Linux_ARM64.tar.gz", mdnsDiscoveryVersion),
Size: 0,
Checksum: "SHA-256:",
CachePath: "tools",
},
},
}
)

func getBuiltinMDNSDiscoveryTool(pm *packagemanager.PackageManager) *cores.ToolRelease {
builtinPackage := pm.Packages.GetOrCreatePackage("builtin")
mdnsDiscoveryTool := builtinPackage.GetOrCreateTool("mdns-discovery")
mdnsDiscoveryToolRel := mdnsDiscoveryTool.GetOrCreateRelease(mdnsDiscoveryVersion)
mdnsDiscoveryToolRel.Flavors = mdnsDiscoveryFlavors
return mdnsDiscoveryToolRel
}
13 changes: 12 additions & 1 deletion commands/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) *sta
instance.PackageManager.Clear()
ctagsTool := getBuiltinCtagsTool(instance.PackageManager)
serialDiscoveryTool := getBuiltinSerialDiscoveryTool(instance.PackageManager)
mdnsDiscoveryTool := getBuiltinMDNSDiscoveryTool(instance.PackageManager)

// Load Platforms
urls := []string{globals.DefaultIndexURL}
Expand Down Expand Up @@ -276,7 +277,17 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) *sta
})
}

if ctagsHasBeenInstalled || serialHasBeenInstalled {
mdnsHasBeenInstalled, err := instance.installToolIfMissing(mdnsDiscoveryTool, downloadCallback, taskCallback)
if err != nil {
s := status.Newf(codes.Internal, err.Error())
responseCallback(&rpc.InitResponse{
Message: &rpc.InitResponse_Error{
Error: s.Proto(),
},
})
}

if ctagsHasBeenInstalled || serialHasBeenInstalled || mdnsHasBeenInstalled {
// We installed at least one new tool after loading hardware
// so we must reload again otherwise we would never found them.
for _, err := range instance.PackageManager.LoadHardware() {
Expand Down

0 comments on commit 1ab82ed

Please sign in to comment.