-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Generate Bindata iff TAGS="bindata" and not up-to-date #10004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
aec9553
86c3b1a
138bc6f
c8a48ed
ad7d198
1f68585
440a99d
4f2ab2b
f9835d6
7a4acca
c930141
ee57d80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//+build bindata | ||
|
||
package options | ||
|
||
//go:generate go run -mod=vendor ../../scripts/generate-bindata.go ../../options options bindata.go |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//+build bindata | ||
|
||
package public | ||
|
||
//go:generate go run -mod=vendor ../../scripts/generate-bindata.go ../../public public bindata.go |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"bytes" | ||
"crypto/sha1" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
|
||
"github.com/shurcooL/vfsgen" | ||
) | ||
|
||
func needsUpdate(dir string, filename string) (bool, []byte) { | ||
needRegen := false | ||
_, err := os.Stat(filename) | ||
if err != nil { | ||
needRegen = true | ||
} | ||
|
||
oldHash, err := ioutil.ReadFile(filename + ".hash") | ||
if err != nil { | ||
oldHash = []byte{} | ||
} | ||
|
||
hasher := sha1.New() | ||
|
||
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, we're basically doing make's job. 😆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup. That's what you get when you mix two competing build systems ... |
||
if err != nil { | ||
return err | ||
} | ||
_, _ = hasher.Write([]byte(info.Name())) | ||
_, _ = hasher.Write([]byte(info.ModTime().String())) | ||
_, _ = hasher.Write([]byte(strconv.FormatInt(info.Size(), 16))) | ||
return nil | ||
}) | ||
if err != nil { | ||
return true, oldHash | ||
} | ||
|
||
newHash := hasher.Sum([]byte{}) | ||
|
||
if bytes.Compare(oldHash, newHash) != 0 { | ||
|
||
return true, newHash | ||
} | ||
|
||
return needRegen, newHash | ||
} | ||
|
||
func main() { | ||
if len(os.Args) != 4 { | ||
log.Fatal("Insufficient number of arguments. Need: directory packageName filename") | ||
} | ||
|
||
dir, packageName, filename := os.Args[1], os.Args[2], os.Args[3] | ||
|
||
update, newHash := needsUpdate(dir, filename) | ||
|
||
if !update { | ||
fmt.Printf("bindata for %s already up-to-date\n", packageName) | ||
return | ||
} | ||
|
||
fmt.Printf("generating bindata for %s\n", packageName) | ||
var fsTemplates http.FileSystem = http.Dir(dir) | ||
err := vfsgen.Generate(fsTemplates, vfsgen.Options{ | ||
PackageName: packageName, | ||
BuildTags: "bindata", | ||
VariableName: "Assets", | ||
Filename: filename, | ||
}) | ||
if err != nil { | ||
log.Fatalf("%v\n", err) | ||
} | ||
_ = ioutil.WriteFile(filename+".hash", newHash, 0666) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.