Skip to content

Commit

Permalink
Merge pull request #1641 from xushiwei/ov
Browse files Browse the repository at this point in the history
genGoDir: don't copy conf
  • Loading branch information
xushiwei committed Jan 18, 2024
2 parents b00ea4e + 8743331 commit 10e379d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
24 changes: 24 additions & 0 deletions build_install_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (

// -----------------------------------------------------------------------------

// InstallDir installs a Go+ package directory.
// if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
func InstallDir(dir string, conf *Config, install *gocmd.InstallConfig) (err error) {
_, _, err = GenGo(dir, conf, false)
if err != nil {
Expand All @@ -34,6 +36,8 @@ func InstallDir(dir string, conf *Config, install *gocmd.InstallConfig) (err err
return gocmd.Install(dir, install)
}

// InstallPkgPath installs a Go+ package.
// if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
func InstallPkgPath(workDir, pkgPath string, conf *Config, install *gocmd.InstallConfig) (err error) {
localDir, recursively, err := GenGoPkgPath(workDir, pkgPath, conf, true)
if err != nil {
Expand All @@ -51,6 +55,8 @@ func cwdParam(recursively bool) string {
return "."
}

// InstallFiles installs specified Go+ files.
// if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
func InstallFiles(files []string, conf *Config, install *gocmd.InstallConfig) (err error) {
files, err = GenGoFiles("", files, conf)
if err != nil {
Expand All @@ -73,6 +79,8 @@ func chdir(dir string) string {

// -----------------------------------------------------------------------------

// BuildDir builds a Go+ package directory.
// if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
func BuildDir(dir string, conf *Config, build *gocmd.BuildConfig) (err error) {
_, _, err = GenGo(dir, conf, false)
if err != nil {
Expand All @@ -81,6 +89,8 @@ func BuildDir(dir string, conf *Config, build *gocmd.BuildConfig) (err error) {
return gocmd.Build(dir, build)
}

// BuildPkgPath builds a Go+ package.
// if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
func BuildPkgPath(workDir, pkgPath string, conf *Config, build *gocmd.BuildConfig) (err error) {
localDir, recursively, err := GenGoPkgPath(workDir, pkgPath, conf, false)
if err != nil {
Expand All @@ -91,6 +101,8 @@ func BuildPkgPath(workDir, pkgPath string, conf *Config, build *gocmd.BuildConfi
return gocmd.Build(cwdParam(recursively), build)
}

// BuildFiles builds specified Go+ files.
// if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
func BuildFiles(files []string, conf *Config, build *gocmd.BuildConfig) (err error) {
files, err = GenGoFiles("", files, conf)
if err != nil {
Expand All @@ -116,6 +128,8 @@ func restoreDirAndMod(old string, mod os.FileMode) {

// -----------------------------------------------------------------------------

// RunDir runs an application from a Go+ package directory.
// if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
func RunDir(dir string, args []string, conf *Config, run *gocmd.RunConfig) (err error) {
_, _, err = GenGo(dir, conf, false)
if err != nil {
Expand All @@ -124,6 +138,8 @@ func RunDir(dir string, args []string, conf *Config, run *gocmd.RunConfig) (err
return gocmd.RunDir(dir, args, run)
}

// RunPkgPath runs an application from a Go+ package.
// if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
func RunPkgPath(pkgPath string, args []string, chDir bool, conf *Config, run *gocmd.RunConfig) (err error) {
localDir, recursively, err := GenGoPkgPath("", pkgPath, conf, true)
if err != nil {
Expand All @@ -140,6 +156,8 @@ func RunPkgPath(pkgPath string, args []string, chDir bool, conf *Config, run *go
return gocmd.RunDir(localDir, args, run)
}

// RunFiles runs an application from specified Go+ files.
// if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
func RunFiles(autogen string, files []string, args []string, conf *Config, run *gocmd.RunConfig) (err error) {
files, err = GenGoFiles(autogen, files, conf)
if err != nil {
Expand All @@ -150,6 +168,8 @@ func RunFiles(autogen string, files []string, args []string, conf *Config, run *

// -----------------------------------------------------------------------------

// TestDir tests a Go+ package directory.
// if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
func TestDir(dir string, conf *Config, test *gocmd.TestConfig) (err error) {
_, _, err = GenGo(dir, conf, true)
if err != nil {
Expand All @@ -158,6 +178,8 @@ func TestDir(dir string, conf *Config, test *gocmd.TestConfig) (err error) {
return gocmd.Test(dir, test)
}

// TestPkgPath tests a Go+ package.
// if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
func TestPkgPath(workDir, pkgPath string, conf *Config, test *gocmd.TestConfig) (err error) {
localDir, recursively, err := GenGoPkgPath(workDir, pkgPath, conf, false)
if err != nil {
Expand All @@ -168,6 +190,8 @@ func TestPkgPath(workDir, pkgPath string, conf *Config, test *gocmd.TestConfig)
return gocmd.Test(cwdParam(recursively), test)
}

// TestFiles tests specified Go+ files.
// if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
func TestFiles(files []string, conf *Config, test *gocmd.TestConfig) (err error) {
files, err = GenGoFiles("", files, conf)
if err != nil {
Expand Down
22 changes: 18 additions & 4 deletions gengo.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ const (

// -----------------------------------------------------------------------------

// GenGo generates gop_autogen.go for a Go+ package directory.
// if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
func GenGo(dir string, conf *Config, genTestPkg bool) (string, bool, error) {
return GenGoEx(dir, conf, genTestPkg, 0)
}

// GenGoEx generates gop_autogen.go for a Go+ package directory.
// if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
func GenGoEx(dir string, conf *Config, genTestPkg bool, flags GenFlags) (string, bool, error) {
recursively := strings.HasSuffix(dir, "/...")
if recursively {
Expand All @@ -65,10 +69,8 @@ func genGoDir(dir string, conf *Config, genTestPkg, recursively bool, flags GenF
if conf == nil {
conf = new(Config)
}
if conf.Context == nil { // clone conf and set Context
confCpy := *conf
confCpy.Context = gox.NewContext()
conf = &confCpy
if conf.Context == nil { // set Context
conf.Context = gox.NewContext()
}
if recursively {
var (
Expand Down Expand Up @@ -210,6 +212,8 @@ const (
modReadonly = 0555
)

// GenGoPkgPath generates gop_autogen.go for a Go+ package.
// if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
func GenGoPkgPath(workDir, pkgPath string, conf *Config, allowExtern bool) (localDir string, recursively bool, err error) {
return GenGoPkgPathEx(workDir, pkgPath, conf, allowExtern, 0)
}
Expand All @@ -227,6 +231,8 @@ func remotePkgPath(pkgPath string, conf *Config, recursively bool, flags GenFlag
return
}

// GenGoPkgPathEx generates gop_autogen.go for a Go+ package.
// if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
func GenGoPkgPathEx(workDir, pkgPath string, conf *Config, allowExtern bool, flags GenFlags) (localDir string, recursively bool, err error) {
recursively = strings.HasSuffix(pkgPath, "/...")
if recursively {
Expand Down Expand Up @@ -268,7 +274,15 @@ func remotePkgPathDo(pkgPath string, doSth func(pkgDir, modDir string), onErr fu

// -----------------------------------------------------------------------------

// GenGoFiles generates gop_autogen.go for specified Go+ files.
// if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
func GenGoFiles(autogen string, files []string, conf *Config) (result []string, err error) {
if conf == nil {
conf = new(Config)
}
if conf.Context == nil { // set Context
conf.Context = gox.NewContext()
}
if autogen == "" {
autogen = "gop_autogen.go"
if len(files) == 1 {
Expand Down

0 comments on commit 10e379d

Please sign in to comment.