@@ -323,17 +323,50 @@ func (Build) Binary() error {
323
323
}
324
324
325
325
// Clean up dev environment.
326
- func (Build ) Clean () {
327
- os .RemoveAll (buildDir )
326
+ func (Build ) Clean () error {
327
+ absBuildDir , err := filepath .Abs (buildDir )
328
+ if err != nil {
329
+ return fmt .Errorf ("cannot get absolute path of build dir: %w" , err )
330
+ }
331
+ if err := os .RemoveAll (absBuildDir ); err != nil {
332
+ return fmt .Errorf ("cannot remove build dir '%s': %w" , absBuildDir , err )
333
+ }
334
+
335
+ testBinariesPath , err := getTestBinariesPath ()
336
+ if err != nil {
337
+ return fmt .Errorf ("cannot remove test binaries: %w" , err )
338
+ }
339
+
340
+ if mg .Verbose () {
341
+ fmt .Println ("removed" , absBuildDir )
342
+ for _ , b := range testBinariesPath {
343
+ fmt .Println ("removed" , b )
344
+ }
345
+ }
346
+
347
+ return nil
328
348
}
329
349
330
- // TestBinaries build the required binaries for the test suite.
331
- func (Build ) TestBinaries () error {
332
- wd , _ := os .Getwd ()
350
+ func getTestBinariesPath () ([]string , error ) {
351
+ wd , err := os .Getwd ()
352
+ if err != nil {
353
+ return nil , fmt .Errorf ("could not get working directory: %w" , err )
354
+ }
355
+
333
356
testBinaryPkgs := []string {
334
357
filepath .Join (wd , "pkg" , "component" , "fake" , "component" ),
335
358
filepath .Join (wd , "internal" , "pkg" , "agent" , "install" , "testblocking" ),
336
359
}
360
+ return testBinaryPkgs , nil
361
+ }
362
+
363
+ // TestBinaries build the required binaries for the test suite.
364
+ func (Build ) TestBinaries () error {
365
+ testBinaryPkgs , err := getTestBinariesPath ()
366
+ if err != nil {
367
+ fmt .Errorf ("cannot build test binaries: %w" , err )
368
+ }
369
+
337
370
for _ , pkg := range testBinaryPkgs {
338
371
binary := filepath .Base (pkg )
339
372
if runtime .GOOS == "windows" {
@@ -809,6 +842,10 @@ func (Cloud) Push() error {
809
842
return nil
810
843
}
811
844
845
+ func Clean () {
846
+ mg .Deps (devtools .Clean , Build .Clean )
847
+ }
848
+
812
849
func dockerCommitHash () string {
813
850
commit , err := devtools .CommitHash ()
814
851
if err == nil && len (commit ) > commitLen {
@@ -2973,8 +3010,6 @@ func stringPrompt(prompt string) (string, error) {
2973
3010
return s , nil
2974
3011
}
2975
3012
}
2976
-
2977
- return "" , nil
2978
3013
}
2979
3014
2980
3015
func writeFile (name string , data []byte , perm os.FileMode ) error {
0 commit comments