From 6837d851855688f3cf1dcae6eaaf52911c3afa73 Mon Sep 17 00:00:00 2001 From: Hana Kim Date: Tue, 14 Jun 2016 11:11:41 -0400 Subject: [PATCH] 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 --- cmd/gomobile/build.go | 2 ++ cmd/gomobile/clean.go | 32 ++++++++++++++++++++++++++++++++ cmd/gomobile/init.go | 2 +- cmd/gomobile/main.go | 1 + 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 cmd/gomobile/clean.go diff --git a/cmd/gomobile/build.go b/cmd/gomobile/build.go index 9584ea5..a1e308b 100644 --- a/cmd/gomobile/build.go +++ b/cmd/gomobile/build.go @@ -253,6 +253,8 @@ func init() { addBuildFlags(cmdBind) addBuildFlagsNVXWork(cmdBind) + + addBuildFlagsNVXWork(cmdClean) } func goBuild(src string, env []string, args ...string) error { diff --git a/cmd/gomobile/clean.go b/cmd/gomobile/clean.go new file mode 100644 index 0000000..1c0e348 --- /dev/null +++ b/cmd/gomobile/clean.go @@ -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) +} diff --git a/cmd/gomobile/init.go b/cmd/gomobile/init.go index ef52e19..94fa759 100644 --- a/cmd/gomobile/init.go +++ b/cmd/gomobile/init.go @@ -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 diff --git a/cmd/gomobile/main.go b/cmd/gomobile/main.go index b17d93d..4e0e184 100644 --- a/cmd/gomobile/main.go +++ b/cmd/gomobile/main.go @@ -174,6 +174,7 @@ var commands = []*command{ // TODO(crawshaw): cmdRun cmdBind, cmdBuild, + cmdClean, cmdInit, cmdInstall, cmdVersion,