Skip to content

Commit

Permalink
refactor: replace golang.org/x/exp with stdlib
Browse files Browse the repository at this point in the history
These experimental packages are now available in the Go standard
library since Go 1.21:

	1. golang.org/x/exp/slices -> slices [1]
	2. golang.org/x/exp/maps -> maps [2]

[1]: https://go.dev/doc/go1.21#slices
[2]: https://go.dev/doc/go1.21#maps

Signed-off-by: Eng Zer Jun <[email protected]>
  • Loading branch information
Juneezee committed Jan 23, 2025
1 parent b48b0fc commit 59024c4
Show file tree
Hide file tree
Showing 23 changed files with 30 additions and 279 deletions.
2 changes: 1 addition & 1 deletion bind/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"syscall"

"github.com/containers/buildah/util"
"github.com/containers/storage/pkg/idtools"
"github.com/containers/storage/pkg/mount"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"golang.org/x/exp/slices"
"golang.org/x/sys/unix"
)

Expand Down
3 changes: 2 additions & 1 deletion bind/util.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package bind

import (
"slices"

"github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/exp/slices"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion chroot/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"os"
"path/filepath"
"slices"
"strconv"
"strings"
"testing"
Expand All @@ -21,7 +22,6 @@ import (
"github.com/opencontainers/runtime-tools/generate"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
"golang.org/x/sys/unix"
)

Expand Down
2 changes: 1 addition & 1 deletion commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
"maps"
"os"
"strings"
"time"
Expand All @@ -26,7 +27,6 @@ import (
digest "github.com/opencontainers/go-digest"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/sirupsen/logrus"
"golang.org/x/exp/maps"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"encoding/json"
"fmt"
"maps"
"os"
"runtime"
"slices"
"strings"
"time"

Expand All @@ -19,8 +21,6 @@ import (
"github.com/containers/storage/pkg/stringid"
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/sirupsen/logrus"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)

// unmarshalConvertedConfig obtains the config blob of img valid for the wantedManifestMIMEType format
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ require (
github.com/stretchr/testify v1.10.0
go.etcd.io/bbolt v1.3.11
golang.org/x/crypto v0.32.0
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67
golang.org/x/sync v0.10.0
golang.org/x/sys v0.29.0
golang.org/x/term v0.28.0
Expand Down Expand Up @@ -145,6 +144,7 @@ require (
go.opentelemetry.io/otel v1.31.0 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect
go.opentelemetry.io/otel/trace v1.31.0 // indirect
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/text v0.21.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions image.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"errors"
"fmt"
"io"
"maps"
"os"
"path/filepath"
"slices"
"strings"
"time"

Expand All @@ -33,8 +35,6 @@ import (
specs "github.com/opencontainers/image-spec/specs-go"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/sirupsen/logrus"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions imagebuildah/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"fmt"
gotypes "go/types"
"io"
"maps"
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"slices"
"strconv"
"strings"
"sync"
Expand All @@ -38,8 +40,6 @@ import (
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/openshift/imagebuilder"
"github.com/sirupsen/logrus"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
"golang.org/x/sync/semaphore"
)

Expand Down
5 changes: 2 additions & 3 deletions imagebuildah/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"io"
"os"
"sort"
"slices"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -35,7 +35,6 @@ import (
"github.com/openshift/imagebuilder"
"github.com/openshift/imagebuilder/dockerfile/parser"
"github.com/sirupsen/logrus"
"golang.org/x/exp/slices"
"golang.org/x/sync/semaphore"
)

Expand Down Expand Up @@ -1015,7 +1014,7 @@ func (b *Executor) Build(ctx context.Context, stages imagebuilder.Stages) (image
for k := range b.unusedArgs {
unusedList = append(unusedList, k)
}
sort.Strings(unusedList)
slices.Sort(unusedList)
fmt.Fprintf(b.out, "[Warning] one or more build args were not consumed: %v\n", unusedList)
}

Expand Down
7 changes: 3 additions & 4 deletions imagebuildah/stage_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os"
"path"
"path/filepath"
"sort"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -44,7 +44,6 @@ import (
"github.com/openshift/imagebuilder/dockerfile/command"
"github.com/openshift/imagebuilder/dockerfile/parser"
"github.com/sirupsen/logrus"
"golang.org/x/exp/slices"
)

// StageExecutor bundles up what we need to know when executing one stage of a
Expand Down Expand Up @@ -1931,7 +1930,7 @@ func (s *StageExecutor) getBuildArgsResolvedForRun() string {
}
}
}
sort.Strings(envs)
slices.Sort(envs)
return strings.Join(envs, " ")
}

Expand All @@ -1944,7 +1943,7 @@ func (s *StageExecutor) getBuildArgsKey() string {
args = append(args, key)
}
}
sort.Strings(args)
slices.Sort(args)
return strings.Join(args, " ")
}

Expand Down
2 changes: 1 addition & 1 deletion internal/config/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package config

import (
"reflect"
"slices"
"strconv"
"testing"

"github.com/containers/image/v5/manifest"
dockerclient "github.com/fsouza/go-dockerclient"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
)

// fillAllFields recursively fills in 1 or "1" for every field in the passed-in
Expand Down
2 changes: 1 addition & 1 deletion internal/volumes/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path"
"path/filepath"
"slices"
"strconv"
"strings"

Expand All @@ -28,7 +29,6 @@ import (
specs "github.com/opencontainers/runtime-spec/specs-go"
selinux "github.com/opencontainers/selinux/go-selinux"
"github.com/sirupsen/logrus"
"golang.org/x/exp/slices"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions new.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"
"errors"
"fmt"
"maps"
"math/rand"
"slices"
"strings"

"github.com/containers/buildah/define"
Expand All @@ -21,8 +23,6 @@ import (
v1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/openshift/imagebuilder"
"github.com/sirupsen/logrus"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"io"
"os"
"path/filepath"
"slices"
"strings"
"time"

Expand All @@ -24,7 +25,6 @@ import (
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"golang.org/x/exp/slices"
)

type BuildOptions struct {
Expand Down
2 changes: 1 addition & 1 deletion run_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"os/signal"
"path/filepath"
"runtime"
"slices"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -52,7 +53,6 @@ import (
"github.com/opencontainers/runtime-tools/generate"
"github.com/opencontainers/selinux/go-selinux/label"
"github.com/sirupsen/logrus"
"golang.org/x/exp/slices"
"golang.org/x/sys/unix"
"golang.org/x/term"
)
Expand Down
2 changes: 1 addition & 1 deletion run_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"strings"
"unsafe"

Expand All @@ -33,7 +34,6 @@ import (
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/generate"
"github.com/sirupsen/logrus"
"golang.org/x/exp/slices"
"golang.org/x/sys/unix"
)

Expand Down
2 changes: 1 addition & 1 deletion run_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -46,7 +47,6 @@ import (
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/generate"
"github.com/sirupsen/logrus"
"golang.org/x/exp/slices"
"golang.org/x/sys/unix"
"tags.cncf.io/container-device-interface/pkg/cdi"
"tags.cncf.io/container-device-interface/pkg/parser"
Expand Down
2 changes: 1 addition & 1 deletion scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"io"
"os"
"path/filepath"
"slices"
"strings"

"github.com/containers/buildah/define"
"github.com/containers/buildah/internal/sbom"
"github.com/mattn/go-shellwords"
rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"golang.org/x/exp/slices"
)

func stringSliceReplaceAll(slice []string, replacements map[string]string, important []string) (built []string, replacedAnImportantValue bool) {
Expand Down
4 changes: 2 additions & 2 deletions tests/conformance/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (
"fmt"
"io"
"io/fs"
"maps"
"os"
"path"
"path/filepath"
"reflect"
"regexp"
"slices"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -52,8 +54,6 @@ import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/url"
"os"
"path/filepath"
"slices"
"sort"
"strings"
"syscall"
Expand All @@ -24,7 +25,6 @@ import (
"github.com/opencontainers/go-digest"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"golang.org/x/exp/slices"
)

const (
Expand All @@ -42,7 +42,7 @@ var RegistryDefaultPathPrefix = map[string]string{
"docker.io": "library",
}

// StringInSlice is deprecated, use golang.org/x/exp/slices.Contains
// StringInSlice is deprecated, use slices.Contains
func StringInSlice(s string, slice []string) bool {
return slices.Contains(slice, s)
}
Expand Down
Loading

0 comments on commit 59024c4

Please sign in to comment.