From 2d38899f3461ff6751f2662a2ad19075c78dc514 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 2 Nov 2024 19:34:04 +0100 Subject: [PATCH 1/4] chore: split internal code and code from Go --- .golangci.yml | 6 +---- internal/{cache => go}/LICENSE | 0 internal/{ => go}/cache/cache.go | 4 +-- internal/{ => go}/cache/cache_gcil.go | 0 internal/{ => go}/cache/cache_test.go | 2 +- internal/{ => go}/cache/default.go | 0 internal/{ => go}/cache/default_gcil.go | 0 internal/{ => go}/cache/hash.go | 0 internal/{ => go}/cache/hash_gcil.go | 0 internal/{ => go}/cache/hash_test.go | 0 internal/{ => go}/cache/prog.go | 2 +- internal/{ => go}/cache/readme.md | 0 internal/{ => go}/mmap/mmap.go | 0 internal/{ => go}/mmap/mmap_other.go | 0 internal/{ => go}/mmap/mmap_unix.go | 0 internal/{ => go}/mmap/mmap_windows.go | 0 internal/{ => go}/mmap/readme.md | 0 internal/{ => go}/quoted/quoted.go | 0 internal/{ => go}/quoted/quoted_test.go | 0 internal/{ => go}/quoted/readme.md | 0 internal/{ => go}/robustio/readme.md | 0 internal/{ => go}/robustio/robustio.go | 0 internal/{ => go}/robustio/robustio_darwin.go | 0 internal/{ => go}/robustio/robustio_flaky.go | 0 internal/{ => go}/robustio/robustio_other.go | 0 .../{ => go}/robustio/robustio_windows.go | 0 internal/{ => go}/testenv/readme.md | 0 internal/{ => go}/testenv/testenv.go | 0 internal/{ => go}/testenv/testenv_notunix.go | 0 internal/{ => go}/testenv/testenv_notwin.go | 0 internal/{ => go}/testenv/testenv_unix.go | 0 internal/{ => go}/testenv/testenv_windows.go | 0 internal/mmap/LICENSE | 27 ------------------- internal/pkgcache/pkgcache.go | 2 +- internal/quoted/LICENSE | 27 ------------------- internal/robustio/LICENSE | 27 ------------------- internal/testenv/LICENSE | 27 ------------------- pkg/commands/cache.go | 2 +- pkg/commands/run.go | 2 +- pkg/result/processors/fixer.go | 2 +- 40 files changed, 9 insertions(+), 121 deletions(-) rename internal/{cache => go}/LICENSE (100%) rename internal/{ => go}/cache/cache.go (99%) rename internal/{ => go}/cache/cache_gcil.go (100%) rename internal/{ => go}/cache/cache_test.go (99%) rename internal/{ => go}/cache/default.go (100%) rename internal/{ => go}/cache/default_gcil.go (100%) rename internal/{ => go}/cache/hash.go (100%) rename internal/{ => go}/cache/hash_gcil.go (100%) rename internal/{ => go}/cache/hash_test.go (100%) rename internal/{ => go}/cache/prog.go (99%) rename internal/{ => go}/cache/readme.md (100%) rename internal/{ => go}/mmap/mmap.go (100%) rename internal/{ => go}/mmap/mmap_other.go (100%) rename internal/{ => go}/mmap/mmap_unix.go (100%) rename internal/{ => go}/mmap/mmap_windows.go (100%) rename internal/{ => go}/mmap/readme.md (100%) rename internal/{ => go}/quoted/quoted.go (100%) rename internal/{ => go}/quoted/quoted_test.go (100%) rename internal/{ => go}/quoted/readme.md (100%) rename internal/{ => go}/robustio/readme.md (100%) rename internal/{ => go}/robustio/robustio.go (100%) rename internal/{ => go}/robustio/robustio_darwin.go (100%) rename internal/{ => go}/robustio/robustio_flaky.go (100%) rename internal/{ => go}/robustio/robustio_other.go (100%) rename internal/{ => go}/robustio/robustio_windows.go (100%) rename internal/{ => go}/testenv/readme.md (100%) rename internal/{ => go}/testenv/testenv.go (100%) rename internal/{ => go}/testenv/testenv_notunix.go (100%) rename internal/{ => go}/testenv/testenv_notwin.go (100%) rename internal/{ => go}/testenv/testenv_unix.go (100%) rename internal/{ => go}/testenv/testenv_windows.go (100%) delete mode 100644 internal/mmap/LICENSE delete mode 100644 internal/quoted/LICENSE delete mode 100644 internal/robustio/LICENSE delete mode 100644 internal/testenv/LICENSE diff --git a/.golangci.yml b/.golangci.yml index f9a821f6b31e..1d083481f909 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -221,11 +221,7 @@ issues: exclude-dirs: - test/testdata_etc # test files - - internal/cache # extracted from Go code - - internal/robustio # extracted from Go code - - internal/mmap # extracted from Go code - - internal/quoted # extracted from Go code - - internal/testenv # extracted from Go code + - internal/go # extracted from Go code run: timeout: 5m diff --git a/internal/cache/LICENSE b/internal/go/LICENSE similarity index 100% rename from internal/cache/LICENSE rename to internal/go/LICENSE diff --git a/internal/cache/cache.go b/internal/go/cache/cache.go similarity index 99% rename from internal/cache/cache.go rename to internal/go/cache/cache.go index a59813236a3e..7bf4f1d660e5 100644 --- a/internal/cache/cache.go +++ b/internal/go/cache/cache.go @@ -22,8 +22,8 @@ import ( "strings" "time" - "github.com/golangci/golangci-lint/internal/mmap" - "github.com/golangci/golangci-lint/internal/robustio" + "github.com/golangci/golangci-lint/internal/go/mmap" + "github.com/golangci/golangci-lint/internal/go/robustio" "github.com/rogpeppe/go-internal/lockedfile" ) diff --git a/internal/cache/cache_gcil.go b/internal/go/cache/cache_gcil.go similarity index 100% rename from internal/cache/cache_gcil.go rename to internal/go/cache/cache_gcil.go diff --git a/internal/cache/cache_test.go b/internal/go/cache/cache_test.go similarity index 99% rename from internal/cache/cache_test.go rename to internal/go/cache/cache_test.go index b201cc675051..208abcedc923 100644 --- a/internal/cache/cache_test.go +++ b/internal/go/cache/cache_test.go @@ -13,7 +13,7 @@ import ( "testing" "time" - "github.com/golangci/golangci-lint/internal/testenv" + "github.com/golangci/golangci-lint/internal/go/testenv" ) func init() { diff --git a/internal/cache/default.go b/internal/go/cache/default.go similarity index 100% rename from internal/cache/default.go rename to internal/go/cache/default.go diff --git a/internal/cache/default_gcil.go b/internal/go/cache/default_gcil.go similarity index 100% rename from internal/cache/default_gcil.go rename to internal/go/cache/default_gcil.go diff --git a/internal/cache/hash.go b/internal/go/cache/hash.go similarity index 100% rename from internal/cache/hash.go rename to internal/go/cache/hash.go diff --git a/internal/cache/hash_gcil.go b/internal/go/cache/hash_gcil.go similarity index 100% rename from internal/cache/hash_gcil.go rename to internal/go/cache/hash_gcil.go diff --git a/internal/cache/hash_test.go b/internal/go/cache/hash_test.go similarity index 100% rename from internal/cache/hash_test.go rename to internal/go/cache/hash_test.go diff --git a/internal/cache/prog.go b/internal/go/cache/prog.go similarity index 99% rename from internal/cache/prog.go rename to internal/go/cache/prog.go index 91ef831755a4..a93740a3cf5d 100644 --- a/internal/cache/prog.go +++ b/internal/go/cache/prog.go @@ -21,7 +21,7 @@ import ( "sync/atomic" "time" - "github.com/golangci/golangci-lint/internal/quoted" + "github.com/golangci/golangci-lint/internal/go/quoted" ) // ProgCache implements Cache via JSON messages over stdin/stdout to a child diff --git a/internal/cache/readme.md b/internal/go/cache/readme.md similarity index 100% rename from internal/cache/readme.md rename to internal/go/cache/readme.md diff --git a/internal/mmap/mmap.go b/internal/go/mmap/mmap.go similarity index 100% rename from internal/mmap/mmap.go rename to internal/go/mmap/mmap.go diff --git a/internal/mmap/mmap_other.go b/internal/go/mmap/mmap_other.go similarity index 100% rename from internal/mmap/mmap_other.go rename to internal/go/mmap/mmap_other.go diff --git a/internal/mmap/mmap_unix.go b/internal/go/mmap/mmap_unix.go similarity index 100% rename from internal/mmap/mmap_unix.go rename to internal/go/mmap/mmap_unix.go diff --git a/internal/mmap/mmap_windows.go b/internal/go/mmap/mmap_windows.go similarity index 100% rename from internal/mmap/mmap_windows.go rename to internal/go/mmap/mmap_windows.go diff --git a/internal/mmap/readme.md b/internal/go/mmap/readme.md similarity index 100% rename from internal/mmap/readme.md rename to internal/go/mmap/readme.md diff --git a/internal/quoted/quoted.go b/internal/go/quoted/quoted.go similarity index 100% rename from internal/quoted/quoted.go rename to internal/go/quoted/quoted.go diff --git a/internal/quoted/quoted_test.go b/internal/go/quoted/quoted_test.go similarity index 100% rename from internal/quoted/quoted_test.go rename to internal/go/quoted/quoted_test.go diff --git a/internal/quoted/readme.md b/internal/go/quoted/readme.md similarity index 100% rename from internal/quoted/readme.md rename to internal/go/quoted/readme.md diff --git a/internal/robustio/readme.md b/internal/go/robustio/readme.md similarity index 100% rename from internal/robustio/readme.md rename to internal/go/robustio/readme.md diff --git a/internal/robustio/robustio.go b/internal/go/robustio/robustio.go similarity index 100% rename from internal/robustio/robustio.go rename to internal/go/robustio/robustio.go diff --git a/internal/robustio/robustio_darwin.go b/internal/go/robustio/robustio_darwin.go similarity index 100% rename from internal/robustio/robustio_darwin.go rename to internal/go/robustio/robustio_darwin.go diff --git a/internal/robustio/robustio_flaky.go b/internal/go/robustio/robustio_flaky.go similarity index 100% rename from internal/robustio/robustio_flaky.go rename to internal/go/robustio/robustio_flaky.go diff --git a/internal/robustio/robustio_other.go b/internal/go/robustio/robustio_other.go similarity index 100% rename from internal/robustio/robustio_other.go rename to internal/go/robustio/robustio_other.go diff --git a/internal/robustio/robustio_windows.go b/internal/go/robustio/robustio_windows.go similarity index 100% rename from internal/robustio/robustio_windows.go rename to internal/go/robustio/robustio_windows.go diff --git a/internal/testenv/readme.md b/internal/go/testenv/readme.md similarity index 100% rename from internal/testenv/readme.md rename to internal/go/testenv/readme.md diff --git a/internal/testenv/testenv.go b/internal/go/testenv/testenv.go similarity index 100% rename from internal/testenv/testenv.go rename to internal/go/testenv/testenv.go diff --git a/internal/testenv/testenv_notunix.go b/internal/go/testenv/testenv_notunix.go similarity index 100% rename from internal/testenv/testenv_notunix.go rename to internal/go/testenv/testenv_notunix.go diff --git a/internal/testenv/testenv_notwin.go b/internal/go/testenv/testenv_notwin.go similarity index 100% rename from internal/testenv/testenv_notwin.go rename to internal/go/testenv/testenv_notwin.go diff --git a/internal/testenv/testenv_unix.go b/internal/go/testenv/testenv_unix.go similarity index 100% rename from internal/testenv/testenv_unix.go rename to internal/go/testenv/testenv_unix.go diff --git a/internal/testenv/testenv_windows.go b/internal/go/testenv/testenv_windows.go similarity index 100% rename from internal/testenv/testenv_windows.go rename to internal/go/testenv/testenv_windows.go diff --git a/internal/mmap/LICENSE b/internal/mmap/LICENSE deleted file mode 100644 index 6a66aea5eafe..000000000000 --- a/internal/mmap/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -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. diff --git a/internal/pkgcache/pkgcache.go b/internal/pkgcache/pkgcache.go index 4a66ce5a8387..8b47d21bedc8 100644 --- a/internal/pkgcache/pkgcache.go +++ b/internal/pkgcache/pkgcache.go @@ -12,7 +12,7 @@ import ( "golang.org/x/tools/go/packages" - "github.com/golangci/golangci-lint/internal/cache" + "github.com/golangci/golangci-lint/internal/go/cache" "github.com/golangci/golangci-lint/pkg/logutils" "github.com/golangci/golangci-lint/pkg/timeutils" ) diff --git a/internal/quoted/LICENSE b/internal/quoted/LICENSE deleted file mode 100644 index 6a66aea5eafe..000000000000 --- a/internal/quoted/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -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. diff --git a/internal/robustio/LICENSE b/internal/robustio/LICENSE deleted file mode 100644 index 6a66aea5eafe..000000000000 --- a/internal/robustio/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -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. diff --git a/internal/testenv/LICENSE b/internal/testenv/LICENSE deleted file mode 100644 index 6a66aea5eafe..000000000000 --- a/internal/testenv/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -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. diff --git a/pkg/commands/cache.go b/pkg/commands/cache.go index 0af8cc2856e5..1f5164570ded 100644 --- a/pkg/commands/cache.go +++ b/pkg/commands/cache.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/cobra" - "github.com/golangci/golangci-lint/internal/cache" + "github.com/golangci/golangci-lint/internal/go/cache" "github.com/golangci/golangci-lint/pkg/fsutils" "github.com/golangci/golangci-lint/pkg/logutils" ) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index f289bfdd79d5..b9cdd407c3ea 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -27,7 +27,7 @@ import ( "golang.org/x/exp/maps" "gopkg.in/yaml.v3" - "github.com/golangci/golangci-lint/internal/cache" + "github.com/golangci/golangci-lint/internal/go/cache" "github.com/golangci/golangci-lint/internal/pkgcache" "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/exitcodes" diff --git a/pkg/result/processors/fixer.go b/pkg/result/processors/fixer.go index 4915dc479a45..cc99e6940ef8 100644 --- a/pkg/result/processors/fixer.go +++ b/pkg/result/processors/fixer.go @@ -8,7 +8,7 @@ import ( "sort" "strings" - "github.com/golangci/golangci-lint/internal/robustio" + "github.com/golangci/golangci-lint/internal/go/robustio" "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/fsutils" "github.com/golangci/golangci-lint/pkg/logutils" From ac5265aebf3bd4a43a70375f8ef530ee5e8db3c3 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 2 Nov 2024 21:07:34 +0100 Subject: [PATCH 2/4] chore: cut dependencies to internal/go/cache --- internal/pkgcache/pkgcache.go | 9 +++++++++ pkg/commands/cache.go | 6 +++--- pkg/commands/run.go | 3 +-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/pkgcache/pkgcache.go b/internal/pkgcache/pkgcache.go index 8b47d21bedc8..d630404f8158 100644 --- a/internal/pkgcache/pkgcache.go +++ b/internal/pkgcache/pkgcache.go @@ -226,3 +226,12 @@ func (c *Cache) packageHash(pkg *packages.Package, mode HashMode) (string, error c.pkgHashes.Store(pkg, hashRes) return hashRes[mode], nil } + +func SetSalt(b *bytes.Buffer) { + cache.SetSalt(b.Bytes()) +} + +func DefaultDir() string { + cacheDir, _ := cache.DefaultDir() + return cacheDir +} diff --git a/pkg/commands/cache.go b/pkg/commands/cache.go index 1f5164570ded..c349c140b30d 100644 --- a/pkg/commands/cache.go +++ b/pkg/commands/cache.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/cobra" - "github.com/golangci/golangci-lint/internal/go/cache" + "github.com/golangci/golangci-lint/internal/pkgcache" "github.com/golangci/golangci-lint/pkg/fsutils" "github.com/golangci/golangci-lint/pkg/logutils" ) @@ -51,7 +51,7 @@ func newCacheCommand() *cacheCommand { } func (*cacheCommand) executeClean(_ *cobra.Command, _ []string) error { - cacheDir, _ := cache.DefaultDir() + cacheDir := pkgcache.DefaultDir() if err := os.RemoveAll(cacheDir); err != nil { return fmt.Errorf("failed to remove dir %s: %w", cacheDir, err) @@ -61,7 +61,7 @@ func (*cacheCommand) executeClean(_ *cobra.Command, _ []string) error { } func (*cacheCommand) executeStatus(_ *cobra.Command, _ []string) { - cacheDir, _ := cache.DefaultDir() + cacheDir := pkgcache.DefaultDir() _, _ = fmt.Fprintf(logutils.StdOut, "Dir: %s\n", cacheDir) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index b9cdd407c3ea..924c887b973e 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -27,7 +27,6 @@ import ( "golang.org/x/exp/maps" "gopkg.in/yaml.v3" - "github.com/golangci/golangci-lint/internal/go/cache" "github.com/golangci/golangci-lint/internal/pkgcache" "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/exitcodes" @@ -640,7 +639,7 @@ func initHashSalt(version string, cfg *config.Config) error { b := bytes.NewBuffer(binSalt) b.Write(configSalt) - cache.SetSalt(b.Bytes()) + pkgcache.SetSalt(b) return nil } From 569d5d79214ecef5a419daa6274bfcf5105d1e08 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 2 Nov 2024 21:09:49 +0100 Subject: [PATCH 3/4] chore: rename pkcache to cache --- internal/{pkgcache/pkgcache.go => cache/cache.go} | 2 +- pkg/commands/cache.go | 6 +++--- pkg/commands/run.go | 6 +++--- pkg/goanalysis/runner.go | 6 +++--- pkg/goanalysis/runner_action.go | 8 ++++---- pkg/goanalysis/runners.go | 6 +++--- pkg/lint/context.go | 6 +++--- pkg/lint/linter/context.go | 4 ++-- 8 files changed, 22 insertions(+), 22 deletions(-) rename internal/{pkgcache/pkgcache.go => cache/cache.go} (99%) diff --git a/internal/pkgcache/pkgcache.go b/internal/cache/cache.go similarity index 99% rename from internal/pkgcache/pkgcache.go rename to internal/cache/cache.go index d630404f8158..ed52fcf4ac43 100644 --- a/internal/pkgcache/pkgcache.go +++ b/internal/cache/cache.go @@ -1,4 +1,4 @@ -package pkgcache +package cache import ( "bytes" diff --git a/pkg/commands/cache.go b/pkg/commands/cache.go index c349c140b30d..4f2c812dce91 100644 --- a/pkg/commands/cache.go +++ b/pkg/commands/cache.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/cobra" - "github.com/golangci/golangci-lint/internal/pkgcache" + "github.com/golangci/golangci-lint/internal/cache" "github.com/golangci/golangci-lint/pkg/fsutils" "github.com/golangci/golangci-lint/pkg/logutils" ) @@ -51,7 +51,7 @@ func newCacheCommand() *cacheCommand { } func (*cacheCommand) executeClean(_ *cobra.Command, _ []string) error { - cacheDir := pkgcache.DefaultDir() + cacheDir := cache.DefaultDir() if err := os.RemoveAll(cacheDir); err != nil { return fmt.Errorf("failed to remove dir %s: %w", cacheDir, err) @@ -61,7 +61,7 @@ func (*cacheCommand) executeClean(_ *cobra.Command, _ []string) error { } func (*cacheCommand) executeStatus(_ *cobra.Command, _ []string) { - cacheDir := pkgcache.DefaultDir() + cacheDir := cache.DefaultDir() _, _ = fmt.Fprintf(logutils.StdOut, "Dir: %s\n", cacheDir) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 924c887b973e..ff7c5e467b67 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -27,7 +27,7 @@ import ( "golang.org/x/exp/maps" "gopkg.in/yaml.v3" - "github.com/golangci/golangci-lint/internal/pkgcache" + "github.com/golangci/golangci-lint/internal/cache" "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/exitcodes" "github.com/golangci/golangci-lint/pkg/fsutils" @@ -208,7 +208,7 @@ func (c *runCommand) preRunE(_ *cobra.Command, args []string) error { sw := timeutils.NewStopwatch("pkgcache", c.log.Child(logutils.DebugKeyStopwatch)) - pkgCache, err := pkgcache.NewCache(sw, c.log.Child(logutils.DebugKeyPkgCache)) + pkgCache, err := cache.NewCache(sw, c.log.Child(logutils.DebugKeyPkgCache)) if err != nil { return fmt.Errorf("failed to build packages cache: %w", err) } @@ -639,7 +639,7 @@ func initHashSalt(version string, cfg *config.Config) error { b := bytes.NewBuffer(binSalt) b.Write(configSalt) - pkgcache.SetSalt(b) + cache.SetSalt(b) return nil } diff --git a/pkg/goanalysis/runner.go b/pkg/goanalysis/runner.go index 806aac81064c..dfcdcbaaa4d5 100644 --- a/pkg/goanalysis/runner.go +++ b/pkg/goanalysis/runner.go @@ -21,8 +21,8 @@ import ( "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/packages" + "github.com/golangci/golangci-lint/internal/cache" "github.com/golangci/golangci-lint/internal/errorutil" - "github.com/golangci/golangci-lint/internal/pkgcache" "github.com/golangci/golangci-lint/pkg/goanalysis/load" "github.com/golangci/golangci-lint/pkg/logutils" "github.com/golangci/golangci-lint/pkg/timeutils" @@ -52,7 +52,7 @@ type Diagnostic struct { type runner struct { log logutils.Log prefix string // ensure unique analyzer names - pkgCache *pkgcache.Cache + pkgCache *cache.Cache loadGuard *load.Guard loadMode LoadMode passToPkg map[*analysis.Pass]*packages.Package @@ -60,7 +60,7 @@ type runner struct { sw *timeutils.Stopwatch } -func newRunner(prefix string, logger logutils.Log, pkgCache *pkgcache.Cache, loadGuard *load.Guard, +func newRunner(prefix string, logger logutils.Log, pkgCache *cache.Cache, loadGuard *load.Guard, loadMode LoadMode, sw *timeutils.Stopwatch, ) *runner { return &runner{ diff --git a/pkg/goanalysis/runner_action.go b/pkg/goanalysis/runner_action.go index 58ea297ea92b..81e2556b39f9 100644 --- a/pkg/goanalysis/runner_action.go +++ b/pkg/goanalysis/runner_action.go @@ -13,8 +13,8 @@ import ( "golang.org/x/tools/go/packages" "golang.org/x/tools/go/types/objectpath" + "github.com/golangci/golangci-lint/internal/cache" "github.com/golangci/golangci-lint/internal/errorutil" - "github.com/golangci/golangci-lint/internal/pkgcache" "github.com/golangci/golangci-lint/pkg/goanalysis/pkgerrors" ) @@ -328,14 +328,14 @@ func (act *action) persistFactsToCache() error { factsCacheDebugf("Caching %d facts for package %q and analyzer %s", len(facts), act.pkg.Name, act.a.Name) key := fmt.Sprintf("%s/facts", analyzer.Name) - return act.r.pkgCache.Put(act.pkg, pkgcache.HashModeNeedAllDeps, key, facts) + return act.r.pkgCache.Put(act.pkg, cache.HashModeNeedAllDeps, key, facts) } func (act *action) loadPersistedFacts() bool { var facts []Fact key := fmt.Sprintf("%s/facts", act.a.Name) - if err := act.r.pkgCache.Get(act.pkg, pkgcache.HashModeNeedAllDeps, key, &facts); err != nil { - if !errors.Is(err, pkgcache.ErrMissing) && !errors.Is(err, io.EOF) { + if err := act.r.pkgCache.Get(act.pkg, cache.HashModeNeedAllDeps, key, &facts); err != nil { + if !errors.Is(err, cache.ErrMissing) && !errors.Is(err, io.EOF) { act.r.log.Warnf("Failed to get persisted facts: %s", err) } diff --git a/pkg/goanalysis/runners.go b/pkg/goanalysis/runners.go index 698439f08196..033cba81d5de 100644 --- a/pkg/goanalysis/runners.go +++ b/pkg/goanalysis/runners.go @@ -12,7 +12,7 @@ import ( "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/packages" - "github.com/golangci/golangci-lint/internal/pkgcache" + "github.com/golangci/golangci-lint/internal/cache" "github.com/golangci/golangci-lint/pkg/goanalysis/pkgerrors" "github.com/golangci/golangci-lint/pkg/lint/linter" "github.com/golangci/golangci-lint/pkg/logutils" @@ -163,7 +163,7 @@ func saveIssuesToCache(allPkgs []*packages.Package, pkgsFromCache map[*packages. } atomic.AddInt64(&savedIssuesCount, int64(len(encodedIssues))) - if err := lintCtx.PkgCache.Put(pkg, pkgcache.HashModeNeedAllDeps, lintResKey, encodedIssues); err != nil { + if err := lintCtx.PkgCache.Put(pkg, cache.HashModeNeedAllDeps, lintResKey, encodedIssues); err != nil { lintCtx.Log.Infof("Failed to save package %s issues (%d) to cache: %s", pkg, len(pkgIssues), err) } else { issuesCacheDebugf("Saved package %s issues (%d) to cache", pkg, len(pkgIssues)) @@ -212,7 +212,7 @@ func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context, defer wg.Done() for pkg := range pkgCh { var pkgIssues []EncodingIssue - err := lintCtx.PkgCache.Get(pkg, pkgcache.HashModeNeedAllDeps, lintResKey, &pkgIssues) + err := lintCtx.PkgCache.Get(pkg, cache.HashModeNeedAllDeps, lintResKey, &pkgIssues) cacheRes := pkgToCacheRes[pkg] cacheRes.loadErr = err if err != nil { diff --git a/pkg/lint/context.go b/pkg/lint/context.go index 160620338f8c..d04a11b81f1a 100644 --- a/pkg/lint/context.go +++ b/pkg/lint/context.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/golangci/golangci-lint/internal/pkgcache" + "github.com/golangci/golangci-lint/internal/cache" "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/exitcodes" "github.com/golangci/golangci-lint/pkg/fsutils" @@ -19,13 +19,13 @@ type ContextBuilder struct { pkgLoader *PackageLoader fileCache *fsutils.FileCache - pkgCache *pkgcache.Cache + pkgCache *cache.Cache loadGuard *load.Guard } func NewContextBuilder(cfg *config.Config, pkgLoader *PackageLoader, - fileCache *fsutils.FileCache, pkgCache *pkgcache.Cache, loadGuard *load.Guard, + fileCache *fsutils.FileCache, pkgCache *cache.Cache, loadGuard *load.Guard, ) *ContextBuilder { return &ContextBuilder{ cfg: cfg, diff --git a/pkg/lint/linter/context.go b/pkg/lint/linter/context.go index 5c03630b26df..9f29b5c4c884 100644 --- a/pkg/lint/linter/context.go +++ b/pkg/lint/linter/context.go @@ -5,7 +5,7 @@ import ( "golang.org/x/tools/go/packages" - "github.com/golangci/golangci-lint/internal/pkgcache" + "github.com/golangci/golangci-lint/internal/cache" "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/fsutils" "github.com/golangci/golangci-lint/pkg/goanalysis/load" @@ -24,7 +24,7 @@ type Context struct { FileCache *fsutils.FileCache Log logutils.Log - PkgCache *pkgcache.Cache + PkgCache *cache.Cache LoadGuard *load.Guard } From 46e8c03ff039cc0a4c56fc396464d12e37acfa91 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 2 Nov 2024 21:17:14 +0100 Subject: [PATCH 4/4] docs: update history --- internal/go/cache/readme.md | 35 +++++++++++++++++++++++----------- internal/go/mmap/readme.md | 16 +++++++++++----- internal/go/quoted/readme.md | 12 +++++++++--- internal/go/robustio/readme.md | 5 +++++ internal/go/testenv/readme.md | 11 ++++++++--- 5 files changed, 57 insertions(+), 22 deletions(-) diff --git a/internal/go/cache/readme.md b/internal/go/cache/readme.md index 6a774536a610..5be600e42525 100644 --- a/internal/go/cache/readme.md +++ b/internal/go/cache/readme.md @@ -2,18 +2,31 @@ Extracted from `go/src/cmd/go/internal/cache/`. -- sync with go1.23.2 -- sync with go1.22.8 -- sync with go1.21.13 -- sync with go1.20.14 -- sync with go1.19.13 -- sync with go1.18.10 -- sync with go1.17.13 -- sync with go1.16.15 -- sync with go1.15.15 -- sync with go1.14.15 +The main modifications are: +- The errors management + - Some methods return error. + - Some errors are returned instead of being ignored. +- The name of the env vars: + - `GOCACHE` -> `GOLANGCI_LINT_CACHE` + - `GOCACHEPROG` -> `GOLANGCI_LINT_CACHEPROG` -# Previous History +## History + +- https://github.com/golangci/golangci-lint/pull/5100 + - Move package from `internal/cache` to `internal/go/cache` +- https://github.com/golangci/golangci-lint/pull/5098 + - sync with go1.23.2 + - sync with go1.22.8 + - sync with go1.21.13 + - sync with go1.20.14 + - sync with go1.19.13 + - sync with go1.18.10 + - sync with go1.17.13 + - sync with go1.16.15 + - sync with go1.15.15 + - sync with go1.14.15 + +## Previous History Based on the initial PR/commit the based in a mix between go1.12 and go1.13: - cache.go (go1.13) diff --git a/internal/go/mmap/readme.md b/internal/go/mmap/readme.md index b5ec2d36840d..f68aef097c88 100644 --- a/internal/go/mmap/readme.md +++ b/internal/go/mmap/readme.md @@ -1,9 +1,15 @@ # mmap Extracted from `go/src/cmd/go/internal/mmap/` (related to `cache`). +This is just a copy of the Go code without any changes. -- sync with go1.23.2 -- sync with go1.22.8 -- sync with go1.21.13 -- sync with go1.20.14 -- sync with go1.19.13 +## History + +- https://github.com/golangci/golangci-lint/pull/5100 + - Move package from `internal/mmap` to `internal/go/mmap` +- https://github.com/golangci/golangci-lint/pull/5098 + - sync with go1.23.2 + - sync with go1.22.8 + - sync with go1.21.13 + - sync with go1.20.14 + - sync with go1.19.13 diff --git a/internal/go/quoted/readme.md b/internal/go/quoted/readme.md index a3c33d624513..a5e4c4bb3b09 100644 --- a/internal/go/quoted/readme.md +++ b/internal/go/quoted/readme.md @@ -1,7 +1,13 @@ # quoted Extracted from `go/src/cmd/internal/quoted/` (related to `cache`). +This is just a copy of the Go code without any changes. -- sync go1.23.2 -- sync go1.22.8 -- sync go1.21.13 +## History + +- https://github.com/golangci/golangci-lint/pull/5100 + - Move package from `internal/quoted` to `internal/go/quoted` +- https://github.com/golangci/golangci-lint/pull/5098 + - sync go1.23.2 + - sync go1.22.8 + - sync go1.21.13 diff --git a/internal/go/robustio/readme.md b/internal/go/robustio/readme.md index 7c7ba0483ae5..f4dbc162649d 100644 --- a/internal/go/robustio/readme.md +++ b/internal/go/robustio/readme.md @@ -4,3 +4,8 @@ Extracted from go1.19.1/src/cmd/go/internal/robustio There is only one modification: - ERROR_SHARING_VIOLATION extracted from go1.19.1/src/internal/syscall/windows/syscall_windows.go to remove the dependencies to `internal/syscall/windows` + +## History + +- https://github.com/golangci/golangci-lint/pull/5100 + - Move package from `internal/robustio` to `internal/go/robustio` diff --git a/internal/go/testenv/readme.md b/internal/go/testenv/readme.md index 528890c26fa6..6610210ee193 100644 --- a/internal/go/testenv/readme.md +++ b/internal/go/testenv/readme.md @@ -4,6 +4,11 @@ Extracted from `go/src/internal/testenv/`. Only the function `SyscallIsNotSupported` is extracted (related to `cache`). -- sync with go1.23.2 -- sync with go1.22.8 -- sync with go1.21.13 +## History + +- https://github.com/golangci/golangci-lint/pull/5100 + - Move package from `internal/testenv` to `internal/go/testenv` +- https://github.com/golangci/golangci-lint/pull/5098 + - sync with go1.23.2 + - sync with go1.22.8 + - sync with go1.21.13