tools: Fixes for intrinsic-gen on windows

Fix slash-related issues.

Change-Id: I618649578746450df7cb2dcd372c5a778eb719ba
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/56776
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/tools/src/cmd/intrinsic-gen/main.go b/tools/src/cmd/intrinsic-gen/main.go
index 8be2966..0a55fdd 100644
--- a/tools/src/cmd/intrinsic-gen/main.go
+++ b/tools/src/cmd/intrinsic-gen/main.go
@@ -106,7 +106,7 @@
 		writeFile := func(relpath, body string) error {
 			// Write the common file header
 			sb := strings.Builder{}
-			sb.WriteString(fmt.Sprintf(header, relTmplPath, defProjectRelPath))
+			sb.WriteString(fmt.Sprintf(header, filepath.ToSlash(relTmplPath), filepath.ToSlash(defProjectRelPath)))
 			sb.WriteString(body)
 			content := sb.String()
 			abspath := filepath.Join(filepath.Dir(tmplPath), relpath)
diff --git a/tools/src/fileutils/fileutils_common.go b/tools/src/fileutils/fileutils_common.go
new file mode 100644
index 0000000..de6a29f
--- /dev/null
+++ b/tools/src/fileutils/fileutils_common.go
@@ -0,0 +1,45 @@
+// 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.
+
+// Package fileutils contains utility functions for files
+package fileutils
+
+import (
+	"path/filepath"
+	"runtime"
+)
+
+// GoSourcePath returns the absolute path to the .go file that calls the
+// function
+func GoSourcePath() string {
+	_, filename, _, ok := runtime.Caller(1)
+	if !ok {
+		panic("No caller information")
+	}
+	path, err := filepath.Abs(filename)
+	if err != nil {
+		panic(err)
+	}
+	return path
+}
+
+// ProjectRoot returns the path to the tint project root
+func ProjectRoot() string {
+	toolRoot := filepath.Dir(GoSourcePath())
+	root, err := filepath.Abs(filepath.Join(toolRoot, "../../.."))
+	if err != nil {
+		panic(err)
+	}
+	return root
+}
diff --git a/tools/src/fileutils/fileutils_other.go b/tools/src/fileutils/fileutils_other.go
index 9c20ea6..85c9e5f 100644
--- a/tools/src/fileutils/fileutils_other.go
+++ b/tools/src/fileutils/fileutils_other.go
@@ -19,8 +19,6 @@
 
 import (
 	"os"
-	"path/filepath"
-	"runtime"
 )
 
 // IsExe returns true if the file at path is an executable
@@ -31,27 +29,3 @@
 	}
 	return s.Mode()&0100 != 0
 }
-
-// GoSourcePath returns the absolute path to the .go file that calls the
-// function
-func GoSourcePath() string {
-	_, filename, _, ok := runtime.Caller(1)
-	if !ok {
-		panic("No caller information")
-	}
-	path, err := filepath.Abs(filename)
-	if err != nil {
-		panic(err)
-	}
-	return path
-}
-
-// ProjectRoot returns the path to the tint project root
-func ProjectRoot() string {
-	toolRoot := filepath.Dir(GoSourcePath())
-	root, err := filepath.Abs(filepath.Join(toolRoot, "../../.."))
-	if err != nil {
-		panic(err)
-	}
-	return root
-}
diff --git a/tools/src/glob/glob.go b/tools/src/glob/glob.go
index e4c8327..b9790b2 100644
--- a/tools/src/glob/glob.go
+++ b/tools/src/glob/glob.go
@@ -192,6 +192,7 @@
 	if err != nil {
 		return false
 	}
+	relPath = filepath.ToSlash(relPath) // Canonicalize
 
 	res := false
 	for _, rule := range c.Paths {