mirror of https://github.com/perkeep/perkeep.git
Add -fileembed-package and -all flags
The -fileembed-package flag makes genfileembed play nicely with goven. If you use goven to vendorize fileembed, the fileembed package path changes (to be relative to the current project). With -fileembed-package, you can make the generated code import the correct (vendorized) fileembed package. The -all flag forces processing of all files, not just modified files. This is useful when changing -import-prefix, when working on a filesystem with unreliable mtimes, or when being neurotic/defensive in build scripts. Addresses https://code.google.com/p/camlistore/issues/detail?id=137 Change-Id: I54215429dabd02bc1fa72c6718e1cabccb1cffaf
This commit is contained in:
parent
481bdf346a
commit
f72c466501
|
@ -40,8 +40,20 @@ const (
|
||||||
zRatio = 0.5
|
zRatio = 0.5
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func usage() {
|
||||||
|
fmt.Fprintf(os.Stderr, "usage: genfileembed [flags] [<dir>]\n")
|
||||||
|
flag.PrintDefaults()
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
var processAll bool
|
||||||
|
flag.BoolVar(&processAll, "all", false, "process all files (if false, only process modified files)")
|
||||||
|
var fileEmbedPkgPath string
|
||||||
|
flag.StringVar(&fileEmbedPkgPath, "fileembed-package", "camlistore.org/pkg/fileembed", "the Go package name for fileembed. If you have vendored fileembed (e.g. with goven), you can use this flag to ensure that generated code imports the vendored package.")
|
||||||
|
flag.Usage = usage
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
dir := "."
|
dir := "."
|
||||||
switch flag.NArg() {
|
switch flag.NArg() {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -51,8 +63,7 @@ func main() {
|
||||||
log.Fatalf("chdir(%q) = %v", dir, err)
|
log.Fatalf("chdir(%q) = %v", dir, err)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(os.Stderr, "usage: genfileembed [<dir>]\n")
|
flag.Usage()
|
||||||
os.Exit(2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pkgName, filePattern, err := parseFileEmbed()
|
pkgName, filePattern, err := parseFileEmbed()
|
||||||
|
@ -67,7 +78,7 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
efi, err := os.Stat(embedName)
|
efi, err := os.Stat(embedName)
|
||||||
if err == nil && !efi.ModTime().Before(fi.ModTime()) {
|
if err == nil && !efi.ModTime().Before(fi.ModTime()) && !processAll {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Printf("Updating %s (package %s)", filepath.Join(dir, embedName), pkgName)
|
log.Printf("Updating %s (package %s)", filepath.Join(dir, embedName), pkgName)
|
||||||
|
@ -93,7 +104,7 @@ func main() {
|
||||||
fmt.Fprintf(&b, "// DO NOT EDIT.\n\n")
|
fmt.Fprintf(&b, "// DO NOT EDIT.\n\n")
|
||||||
fmt.Fprintf(&b, "package %s\n\n", pkgName)
|
fmt.Fprintf(&b, "package %s\n\n", pkgName)
|
||||||
fmt.Fprintf(&b, "import \"time\"\n\n")
|
fmt.Fprintf(&b, "import \"time\"\n\n")
|
||||||
fmt.Fprintf(&b, "import \"camlistore.org/pkg/fileembed\"\n\n")
|
fmt.Fprintf(&b, "import \""+fileEmbedPkgPath+"\"\n\n")
|
||||||
fmt.Fprintf(&b, "func init() {\n\tFiles.Add(%q, %d, %s(%s), time.Unix(0, %d));\n}\n",
|
fmt.Fprintf(&b, "func init() {\n\tFiles.Add(%q, %d, %s(%s), time.Unix(0, %d));\n}\n",
|
||||||
fileName, fileSize, byteStreamType, qb, fi.ModTime().UnixNano())
|
fileName, fileSize, byteStreamType, qb, fi.ModTime().UnixNano())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue