Skip to content

Commit 475d987

Browse files
authored
[skip-changelog] Cleaned-up some legacy code (#2160)
* Removed unused class * Replaced two accessory functions with stdlib functions * Removed unused structs * Replaced utils.SliceContains with stdlib function
1 parent 0b77c0a commit 475d987

10 files changed

+141
-176
lines changed

Diff for: .licenses/go/golang.org/x/exp/constraints.dep.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
name: golang.org/x/exp/constraints
3+
version: v0.0.0-20230321023759-10a507213a29
4+
type: go
5+
summary: Package constraints defines a set of useful constraints to be used with type
6+
parameters.
7+
homepage: https://pkg.go.dev/golang.org/x/exp/constraints
8+
license: bsd-3-clause
9+
licenses:
10+
- sources: [email protected]/LICENSE
11+
text: |
12+
Copyright (c) 2009 The Go Authors. All rights reserved.
13+
14+
Redistribution and use in source and binary forms, with or without
15+
modification, are permitted provided that the following conditions are
16+
met:
17+
18+
* Redistributions of source code must retain the above copyright
19+
notice, this list of conditions and the following disclaimer.
20+
* Redistributions in binary form must reproduce the above
21+
copyright notice, this list of conditions and the following disclaimer
22+
in the documentation and/or other materials provided with the
23+
distribution.
24+
* Neither the name of Google Inc. nor the names of its
25+
contributors may be used to endorse or promote products derived from
26+
this software without specific prior written permission.
27+
28+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39+
- sources: [email protected]/PATENTS
40+
text: |
41+
Additional IP Rights Grant (Patents)
42+
43+
"This implementation" means the copyrightable works distributed by
44+
Google as part of the Go project.
45+
46+
Google hereby grants to You a perpetual, worldwide, non-exclusive,
47+
no-charge, royalty-free, irrevocable (except as stated in this section)
48+
patent license to make, have made, use, offer to sell, sell, import,
49+
transfer and otherwise run, modify and propagate the contents of this
50+
implementation of Go, where such license applies only to those patent
51+
claims, both currently owned or controlled by Google and acquired in
52+
the future, licensable by Google that are necessarily infringed by this
53+
implementation of Go. This grant does not include claims that would be
54+
infringed only as a consequence of further modification of this
55+
implementation. If you or your agent or exclusive licensee institute or
56+
order or agree to the institution of patent litigation against any
57+
entity (including a cross-claim or counterclaim in a lawsuit) alleging
58+
that this implementation of Go or any code incorporated within this
59+
implementation of Go constitutes direct or contributory patent
60+
infringement, or inducement of patent infringement, then any patent
61+
rights granted to you under this License for this implementation of Go
62+
shall terminate as of the date such litigation is filed.
63+
notices: []

Diff for: .licenses/go/golang.org/x/exp/slices.dep.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
name: golang.org/x/exp/slices
3+
version: v0.0.0-20230321023759-10a507213a29
4+
type: go
5+
summary: Package slices defines various functions useful with slices of any type.
6+
homepage: https://pkg.go.dev/golang.org/x/exp/slices
7+
license: bsd-3-clause
8+
licenses:
9+
- sources: [email protected]/LICENSE
10+
text: |
11+
Copyright (c) 2009 The Go Authors. All rights reserved.
12+
13+
Redistribution and use in source and binary forms, with or without
14+
modification, are permitted provided that the following conditions are
15+
met:
16+
17+
* Redistributions of source code must retain the above copyright
18+
notice, this list of conditions and the following disclaimer.
19+
* Redistributions in binary form must reproduce the above
20+
copyright notice, this list of conditions and the following disclaimer
21+
in the documentation and/or other materials provided with the
22+
distribution.
23+
* Neither the name of Google Inc. nor the names of its
24+
contributors may be used to endorse or promote products derived from
25+
this software without specific prior written permission.
26+
27+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38+
- sources: [email protected]/PATENTS
39+
text: |
40+
Additional IP Rights Grant (Patents)
41+
42+
"This implementation" means the copyrightable works distributed by
43+
Google as part of the Go project.
44+
45+
Google hereby grants to You a perpetual, worldwide, non-exclusive,
46+
no-charge, royalty-free, irrevocable (except as stated in this section)
47+
patent license to make, have made, use, offer to sell, sell, import,
48+
transfer and otherwise run, modify and propagate the contents of this
49+
implementation of Go, where such license applies only to those patent
50+
claims, both currently owned or controlled by Google and acquired in
51+
the future, licensable by Google that are necessarily infringed by this
52+
implementation of Go. This grant does not include claims that would be
53+
infringed only as a consequence of further modification of this
54+
implementation. If you or your agent or exclusive licensee institute or
55+
order or agree to the institution of patent litigation against any
56+
entity (including a cross-claim or counterclaim in a lawsuit) alleging
57+
that this implementation of Go or any code incorporated within this
58+
implementation of Go constitutes direct or contributory patent
59+
infringement, or inducement of patent infringement, then any patent
60+
rights granted to you under this License for this implementation of Go
61+
shall terminate as of the date such litigation is filed.
62+
notices: []

Diff for: legacy/builder/create_cmake_rule.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strings"
2323

2424
properties "github.com/arduino/go-properties-orderedmap"
25+
"golang.org/x/exp/slices"
2526

2627
"github.com/arduino/arduino-cli/arduino/globals"
2728
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
@@ -213,7 +214,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
213214
lib := staticLib.Base()
214215
lib = strings.TrimPrefix(lib, "lib")
215216
lib = strings.TrimSuffix(lib, ".a")
216-
if !utils.SliceContains(dynamicLibsFromGccMinusL, lib) {
217+
if !slices.Contains(dynamicLibsFromGccMinusL, lib) {
217218
linkGroup += " " + lib
218219
cmakelist += "add_library (" + lib + " STATIC IMPORTED)\n"
219220
location := strings.TrimPrefix(staticLib.String(), cmakeFolder.String())
@@ -268,7 +269,7 @@ func findUniqueFoldersRelative(slice []string, base string) string {
268269
for _, element := range slice {
269270
path := filepath.Dir(element)
270271
path = strings.TrimPrefix(path, base+"/")
271-
if !utils.SliceContains(out, path) {
272+
if !slices.Contains(out, path) {
272273
out = append(out, path)
273274
}
274275
}

Diff for: legacy/builder/test/helper_tools_downloader.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ import (
2929

3030
"github.com/arduino/arduino-cli/legacy/builder/constants"
3131
"github.com/arduino/arduino-cli/legacy/builder/gohasissues"
32-
"github.com/arduino/arduino-cli/legacy/builder/utils"
3332
"github.com/arduino/go-paths-helper"
3433
"github.com/arduino/go-properties-orderedmap"
3534
"github.com/pkg/errors"
35+
"golang.org/x/exp/slices"
3636
)
3737

3838
var hardwareFolder = paths.New("downloaded_hardware")
@@ -692,7 +692,7 @@ func translateGOOSGOARCHToPackageIndexValue() []string {
692692
func findToolUrl(index map[string]interface{}, tool Tool, host []string) (string, error) {
693693
if len(tool.OsUrls) > 0 {
694694
for _, osUrl := range tool.OsUrls {
695-
if utils.SliceContains(host, osUrl.Os) {
695+
if slices.Contains(host, osUrl.Os) {
696696
return osUrl.Url, nil
697697
}
698698
}
@@ -709,7 +709,7 @@ func findToolUrl(index map[string]interface{}, tool Tool, host []string) (string
709709
systems := packageTool["systems"].([]interface{})
710710
for _, s := range systems {
711711
system := s.(map[string]interface{})
712-
if utils.SliceContains(host, system["host"].(string)) {
712+
if slices.Contains(host, system["host"].(string)) {
713713
return system[constants.TOOL_URL].(string), nil
714714
}
715715
}

Diff for: legacy/builder/test/unique_string_queue_test.go

-34
This file was deleted.

Diff for: legacy/builder/types/accessories.go

+5-57
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,7 @@
1515

1616
package types
1717

18-
import (
19-
"bytes"
20-
"sync"
21-
)
22-
23-
type UniqueStringQueue []string
24-
25-
func (queue UniqueStringQueue) Len() int { return len(queue) }
26-
func (queue UniqueStringQueue) Less(i, j int) bool { return false }
27-
func (queue UniqueStringQueue) Swap(i, j int) { panic("Who called me?!?") }
28-
29-
func (queue *UniqueStringQueue) Push(value string) {
30-
if !sliceContains(*queue, value) {
31-
*queue = append(*queue, value)
32-
}
33-
}
34-
35-
func (queue *UniqueStringQueue) Pop() interface{} {
36-
old := *queue
37-
x := old[0]
38-
*queue = old[1:]
39-
return x
40-
}
41-
42-
func (queue *UniqueStringQueue) Empty() bool {
43-
return queue.Len() == 0
44-
}
18+
import "golang.org/x/exp/slices"
4519

4620
type UniqueSourceFileQueue []SourceFile
4721

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

5226
func (queue *UniqueSourceFileQueue) Push(value SourceFile) {
53-
if !sliceContainsSourceFile(*queue, value) {
27+
equals := func(elem SourceFile) bool {
28+
return elem.Origin == value.Origin && elem.RelativePath.EqualsTo(value.RelativePath)
29+
}
30+
if !slices.ContainsFunc(*queue, equals) {
5431
*queue = append(*queue, value)
5532
}
5633
}
@@ -65,32 +42,3 @@ func (queue *UniqueSourceFileQueue) Pop() SourceFile {
6542
func (queue *UniqueSourceFileQueue) Empty() bool {
6643
return queue.Len() == 0
6744
}
68-
69-
type BufferedUntilNewLineWriter struct {
70-
PrintFunc PrintFunc
71-
Buffer bytes.Buffer
72-
lock sync.Mutex
73-
}
74-
75-
type PrintFunc func([]byte)
76-
77-
func (w *BufferedUntilNewLineWriter) Write(p []byte) (n int, err error) {
78-
w.lock.Lock()
79-
defer w.lock.Unlock()
80-
81-
writtenToBuffer, err := w.Buffer.Write(p)
82-
return writtenToBuffer, err
83-
}
84-
85-
func (w *BufferedUntilNewLineWriter) Flush() {
86-
w.lock.Lock()
87-
defer w.lock.Unlock()
88-
89-
remainingBytes := w.Buffer.Bytes()
90-
if len(remainingBytes) > 0 {
91-
if remainingBytes[len(remainingBytes)-1] != '\n' {
92-
remainingBytes = append(remainingBytes, '\n')
93-
}
94-
w.PrintFunc(remainingBytes)
95-
}
96-
}

Diff for: legacy/builder/types/types.go

-32
Original file line numberDiff line numberDiff line change
@@ -85,38 +85,6 @@ func (f *SourceFile) DepfilePath(ctx *Context) *paths.Path {
8585
return buildRoot(ctx, f.Origin).Join(f.RelativePath.String() + ".d")
8686
}
8787

88-
type SketchFile struct {
89-
Name *paths.Path
90-
}
91-
92-
type SketchFileSortByName []SketchFile
93-
94-
func (s SketchFileSortByName) Len() int {
95-
return len(s)
96-
}
97-
98-
func (s SketchFileSortByName) Swap(i, j int) {
99-
s[i], s[j] = s[j], s[i]
100-
}
101-
102-
func (s SketchFileSortByName) Less(i, j int) bool {
103-
return s[i].Name.String() < s[j].Name.String()
104-
}
105-
106-
type PlatforKeysRewrite struct {
107-
Rewrites []PlatforKeyRewrite
108-
}
109-
110-
func (p *PlatforKeysRewrite) Empty() bool {
111-
return len(p.Rewrites) == 0
112-
}
113-
114-
type PlatforKeyRewrite struct {
115-
Key string
116-
OldValue string
117-
NewValue string
118-
}
119-
12088
type Prototype struct {
12189
FunctionName string
12290
File string

Diff for: legacy/builder/types/utils.go

-35
This file was deleted.

Diff for: legacy/builder/unused_compiled_libraries_remover.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ package builder
1818
import (
1919
"github.com/arduino/arduino-cli/arduino/libraries"
2020
"github.com/arduino/arduino-cli/legacy/builder/types"
21-
"github.com/arduino/arduino-cli/legacy/builder/utils"
2221
"github.com/pkg/errors"
22+
"golang.org/x/exp/slices"
2323
)
2424

2525
type UnusedCompiledLibrariesRemover struct{}
@@ -39,7 +39,7 @@ func (s *UnusedCompiledLibrariesRemover) Run(ctx *types.Context) error {
3939
}
4040
for _, file := range files {
4141
if file.IsDir() {
42-
if !utils.SliceContains(libraryNames, file.Base()) {
42+
if !slices.Contains(libraryNames, file.Base()) {
4343
if err := file.RemoveAll(); err != nil {
4444
return errors.WithStack(err)
4545
}

0 commit comments

Comments
 (0)