tools: Shuffle go code into an idiomatic tree

main packages usually go under a `cmd` directory.
Hoist utility packages to the root `src` directroy so they can be shared.

Change-Id: I0c221f6cd39980f5c202c030cd5134d775533efa
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50901
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
diff --git a/.gitignore b/.gitignore
index 00f82a1..56d35271 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,3 +22,4 @@
 third_party/spirv-headers
 third_party/spirv-tools
 tools/clang
+tools/bin
diff --git a/tools/fix-tests b/tools/fix-tests
index ad5915d..445b5fe 100755
--- a/tools/fix-tests
+++ b/tools/fix-tests
@@ -15,6 +15,8 @@
 
 # See https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
 
+set -e # Fail on any error.
+
 if [ ! -x "$(which go)" ] ; then
     echo "error: go needs to be on \$PATH to use $0"
     exit 1
@@ -22,9 +24,12 @@
 
 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
 ROOT_DIR="$( cd "${SCRIPT_DIR}/.." >/dev/null 2>&1 && pwd )"
+BINARY="${SCRIPT_DIR}/bin/fix-tests"
 
-TARGET_EXE="$(realpath $1)"
+# Rebuild the binary.
+# Note, go caches build artifacts, so this is quick for repeat calls
+pushd "${SCRIPT_DIR}/src/cmd/fix-tests" > /dev/null
+    go build -o "${BINARY}" main.go
+popd > /dev/null
 
-pushd ${SCRIPT_DIR}/src/fix-tests
-go run fix-tests.go "${TARGET_EXE}"
-popd
+"${BINARY}" "$@"
diff --git a/tools/lint b/tools/lint
index e61fc83..1b20be8 100755
--- a/tools/lint
+++ b/tools/lint
@@ -28,11 +28,11 @@
 
 if command -v go &> /dev/null; then
     # Go is installed. Run cpplint in parallel for speed wins
-    go run $SCRIPT_DIR/src/run-parallel/main.go \
-         --only-print-failures                  \
-         cpplint.py                             \
-         --root=$ROOT_DIR                       \
-         --filter="$FILTER"                     \
+    go run $SCRIPT_DIR/src/cmd/run-parallel/main.go \
+         --only-print-failures                      \
+         cpplint.py                                 \
+         --root=$ROOT_DIR                           \
+         --filter="$FILTER"                         \
          $ -- $FILES
 else
     cpplint.py --root=$ROOT_DIR --filter="$FILTER" $FILES
diff --git a/tools/src/fix-tests/fix-tests.go b/tools/src/cmd/fix-tests/main.go
similarity index 98%
rename from tools/src/fix-tests/fix-tests.go
rename to tools/src/cmd/fix-tests/main.go
index 9b80381..8865270 100644
--- a/tools/src/fix-tests/fix-tests.go
+++ b/tools/src/cmd/fix-tests/main.go
@@ -26,7 +26,7 @@
 	"regexp"
 	"strings"
 
-	"dawn.googlesource.com/tint/tools/src/fix-tests/substr"
+	"dawn.googlesource.com/tint/tools/src/substr"
 )
 
 func main() {
diff --git a/tools/src/run-parallel/main.go b/tools/src/cmd/run-parallel/main.go
similarity index 100%
rename from tools/src/run-parallel/main.go
rename to tools/src/cmd/run-parallel/main.go
diff --git a/tools/src/trim-includes/config.cfg b/tools/src/cmd/trim-includes/config.cfg
similarity index 100%
rename from tools/src/trim-includes/config.cfg
rename to tools/src/cmd/trim-includes/config.cfg
diff --git a/tools/src/trim-includes/main.go b/tools/src/cmd/trim-includes/main.go
similarity index 98%
rename from tools/src/trim-includes/main.go
rename to tools/src/cmd/trim-includes/main.go
index 0c411c3..ce195d7 100644
--- a/tools/src/trim-includes/main.go
+++ b/tools/src/cmd/trim-includes/main.go
@@ -35,7 +35,7 @@
 	"sync"
 	"time"
 
-	"dawn.googlesource.com/tint/tools/src/trim-includes/glob"
+	"dawn.googlesource.com/tint/tools/src/glob"
 )
 
 var (
diff --git a/tools/src/trim-includes/glob/glob.go b/tools/src/glob/glob.go
similarity index 98%
rename from tools/src/trim-includes/glob/glob.go
rename to tools/src/glob/glob.go
index 8a9a9bb..0f109d4 100644
--- a/tools/src/trim-includes/glob/glob.go
+++ b/tools/src/glob/glob.go
@@ -23,7 +23,7 @@
 	"os"
 	"path/filepath"
 
-	"dawn.googlesource.com/tint/tools/src/trim-includes/match"
+	"dawn.googlesource.com/tint/tools/src/match"
 )
 
 // Scan walks all files and subdirectories from root, returning those
diff --git a/tools/src/trim-includes/match/match.go b/tools/src/match/match.go
similarity index 100%
rename from tools/src/trim-includes/match/match.go
rename to tools/src/match/match.go
diff --git a/tools/src/trim-includes/match/match_test.go b/tools/src/match/match_test.go
similarity index 100%
rename from tools/src/trim-includes/match/match_test.go
rename to tools/src/match/match_test.go
diff --git a/tools/src/fix-tests/substr/substr.go b/tools/src/substr/substr.go
similarity index 100%
rename from tools/src/fix-tests/substr/substr.go
rename to tools/src/substr/substr.go
diff --git a/tools/src/fix-tests/substr/substr_test.go b/tools/src/substr/substr_test.go
similarity index 100%
rename from tools/src/fix-tests/substr/substr_test.go
rename to tools/src/substr/substr_test.go
diff --git a/tools/src/trim-includes/build.sh b/tools/src/trim-includes/build.sh
deleted file mode 100755
index 3b6faeb..0000000
--- a/tools/src/trim-includes/build.sh
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/bash
-
-set -e # Fail on any error.
-
-SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
-ROOT_DIR="$( cd "${SCRIPT_DIR}/../.." >/dev/null 2>&1 && pwd )"
-
-cd $ROOT_DIR
-autoninja -C out/Debug
-cd $ROOT_DIR/build
-ninja
diff --git a/tools/trim-includes b/tools/trim-includes
new file mode 100755
index 0000000..cc685f9
--- /dev/null
+++ b/tools/trim-includes
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+# Copyright 2021 The Tint Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -e # Fail on any error.
+
+if [ ! -x "$(which go)" ] ; then
+    echo "error: go needs to be on \$PATH to use $0"
+    exit 1
+fi
+
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
+ROOT_DIR="$( cd "${SCRIPT_DIR}/.." >/dev/null 2>&1 && pwd )"
+BINARY="${SCRIPT_DIR}/bin/trim-includes"
+
+# Rebuild the binary.
+# Note, go caches build artifacts, so this is quick for repeat calls
+pushd "${SCRIPT_DIR}/src/cmd/trim-includes" > /dev/null
+    go build -o "${BINARY}" main.go
+popd > /dev/null
+
+"${BINARY}" "$@"