Skip to content

Commit 3fbc038

Browse files
authored
Move first batch of ext-suffixed packages to standard with x prefix (#3838)
1 parent 878a477 commit 3fbc038

File tree

205 files changed

+1069
-1059
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

205 files changed

+1069
-1059
lines changed

.golangci.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ linters:
4949
forbid:
5050
# Use private/pkg/thread.Parallelize
5151
- pattern: ^errgroup\.
52-
# Use private/pkg/execext
52+
# Use private/pkg/standard/xos/xexec
5353
- pattern: ^exec\.Cmd$
5454
- pattern: ^exec\.Command$
5555
- pattern: ^exec\.CommandContext$
@@ -229,7 +229,7 @@ linters:
229229
- linters:
230230
- containedctx
231231
# we actually want to embed a context here
232-
path: private/pkg/execext/process.go
232+
path: private/pkg/standard/xos/xexec/process.go
233233
- linters:
234234
- gochecknoinits
235235
# we actually want to use init here
@@ -242,15 +242,15 @@ linters:
242242
- linters:
243243
- forbidigo
244244
# this is one of two files we want to allow exec.Cmd functions in
245-
path: private/pkg/execext/execext.go
245+
path: private/pkg/standard/xos/xexec/xexec.go
246246
- linters:
247247
- forbidigo
248248
# this is one of two files we want to allow exec.Cmd functions in
249-
path: private/pkg/execext/process.go
249+
path: private/pkg/standard/xos/xexec/process.go
250250
- linters:
251251
- gosec
252252
# G204 checks that exec.Command is not called with non-constants.
253-
path: private/pkg/execext/execext.go
253+
path: private/pkg/standard/xos/xexec/xexec.go
254254
text: 'G204:'
255255
- linters:
256256
- gosec
@@ -273,6 +273,11 @@ linters:
273273
# We cache os.Getwd in osext, osext has a Chdir that clears the cache.
274274
path: private/pkg/osext/osext.go
275275
text: os.Chdir
276+
- linters:
277+
- forbidigo
278+
# We're going to move xfilepath out.
279+
path: private/pkg/standard/xpath/xfilepath/xfilepath.go
280+
text: os.Getwd
276281
- linters:
277282
- gochecknoinits
278283
# protoencoding calls detrand.Disable via go:linkname and and init function. See the comments

private/buf/bufcli/flags_args.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"buf.build/go/app"
2525
"buf.build/go/app/appcmd"
2626
"github.com/bufbuild/buf/private/buf/buffetch"
27-
"github.com/bufbuild/buf/private/pkg/stringutil"
27+
"github.com/bufbuild/buf/private/pkg/standard/xstrings"
2828
"github.com/spf13/pflag"
2929
)
3030

@@ -154,7 +154,7 @@ func BindVisibility(flagSet *pflag.FlagSet, addr *string, flagName string, empty
154154
addr,
155155
flagName,
156156
defaultVisibility,
157-
fmt.Sprintf(`The module's visibility setting. Must be one of %s`, stringutil.SliceToString(allVisibilityStrings)),
157+
fmt.Sprintf(`The module's visibility setting. Must be one of %s`, xstrings.SliceToString(allVisibilityStrings)),
158158
)
159159
}
160160

@@ -165,7 +165,7 @@ func BindCreateVisibility(flagSet *pflag.FlagSet, addr *string, flagName string,
165165
addr,
166166
flagName,
167167
privateVisibility,
168-
fmt.Sprintf(`The module's visibility setting, if created. Can only be set with --%s. Must be one of %s`, createFlagName, stringutil.SliceToString(allVisibilityStrings)),
168+
fmt.Sprintf(`The module's visibility setting, if created. Can only be set with --%s. Must be one of %s`, createFlagName, xstrings.SliceToString(allVisibilityStrings)),
169169
)
170170
}
171171

