cmd/gomobile: introduce the 'clean' command
The command deletes all files under $GOPATH/pkg/gomobile dir that keeps downloaded files and precompiled objects during the last gomobile init run. 'gomobile clean' will be suggested in case of gomobile init failures due to downloaded file hash mismatch. For golang/go#15973 Change-Id: Ie9d3cfa7aef9d68931fd68f7b58d1a18c9d4b3b8 Reviewed-on: https://go-review.googlesource.com/24074 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
1decf4c941
commit
6837d85185
@ -253,6 +253,8 @@ func init() {
|
||||
|
||||
addBuildFlags(cmdBind)
|
||||
addBuildFlagsNVXWork(cmdBind)
|
||||
|
||||
addBuildFlagsNVXWork(cmdClean)
|
||||
}
|
||||
|
||||
func goBuild(src string, env []string, args ...string) error {
|
||||
|
32
cmd/gomobile/clean.go
Normal file
32
cmd/gomobile/clean.go
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright 2015 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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var cmdClean = &command{
|
||||
run: runClean,
|
||||
Name: "clean",
|
||||
Usage: "",
|
||||
Short: "remove object files and cached gomobile files",
|
||||
Long: `
|
||||
Clean removes object files and cached NDK files downloaded by gomobile init
|
||||
`,
|
||||
}
|
||||
|
||||
func runClean(cmd *command) (err error) {
|
||||
gopaths := filepath.SplitList(goEnv("GOPATH"))
|
||||
if len(gopaths) == 0 {
|
||||
return fmt.Errorf("GOPATH is not set")
|
||||
}
|
||||
gomobilepath = filepath.Join(gopaths[0], "pkg/gomobile")
|
||||
if buildX {
|
||||
fmt.Fprintln(xout, "GOMOBILE="+gomobilepath)
|
||||
}
|
||||
return removeAll(gomobilepath)
|
||||
}
|
@ -566,7 +566,7 @@ func fetch(url string) (dst string, err error) {
|
||||
}
|
||||
hash := hex.EncodeToString(hashw.Sum(nil))
|
||||
if fetchHashes[name] != hash {
|
||||
return "", fmt.Errorf("sha256 for %q: %v, want %v", name, hash, fetchHashes[name])
|
||||
return "", fmt.Errorf("sha256 for %q: %v, want %v. Try 'gomobile clean'", name, hash, fetchHashes[name])
|
||||
}
|
||||
if err = os.Rename(f.Name(), dst); err != nil {
|
||||
return "", err
|
||||
|
@ -174,6 +174,7 @@ var commands = []*command{
|
||||
// TODO(crawshaw): cmdRun
|
||||
cmdBind,
|
||||
cmdBuild,
|
||||
cmdClean,
|
||||
cmdInit,
|
||||
cmdInstall,
|
||||
cmdVersion,
|
||||
|
Loading…
x
Reference in New Issue
Block a user