@@ -27,7 +27,6 @@ import (
27
27
// -----------------------------------------------------------------------------
28
28
29
29
// InstallDir installs a Go+ package directory.
30
- // if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
31
30
func InstallDir (dir string , conf * Config , install * gocmd.InstallConfig ) (err error ) {
32
31
_ , _ , err = GenGo (dir , conf , false )
33
32
if err != nil {
@@ -37,7 +36,6 @@ func InstallDir(dir string, conf *Config, install *gocmd.InstallConfig) (err err
37
36
}
38
37
39
38
// InstallPkgPath installs a Go+ package.
40
- // if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
41
39
func InstallPkgPath (workDir , pkgPath string , conf * Config , install * gocmd.InstallConfig ) (err error ) {
42
40
localDir , recursively , err := GenGoPkgPath (workDir , pkgPath , conf , true )
43
41
if err != nil {
@@ -56,7 +54,6 @@ func cwdParam(recursively bool) string {
56
54
}
57
55
58
56
// InstallFiles installs specified Go+ files.
59
- // if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
60
57
func InstallFiles (files []string , conf * Config , install * gocmd.InstallConfig ) (err error ) {
61
58
files , err = GenGoFiles ("" , files , conf )
62
59
if err != nil {
@@ -80,7 +77,6 @@ func chdir(dir string) string {
80
77
// -----------------------------------------------------------------------------
81
78
82
79
// BuildDir builds a Go+ package directory.
83
- // if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
84
80
func BuildDir (dir string , conf * Config , build * gocmd.BuildConfig ) (err error ) {
85
81
_ , _ , err = GenGo (dir , conf , false )
86
82
if err != nil {
@@ -90,7 +86,6 @@ func BuildDir(dir string, conf *Config, build *gocmd.BuildConfig) (err error) {
90
86
}
91
87
92
88
// BuildPkgPath builds a Go+ package.
93
- // if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
94
89
func BuildPkgPath (workDir , pkgPath string , conf * Config , build * gocmd.BuildConfig ) (err error ) {
95
90
localDir , recursively , err := GenGoPkgPath (workDir , pkgPath , conf , false )
96
91
if err != nil {
@@ -102,7 +97,6 @@ func BuildPkgPath(workDir, pkgPath string, conf *Config, build *gocmd.BuildConfi
102
97
}
103
98
104
99
// BuildFiles builds specified Go+ files.
105
- // if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
106
100
func BuildFiles (files []string , conf * Config , build * gocmd.BuildConfig ) (err error ) {
107
101
files , err = GenGoFiles ("" , files , conf )
108
102
if err != nil {
@@ -128,18 +122,24 @@ func restoreDirAndMod(old string, mod os.FileMode) {
128
122
129
123
// -----------------------------------------------------------------------------
130
124
125
+ // If no go.mod and used Go+, use GOPROOT as buildDir.
126
+ func getBuildDir (conf * Config ) string {
127
+ if conf != nil && conf .GopDeps != nil && * conf .GopDeps != 0 {
128
+ return conf .Gop .Root
129
+ }
130
+ return ""
131
+ }
132
+
131
133
// RunDir runs an application from a Go+ package directory.
132
- // if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
133
134
func RunDir (dir string , args []string , conf * Config , run * gocmd.RunConfig ) (err error ) {
134
135
_ , _ , err = GenGo (dir , conf , false )
135
136
if err != nil {
136
137
return errors .NewWith (err , `GenGo(dir, conf, false)` , - 2 , "gop.GenGo" , dir , conf , false )
137
138
}
138
- return gocmd .RunDir (dir , args , run )
139
+ return gocmd .RunDir (getBuildDir ( conf ), dir , args , run )
139
140
}
140
141
141
142
// RunPkgPath runs an application from a Go+ package.
142
- // if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
143
143
func RunPkgPath (pkgPath string , args []string , chDir bool , conf * Config , run * gocmd.RunConfig ) (err error ) {
144
144
localDir , recursively , err := GenGoPkgPath ("" , pkgPath , conf , true )
145
145
if err != nil {
@@ -153,23 +153,21 @@ func RunPkgPath(pkgPath string, args []string, chDir bool, conf *Config, run *go
153
153
defer os .Chdir (old )
154
154
localDir = "."
155
155
}
156
- return gocmd .RunDir (localDir , args , run )
156
+ return gocmd .RunDir ("" , localDir , args , run )
157
157
}
158
158
159
159
// RunFiles runs an application from specified Go+ files.
160
- // if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
161
160
func RunFiles (autogen string , files []string , args []string , conf * Config , run * gocmd.RunConfig ) (err error ) {
162
161
files , err = GenGoFiles (autogen , files , conf )
163
162
if err != nil {
164
163
return errors .NewWith (err , `GenGoFiles(autogen, files, conf)` , - 2 , "gop.GenGoFiles" , autogen , files , conf )
165
164
}
166
- return gocmd .RunFiles (files , args , run )
165
+ return gocmd .RunFiles (getBuildDir ( conf ), files , args , run )
167
166
}
168
167
169
168
// -----------------------------------------------------------------------------
170
169
171
170
// TestDir tests a Go+ package directory.
172
- // if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
173
171
func TestDir (dir string , conf * Config , test * gocmd.TestConfig ) (err error ) {
174
172
_ , _ , err = GenGo (dir , conf , true )
175
173
if err != nil {
@@ -179,7 +177,6 @@ func TestDir(dir string, conf *Config, test *gocmd.TestConfig) (err error) {
179
177
}
180
178
181
179
// TestPkgPath tests a Go+ package.
182
- // if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
183
180
func TestPkgPath (workDir , pkgPath string , conf * Config , test * gocmd.TestConfig ) (err error ) {
184
181
localDir , recursively , err := GenGoPkgPath (workDir , pkgPath , conf , false )
185
182
if err != nil {
@@ -191,7 +188,6 @@ func TestPkgPath(workDir, pkgPath string, conf *Config, test *gocmd.TestConfig)
191
188
}
192
189
193
190
// TestFiles tests specified Go+ files.
194
- // if conf != nil && conf.Context == nil, it will be set with `gox.NewContext()`.
195
191
func TestFiles (files []string , conf * Config , test * gocmd.TestConfig ) (err error ) {
196
192
files , err = GenGoFiles ("" , files , conf )
197
193
if err != nil {
0 commit comments