-
Notifications
You must be signed in to change notification settings - Fork 17.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go: split out cmd/go/internal/work
This is one CL in a long sequence of changes to break up the go command from one package into a plausible group of packages. This sequence is concerned only with moving code, not changing or cleaning up code. There will still be more cleanup after this sequence. The entire sequence will be submitted together: it is not a goal for the tree to build at every step. For #18653. Change-Id: Icdd181098f9f0e81f68bf201e6867cdd8f820300 Reviewed-on: https://go-review.googlesource.com/36197 Reviewed-by: David Crawshaw <[email protected]>
- Loading branch information
Showing
18 changed files
with
878 additions
and
784 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2017 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package base | ||
|
||
import "strings" | ||
|
||
// envForDir returns a copy of the environment | ||
// suitable for running in the given directory. | ||
// The environment is the current process's environment | ||
// but with an updated $PWD, so that an os.Getwd in the | ||
// child will be faster. | ||
func EnvForDir(dir string, base []string) []string { | ||
// Internally we only use rooted paths, so dir is rooted. | ||
// Even if dir is not rooted, no harm done. | ||
return MergeEnvLists([]string{"PWD=" + dir}, base) | ||
} | ||
|
||
// MergeEnvLists merges the two environment lists such that | ||
// variables with the same name in "in" replace those in "out". | ||
// This always returns a newly allocated slice. | ||
func MergeEnvLists(in, out []string) []string { | ||
out = append([]string(nil), out...) | ||
NextVar: | ||
for _, inkv := range in { | ||
k := strings.SplitAfterN(inkv, "=", 2)[0] | ||
for i, outkv := range out { | ||
if strings.HasPrefix(outkv, k) { | ||
out[i] = inkv | ||
continue NextVar | ||
} | ||
} | ||
out = append(out, inkv) | ||
} | ||
return out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2017 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package base | ||
|
||
import ( | ||
"cmd/go/internal/str" | ||
"flag" | ||
) | ||
|
||
// A StringsFlag is a command-line flag that interprets its argument | ||
// as a space-separated list of possibly-quoted strings. | ||
type StringsFlag []string | ||
|
||
func (v *StringsFlag) Set(s string) error { | ||
var err error | ||
*v, err = str.SplitQuotedFields(s) | ||
if *v == nil { | ||
*v = []string{} | ||
} | ||
return err | ||
} | ||
|
||
func (v *StringsFlag) String() string { | ||
return "<StringsFlag>" | ||
} | ||
|
||
// AddBuildFlagsNX adds the -n and -x build flags to the flag set. | ||
func AddBuildFlagsNX(flags *flag.FlagSet) { | ||
flags.BoolVar(&BuildN, "n", false, "") | ||
flags.BoolVar(&BuildX, "x", false, "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.