Skip to content

legacy: some clean-ups of legacy code #2160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .licenses/go/golang.org/x/exp/constraints.dep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
name: golang.org/x/exp/constraints
version: v0.0.0-20230321023759-10a507213a29
type: go
summary: Package constraints defines a set of useful constraints to be used with type
parameters.
homepage: https://pkg.go.dev/golang.org/x/exp/constraints
license: bsd-3-clause
licenses:
- sources: [email protected]/LICENSE
text: |
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- sources: [email protected]/PATENTS
text: |
Additional IP Rights Grant (Patents)
"This implementation" means the copyrightable works distributed by
Google as part of the Go project.
Google hereby grants to You a perpetual, worldwide, non-exclusive,
no-charge, royalty-free, irrevocable (except as stated in this section)
patent license to make, have made, use, offer to sell, sell, import,
transfer and otherwise run, modify and propagate the contents of this
implementation of Go, where such license applies only to those patent
claims, both currently owned or controlled by Google and acquired in
the future, licensable by Google that are necessarily infringed by this
implementation of Go. This grant does not include claims that would be
infringed only as a consequence of further modification of this
implementation. If you or your agent or exclusive licensee institute or
order or agree to the institution of patent litigation against any
entity (including a cross-claim or counterclaim in a lawsuit) alleging
that this implementation of Go or any code incorporated within this
implementation of Go constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any patent
rights granted to you under this License for this implementation of Go
shall terminate as of the date such litigation is filed.
notices: []
62 changes: 62 additions & 0 deletions .licenses/go/golang.org/x/exp/slices.dep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
name: golang.org/x/exp/slices
version: v0.0.0-20230321023759-10a507213a29
type: go
summary: Package slices defines various functions useful with slices of any type.
homepage: https://pkg.go.dev/golang.org/x/exp/slices
license: bsd-3-clause
licenses:
- sources: [email protected]/LICENSE
text: |
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- sources: [email protected]/PATENTS
text: |
Additional IP Rights Grant (Patents)
"This implementation" means the copyrightable works distributed by
Google as part of the Go project.
Google hereby grants to You a perpetual, worldwide, non-exclusive,
no-charge, royalty-free, irrevocable (except as stated in this section)
patent license to make, have made, use, offer to sell, sell, import,
transfer and otherwise run, modify and propagate the contents of this
implementation of Go, where such license applies only to those patent
claims, both currently owned or controlled by Google and acquired in
the future, licensable by Google that are necessarily infringed by this
implementation of Go. This grant does not include claims that would be
infringed only as a consequence of further modification of this
implementation. If you or your agent or exclusive licensee institute or
order or agree to the institution of patent litigation against any
entity (including a cross-claim or counterclaim in a lawsuit) alleging
that this implementation of Go or any code incorporated within this
implementation of Go constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any patent
rights granted to you under this License for this implementation of Go
shall terminate as of the date such litigation is filed.
notices: []
5 changes: 3 additions & 2 deletions legacy/builder/create_cmake_rule.go
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ import (
"strings"

properties "github.com/arduino/go-properties-orderedmap"
"golang.org/x/exp/slices"

"github.com/arduino/arduino-cli/arduino/globals"
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
@@ -213,7 +214,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
lib := staticLib.Base()
lib = strings.TrimPrefix(lib, "lib")
lib = strings.TrimSuffix(lib, ".a")
if !utils.SliceContains(dynamicLibsFromGccMinusL, lib) {
if !slices.Contains(dynamicLibsFromGccMinusL, lib) {
linkGroup += " " + lib
cmakelist += "add_library (" + lib + " STATIC IMPORTED)\n"
location := strings.TrimPrefix(staticLib.String(), cmakeFolder.String())
@@ -268,7 +269,7 @@ func findUniqueFoldersRelative(slice []string, base string) string {
for _, element := range slice {
path := filepath.Dir(element)
path = strings.TrimPrefix(path, base+"/")
if !utils.SliceContains(out, path) {
if !slices.Contains(out, path) {
out = append(out, path)
}
}
6 changes: 3 additions & 3 deletions legacy/builder/test/helper_tools_downloader.go
Original file line number Diff line number Diff line change
@@ -29,10 +29,10 @@ import (

"github.com/arduino/arduino-cli/legacy/builder/constants"
"github.com/arduino/arduino-cli/legacy/builder/gohasissues"
"github.com/arduino/arduino-cli/legacy/builder/utils"
"github.com/arduino/go-paths-helper"
"github.com/arduino/go-properties-orderedmap"
"github.com/pkg/errors"
"golang.org/x/exp/slices"
)

var hardwareFolder = paths.New("downloaded_hardware")
@@ -692,7 +692,7 @@ func translateGOOSGOARCHToPackageIndexValue() []string {
func findToolUrl(index map[string]interface{}, tool Tool, host []string) (string, error) {
if len(tool.OsUrls) > 0 {
for _, osUrl := range tool.OsUrls {
if utils.SliceContains(host, osUrl.Os) {
if slices.Contains(host, osUrl.Os) {
return osUrl.Url, nil
}
}
@@ -709,7 +709,7 @@ func findToolUrl(index map[string]interface{}, tool Tool, host []string) (string
systems := packageTool["systems"].([]interface{})
for _, s := range systems {
system := s.(map[string]interface{})
if utils.SliceContains(host, system["host"].(string)) {
if slices.Contains(host, system["host"].(string)) {
return system[constants.TOOL_URL].(string), nil
}
}
34 changes: 0 additions & 34 deletions legacy/builder/test/unique_string_queue_test.go

This file was deleted.

62 changes: 5 additions & 57 deletions legacy/builder/types/accessories.go
Original file line number Diff line number Diff line change
@@ -15,33 +15,7 @@

package types

import (
"bytes"
"sync"
)

type UniqueStringQueue []string

func (queue UniqueStringQueue) Len() int { return len(queue) }
func (queue UniqueStringQueue) Less(i, j int) bool { return false }
func (queue UniqueStringQueue) Swap(i, j int) { panic("Who called me?!?") }

func (queue *UniqueStringQueue) Push(value string) {
if !sliceContains(*queue, value) {
*queue = append(*queue, value)
}
}

func (queue *UniqueStringQueue) Pop() interface{} {
old := *queue
x := old[0]
*queue = old[1:]
return x
}

func (queue *UniqueStringQueue) Empty() bool {
return queue.Len() == 0
}
import "golang.org/x/exp/slices"

type UniqueSourceFileQueue []SourceFile

@@ -50,7 +24,10 @@ func (queue UniqueSourceFileQueue) Less(i, j int) bool { return false }
func (queue UniqueSourceFileQueue) Swap(i, j int) { panic("Who called me?!?") }

func (queue *UniqueSourceFileQueue) Push(value SourceFile) {
if !sliceContainsSourceFile(*queue, value) {
equals := func(elem SourceFile) bool {
return elem.Origin == value.Origin && elem.RelativePath.EqualsTo(value.RelativePath)
}
if !slices.ContainsFunc(*queue, equals) {
*queue = append(*queue, value)
}
}
@@ -65,32 +42,3 @@ func (queue *UniqueSourceFileQueue) Pop() SourceFile {
func (queue *UniqueSourceFileQueue) Empty() bool {
return queue.Len() == 0
}

type BufferedUntilNewLineWriter struct {
PrintFunc PrintFunc
Buffer bytes.Buffer
lock sync.Mutex
}

type PrintFunc func([]byte)

func (w *BufferedUntilNewLineWriter) Write(p []byte) (n int, err error) {
w.lock.Lock()
defer w.lock.Unlock()

writtenToBuffer, err := w.Buffer.Write(p)
return writtenToBuffer, err
}

func (w *BufferedUntilNewLineWriter) Flush() {
w.lock.Lock()
defer w.lock.Unlock()

remainingBytes := w.Buffer.Bytes()
if len(remainingBytes) > 0 {
if remainingBytes[len(remainingBytes)-1] != '\n' {
remainingBytes = append(remainingBytes, '\n')
}
w.PrintFunc(remainingBytes)
}
}
32 changes: 0 additions & 32 deletions legacy/builder/types/types.go
Original file line number Diff line number Diff line change
@@ -85,38 +85,6 @@ func (f *SourceFile) DepfilePath(ctx *Context) *paths.Path {
return buildRoot(ctx, f.Origin).Join(f.RelativePath.String() + ".d")
}

type SketchFile struct {
Name *paths.Path
}

type SketchFileSortByName []SketchFile

func (s SketchFileSortByName) Len() int {
return len(s)
}

func (s SketchFileSortByName) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}

func (s SketchFileSortByName) Less(i, j int) bool {
return s[i].Name.String() < s[j].Name.String()
}

type PlatforKeysRewrite struct {
Rewrites []PlatforKeyRewrite
}

func (p *PlatforKeysRewrite) Empty() bool {
return len(p.Rewrites) == 0
}

type PlatforKeyRewrite struct {
Key string
OldValue string
NewValue string
}

type Prototype struct {
FunctionName string
File string
35 changes: 0 additions & 35 deletions legacy/builder/types/utils.go

This file was deleted.

4 changes: 2 additions & 2 deletions legacy/builder/unused_compiled_libraries_remover.go
Original file line number Diff line number Diff line change
@@ -18,8 +18,8 @@ package builder
import (
"github.com/arduino/arduino-cli/arduino/libraries"
"github.com/arduino/arduino-cli/legacy/builder/types"
"github.com/arduino/arduino-cli/legacy/builder/utils"
"github.com/pkg/errors"
"golang.org/x/exp/slices"
)

type UnusedCompiledLibrariesRemover struct{}
@@ -39,7 +39,7 @@ func (s *UnusedCompiledLibrariesRemover) Run(ctx *types.Context) error {
}
for _, file := range files {
if file.IsDir() {
if !utils.SliceContains(libraryNames, file.Base()) {
if !slices.Contains(libraryNames, file.Base()) {
if err := file.RemoveAll(); err != nil {
return errors.WithStack(err)
}
14 changes: 3 additions & 11 deletions legacy/builder/utils/utils.go
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ import (
"github.com/arduino/arduino-cli/legacy/builder/types"
paths "github.com/arduino/go-paths-helper"
"github.com/pkg/errors"
"golang.org/x/exp/slices"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
@@ -64,7 +65,7 @@ func FilterFilesWithExtensions(extensions ...string) filterFiles {
return func(files []os.FileInfo) []os.FileInfo {
var filtered []os.FileInfo
for _, file := range files {
if !file.IsDir() && SliceContains(extensions, filepath.Ext(file.Name())) {
if !file.IsDir() && slices.Contains(extensions, filepath.Ext(file.Name())) {
filtered = append(filtered, file)
}
}
@@ -119,15 +120,6 @@ func IsSCCSFile(file os.FileInfo) bool {
return SOURCE_CONTROL_FOLDERS[name]
}

func SliceContains(slice []string, target string) bool {
for _, value := range slice {
if value == target {
return true
}
}
return false
}

type mapFunc func(string) string

func Map(slice []string, fn mapFunc) []string {
@@ -263,7 +255,7 @@ func FindFilesInFolder(dir *paths.Path, recurse bool, extensions []string) (path

func AppendIfNotPresent(target []string, elements ...string) []string {
for _, element := range elements {
if !SliceContains(target, element) {
if !slices.Contains(target, element) {
target = append(target, element)
}
}