Generate inline headers for use declarations

This commit is contained in:
Nigel Tao committed 2017-12-02 14:54:58 +11:00
1 parent c5b5efd7c8
commit 9867cd5e3a
6 files changed
+549 -16

No files matched your search

+26
View File
@@ -18,6 +18,14 @@
// It also holds functions to parse and validate these flag values.
package commonflags
import (
"errors"
"go/build"
"os"
"path"
"path/filepath"
)
const (
CcompilersDefault = "clang,gcc"
CcompilersUsage = `comma-separated list of C compilers, e.g. "clang,gcc"`
@@ -34,6 +42,9 @@ const (
RepsUsage = `the number of repetitions per benchmark`
)
// TODO: do IsAlphaNumericIsh and IsValidUsePath belong in a separate package,
// such as lang/validate? Perhaps together with token.Unescape?
// IsAlphaNumericIsh returns whether s contains only ASCII alpha-numerics and a
// limited set of punctuation such as commas and slahes, but not containing
// e.g. spaces, semi-colons, colons or backslashes.
@@ -51,3 +62,18 @@ func IsAlphaNumericIsh(s string) bool {
}
return true
}
func IsValidUsePath(s string) bool {
return s == path.Clean(s) && s != "" && s[0] != '.' && s[0] != '/'
}
func WuffsRoot() (string, error) {
// TODO: look for a WUFFSROOT environment variable?
for _, p := range filepath.SplitList(build.Default.GOPATH) {
p = filepath.Join(p, "src", "github.com", "google", "wuffs")
if o, err := os.Stat(p); err == nil && o.IsDir() {
return p, nil
}
}
return "", errors.New("could not find Wuffs root directory")
}