@@ -176,7 +176,7 @@ func BindArchiveStatus(flagSet *pflag.FlagSet, addr *string, flagName string) {
176176
addr,
177177
flagName,
178178
DefaultArchiveStatus,
179-
fmt.Sprintf(`The archive status of the labels listed. Must be one of %s`, stringutil.SliceToString(allArchiveStatusStrings)),
179+
fmt.Sprintf(`The archive status of the labels listed. Must be one of %s`, xstrings.SliceToString(allArchiveStatusStrings)),
180180
)
181181
}
182182

private/buf/bufctl/controller.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ import (
4545
imagev1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/image/v1"
4646
"github.com/bufbuild/buf/private/pkg/git"
4747
"github.com/bufbuild/buf/private/pkg/httpauth"
48-
"github.com/bufbuild/buf/private/pkg/ioext"
4948
"github.com/bufbuild/buf/private/pkg/normalpath"
5049
"github.com/bufbuild/buf/private/pkg/protoencoding"
51-
"github.com/bufbuild/buf/private/pkg/slicesext"
50+
"github.com/bufbuild/buf/private/pkg/standard/xio"
51+
"github.com/bufbuild/buf/private/pkg/standard/xslices"
5252
"github.com/bufbuild/buf/private/pkg/storage/storageos"
5353
"github.com/bufbuild/buf/private/pkg/syserror"
5454
"github.com/bufbuild/buf/private/pkg/wasm"
@@ -726,7 +726,7 @@ func (c *controller) GetMessage(
726726
if err != nil {
727727
return nil, 0, err
728728
}
729-
data, err := ioext.ReadAllAndClose(readCloser)
729+
data, err := xio.ReadAllAndClose(readCloser)
730730
if err != nil {
731731
return nil, 0, err
732732
}
@@ -1205,13 +1205,13 @@ func (c *controller) warnUnconfiguredTransitiveImports(
12051205
// First, figure out if we have a local module. If we don't, just return - the Workspace
12061206
// was purely built from remote Modules, and therefore buf.yaml configured dependencies
12071207
// do not apply.
1208-
if slicesext.Count(workspace.Modules(), bufmodule.Module.IsLocal) == 0 {
1208+
if xslices.Count(workspace.Modules(), bufmodule.Module.IsLocal) == 0 {
12091209
return nil
12101210
}
12111211
// Construct a struct map of all the FullName strings of the configured buf.yaml
12121212
// Module dependencies, and the local Modules. These are considered OK to depend on
12131213
// for non-imports in the Image.
1214-
configuredFullNameStrings, err := slicesext.MapError(
1214+
configuredFullNameStrings, err := xslices.MapError(
12151215
workspace.ConfiguredDepModuleRefs(),
12161216
func(moduleRef bufparse.Ref) (string, error) {
12171217
moduleFullName := moduleRef.FullName()
@@ -1224,7 +1224,7 @@ func (c *controller) warnUnconfiguredTransitiveImports(
12241224
if err != nil {
12251225
return err
12261226
}
1227-
configuredFullNameStringMap := slicesext.ToStructMap(configuredFullNameStrings)
1227+
configuredFullNameStringMap := xslices.ToStructMap(configuredFullNameStrings)
12281228
for _, localModule := range bufmodule.ModuleSetLocalModules(workspace) {
12291229
if moduleFullName := localModule.FullName(); moduleFullName != nil {
12301230
configuredFullNameStringMap[moduleFullName.String()] = struct{}{}
@@ -1314,7 +1314,7 @@ func getImageFileInfosForModuleSet(ctx context.Context, moduleSet bufmodule.Modu
13141314
if err != nil {
13151315
return nil, err
13161316
}
1317-
return slicesext.Map(
1317+
return xslices.Map(
13181318
fileInfos,
13191319
func(fileInfo bufmodule.FileInfo) bufimage.ImageFileInfo {
13201320
return bufimage.ImageFileInfoForModuleFileInfo(fileInfo)
@@ -1478,15 +1478,15 @@ func newStaticPluginKeyProviderForPluginConfigs(
14781478
pluginKeys []bufplugin.PluginKey,
14791479
) (_ bufplugin.PluginKeyProvider, retErr error) {
14801480
// Validate that all remote PluginConfigs are present in the buf.lock file.
1481-
pluginKeysByFullName, err := slicesext.ToUniqueValuesMap(pluginKeys, func(pluginKey bufplugin.PluginKey) string {
1481+
pluginKeysByFullName, err := xslices.ToUniqueValuesMap(pluginKeys, func(pluginKey bufplugin.PluginKey) string {
14821482
return pluginKey.FullName().String()
14831483
})
14841484
if err != nil {
14851485
return nil, fmt.Errorf("failed to validate remote PluginKeys: %w", err)
14861486
}
14871487
// Remote PluginConfig Refs are any PluginConfigs that have a Ref.
1488-
remotePluginRefs := slicesext.Filter(
1489-
slicesext.Map(pluginConfigs, func(pluginConfig bufconfig.PluginConfig) bufparse.Ref {
1488+
remotePluginRefs := xslices.Filter(
1489+
xslices.Map(pluginConfigs, func(pluginConfig bufconfig.PluginConfig) bufparse.Ref {
14901490
return pluginConfig.Ref()
14911491
}),
14921492
func(pluginRef bufparse.Ref) bool {

private/buf/buffetch/buffetch.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929
"github.com/bufbuild/buf/private/bufpkg/bufmodule"
3030
"github.com/bufbuild/buf/private/pkg/git"
3131
"github.com/bufbuild/buf/private/pkg/httpauth"
32+
"github.com/bufbuild/buf/private/pkg/standard/xstrings"
3233
"github.com/bufbuild/buf/private/pkg/storage/storageos"
33-
"github.com/bufbuild/buf/private/pkg/stringutil"
3434
)
3535

3636
const (
@@ -51,34 +51,34 @@ var (
5151
// MessageFormatsString is the string representation of all message formats.
5252
//
5353
// This does not include deprecated formats.
54-
MessageFormatsString = stringutil.SliceToString(messageFormatsNotDeprecated)
54+
MessageFormatsString = xstrings.SliceToString(messageFormatsNotDeprecated)
5555
// SourceDirFormatsString is the string representation of all source directory formats.
5656
// This includes all of the formats in SourceFormatsString except the protofile format.
5757
//
5858
// This does not include deprecated formats.
59-
SourceDirFormatsString = stringutil.SliceToString(sourceDirFormatsNotDeprecated)
59+
SourceDirFormatsString = xstrings.SliceToString(sourceDirFormatsNotDeprecated)
6060
// SourceFormatsString is the string representation of all source formats.
6161
//
6262
// This does not include deprecated formats.
63-
SourceFormatsString = stringutil.SliceToString(sourceFormatsNotDeprecated)
63+
SourceFormatsString = xstrings.SliceToString(sourceFormatsNotDeprecated)
6464
// ModuleFormatsString is the string representation of all module formats.
6565
//
6666
// Module formats are also source formats.
6767
//
6868
// This does not include deprecated formats.
69-
ModuleFormatsString = stringutil.SliceToString(moduleFormatsNotDeprecated)
69+
ModuleFormatsString = xstrings.SliceToString(moduleFormatsNotDeprecated)
7070
// SourceOrModuleFormatsString is the string representation of all source or module formats.
7171
//
7272
// This does not include deprecated formats.
73-
SourceOrModuleFormatsString = stringutil.SliceToString(sourceOrModuleFormatsNotDeprecated)
73+
SourceOrModuleFormatsString = xstrings.SliceToString(sourceOrModuleFormatsNotDeprecated)
7474
// DirOrProtoFileFormatsString is the string representation of all dir or proto file formats.
7575
//
7676
// This does not include deprecated formats.
77-
DirOrProtoFileFormatsString = stringutil.SliceToString(dirOrProtoFileFormats)
77+
DirOrProtoFileFormatsString = xstrings.SliceToString(dirOrProtoFileFormats)
7878
// AllFormatsString is the string representation of all formats.
7979
//
8080
// This does not include deprecated formats.
81-
AllFormatsString = stringutil.SliceToString(allFormatsNotDeprecated)
81+
AllFormatsString = xstrings.SliceToString(allFormatsNotDeprecated)
8282

8383
// ErrModuleFormatDetectedForDirOrProtoFileRef is the error returned if a module is the
8484
// detected format in the DirOrProtoFileRefParser. We have a special heuristic to determine

private/buf/buffetch/internal/dir_ref.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
"strings"
1919

2020
"buf.build/go/app"
21-
"github.com/bufbuild/buf/private/pkg/filepathext"
2221
"github.com/bufbuild/buf/private/pkg/normalpath"
22+
"github.com/bufbuild/buf/private/pkg/standard/xpath/xfilepath"
2323
)
2424

2525
var (
@@ -47,7 +47,7 @@ func newDirRef(
4747
if strings.Contains(path, "://") {
4848
return nil, NewInvalidPathError(format, path)
4949
}
50-
path, err := filepathext.RealClean(path)
50+
path, err := xfilepath.RealClean(path)
5151
if err != nil {
5252
return nil, NewRealCleanPathError(path)
5353
}

private/buf/buffetch/internal/proto_file_writer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"os"
2424

2525
"buf.build/go/app"
26-
"github.com/bufbuild/buf/private/pkg/ioext"
2726
"github.com/bufbuild/buf/private/pkg/normalpath"
27+
"github.com/bufbuild/buf/private/pkg/standard/xio"
2828
)
2929

3030
type protoFileWriter struct {
@@ -62,11 +62,11 @@ func (w *protoFileWriter) PutProtoFile(
6262
// This was in the old formatter, just keeping as-is for now instead of using os.Create.
6363
return os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
6464
case FileSchemeStdio, FileSchemeStdout:
65-
return ioext.NopWriteCloser(container.Stdout()), nil
65+
return xio.NopWriteCloser(container.Stdout()), nil
6666
case FileSchemeStdin:
6767
return nil, errors.New("cannot write to stdin")
6868
case FileSchemeNull:
69-
return ioext.DiscardWriteCloser, nil
69+
return xio.DiscardWriteCloser, nil
7070
default:
7171
return nil, fmt.Errorf("unknown FileScheme: %v", fileScheme)
7272
}

private/buf/buffetch/internal/reader.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ import (
3232
"github.com/bufbuild/buf/private/bufpkg/bufparse"
3333
"github.com/bufbuild/buf/private/pkg/git"
3434
"github.com/bufbuild/buf/private/pkg/httpauth"
35-
"github.com/bufbuild/buf/private/pkg/ioext"
3635
"github.com/bufbuild/buf/private/pkg/normalpath"
3736
"github.com/bufbuild/buf/private/pkg/osext"
38-
"github.com/bufbuild/buf/private/pkg/slicesext"
37+
"github.com/bufbuild/buf/private/pkg/standard/xio"
38+
"github.com/bufbuild/buf/private/pkg/standard/xslices"
3939
"github.com/bufbuild/buf/private/pkg/storage"
4040
"github.com/bufbuild/buf/private/pkg/storage/storagearchive"
4141
"github.com/bufbuild/buf/private/pkg/storage/storagemem"
@@ -272,7 +272,7 @@ func (r *reader) getArchiveBucket(
272272
readerAt = bytes.NewReader(data)
273273
size = int64(len(data))
274274
} else {
275-
readerAt, err = ioext.ReaderAtForReader(readCloser)
275+
readerAt, err = xio.ReaderAtForReader(readCloser)
276276
if err != nil {
277277
return nil, nil, err
278278
}
@@ -438,9 +438,9 @@ func (r *reader) getFileReadCloserAndSize(
438438
if err != nil {
439439
return nil, -1, err
440440
}
441-
return ioext.CompositeReadCloser(
441+
return xio.CompositeReadCloser(
442442
gzipReadCloser,
443-
ioext.ChainCloser(
443+
xio.ChainCloser(
444444
gzipReadCloser,
445445
readCloser,
446446
),
@@ -451,9 +451,9 @@ func (r *reader) getFileReadCloserAndSize(
451451
return nil, -1, err
452452
}
453453
zstdReadCloser := zstdDecoder.IOReadCloser()
454-
return ioext.CompositeReadCloser(
454+
return xio.CompositeReadCloser(
455455
zstdReadCloser,
456-
ioext.ChainCloser(
456+
xio.ChainCloser(
457457
zstdReadCloser,
458458
readCloser,
459459
),
@@ -501,7 +501,7 @@ func (r *reader) getFileReadCloserAndSizePotentiallyCompressed(
501501
case FileSchemeStdout:
502502
return nil, -1, errors.New("cannot read from stdout")
503503
case FileSchemeNull:
504-
return ioext.DiscardReadCloser, 0, nil
504+
return xio.DiscardReadCloser, 0, nil
505505
default:
506506
return nil, -1, fmt.Errorf("unknown FileScheme: %v", fileScheme)
507507
}
@@ -901,13 +901,13 @@ func validatePaths(
901901
if _, err := normalpath.NormalizeAndValidate(inputSubDirPath); err != nil {
902902
return err
903903
}
904-
if _, err := slicesext.MapError(
904+
if _, err := xslices.MapError(
905905
targetPaths,
906906
normalpath.NormalizeAndValidate,
907907
); err != nil {
908908
return err
909909
}
910-
if _, err := slicesext.MapError(
910+
if _, err := xslices.MapError(
911911
targetPaths,
912912
normalpath.NormalizeAndValidate,
913913
); err != nil {
@@ -925,13 +925,13 @@ func mapTargetPathsAndTargetExcludePathsForArchiveAndGitRefs(
925925
if inputSubDirPath == "." {
926926
return targetPaths, targetExcludePaths
927927
}
928-
return slicesext.Map(
928+
return xslices.Map(
929929
targetPaths,
930930
func(targetPath string) string {
931931
return normalpath.Join(inputSubDirPath, targetPath)
932932
},
933933
),
934-
slicesext.Map(
934+
xslices.Map(
935935
targetExcludePaths,
936936
func(targetExcludePath string) string {
937937
return normalpath.Join(inputSubDirPath, targetExcludePath)

private/buf/buffetch/internal/writer.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"os"
2525

2626
"buf.build/go/app"
27-
"github.com/bufbuild/buf/private/pkg/ioext"
27+
"github.com/bufbuild/buf/private/pkg/standard/xio"
2828
"github.com/klauspost/compress/zstd"
2929
)
3030

@@ -121,9 +121,9 @@ func (w *writer) putFileWriteCloser(
121121
return writeCloser, nil
122122
case CompressionTypeGzip:
123123
gzipWriteCloser := gzip.NewWriter(writeCloser)
124-
return ioext.CompositeWriteCloser(
124+
return xio.CompositeWriteCloser(
125125
gzipWriteCloser,
126-
ioext.ChainCloser(
126+
xio.ChainCloser(
127127
gzipWriteCloser,
128128
writeCloser,
129129
),
@@ -133,9 +133,9 @@ func (w *writer) putFileWriteCloser(
133133
if err != nil {
134134
return nil, err
135135
}
136-
return ioext.CompositeWriteCloser(
136+
return xio.CompositeWriteCloser(
137137
zstdWriteCloser,
138-
ioext.ChainCloser(
138+
xio.ChainCloser(
139139
zstdWriteCloser,
140140
writeCloser,
141141
),
@@ -170,11 +170,11 @@ func (w *writer) putFileWriteCloserPotentiallyUncompressed(
170170
if !w.stdioEnabled {
171171
return nil, NewWriteStdioDisabledError()
172172
}
173-
return ioext.NopWriteCloser(container.Stdout()), nil
173+
return xio.NopWriteCloser(container.Stdout()), nil
174174
case FileSchemeStdin:
175175
return nil, errors.New("cannot write to stdin")
176176
case FileSchemeNull:
177-
return ioext.DiscardWriteCloser, nil
177+
return xio.DiscardWriteCloser, nil
178178
default:
179179
return nil, fmt.Errorf("unknown FileScheme: %v", fileScheme)
180180
}

0 commit comments

Comments
 (0)