Created
July 1, 2017 08:04
-
-
Save excavador/95da1b57bf2310cd185073db870048e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SIGNATURE__API = $(shell find api -type f -name "*.yaml" | sort | bin/sign | bin/update-if-different $(SIGNATURE_DIRECTORY)/api) | |
$(MAKE_DIRECTORY)/api: $(SIGNATURE__API) bin/dsl-api | |
bin/dsl-api -strict -root api/gen.a.root.yaml | |
@touch $@ | |
api: $(MAKE_DIRECTORY)/api | |
################################################################################ | |
# bin/gb | |
################################################################################ | |
bin/gb-$(HOST_GO_OS_ARCH_SUFFIX): bin/go $(SIGNATURE__GO__VENDOR) | |
(cd vendor && GOOS=$(HOST_GOOS) GOARCH=$(HOST_GOARCH) ../bin/go install github.com/constabulary/gb/cmd/gb) | |
cp vendor/bin/gb bin/gb-$(HOST_GO_OS_ARCH_SUFFIX) | |
bin/gb: bin/gb-$(HOST_GO_OS_ARCH_SUFFIX) make/03.generate.os.arch.switcher.sh | |
make/03.generate.os.arch.switcher.sh gb | |
clean-bin-gb: | |
$(info [$@]) | |
rm -f bin/gb* | |
################################################################################ | |
# bin/sign | |
################################################################################ | |
bin/sign-$(HOST_GO_OS_ARCH_SUFFIX): bin/gb src/cmd/make/sign/main.go | |
GOOS=$(HOST_GOOS) GOARCH=$(HOST_GOARCH) bin/gb build cmd/make/sign | |
@touch $@ | |
bin/sign: bin/sign-$(HOST_GO_OS_ARCH_SUFFIX) make/03.generate.os.arch.switcher.sh | |
GOOS=$(HOST_GOOS) GOARCH=$(HOST_GOARCH) make/03.generate.os.arch.switcher.sh $(@F) | |
tool: bin/sign | |
clean-bin-sign: | |
$(info [$@]) | |
rm -f bin/sign* | |
################################################################################ | |
# bin/update-if-different | |
################################################################################ | |
bin/update-if-different-$(HOST_GO_OS_ARCH_SUFFIX): bin/gb src/cmd/make/update-if-different/main.go | |
GOOS=$(HOST_GOOS) GOARCH=$(HOST_GOARCH) bin/gb build cmd/make/update-if-different | |
@touch $@ | |
bin/update-if-different: bin/update-if-different-$(HOST_GO_OS_ARCH_SUFFIX) make/03.generate.os.arch.switcher.sh | |
GOOS=$(HOST_GOOS) GOARCH=$(HOST_GOARCH) make/03.generate.os.arch.switcher.sh $(@F) | |
tool: bin/update-if-different | |
clean-bin-update-if-different: | |
$(info [$@]) | |
rm -f bin/update-if-different* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"crypto/md5" | |
"flag" | |
"fmt" | |
"io/ioutil" | |
"os" | |
) | |
func Usage() { | |
fmt.Fprintf(os.Stderr, `Usage: %s | |
tool generates <signature-file> of source of files | |
1. read file path list from stdin | |
2. read content of every file and accumulate MD5 | |
3. print result MD5 to stdout | |
`, os.Args[0]) | |
} | |
func main() { | |
flag.Usage = Usage | |
flag.Parse() | |
if flag.NArg() != 0 { | |
flag.Usage() | |
os.Exit(1) | |
} | |
sum := md5.New() | |
scanner := bufio.NewScanner(os.Stdin) | |
for scanner.Scan() { | |
path := scanner.Text() | |
if content, err := ioutil.ReadFile(path); err != nil { | |
fmt.Fprintf(os.Stderr, "read input '%s' problem %s\n", path, err) | |
// TODO: translate error to suitable exit code | |
os.Exit(1) | |
} else { | |
sum.Write([]byte(path)) | |
sum.Write(content) | |
} | |
} | |
fmt.Fprintf(os.Stdout, "%x\n", sum.Sum(nil)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"io/ioutil" | |
"os" | |
"path/filepath" | |
) | |
func Usage() { | |
fmt.Fprintf(os.Stderr, `Usage: %s <marker-file> | |
tool update <marker-file> from stdin if different | |
`, os.Args[0]) | |
} | |
func main() { | |
var ( | |
content []byte | |
previous string | |
err error | |
actual string | |
) | |
flag.Usage = Usage | |
flag.Parse() | |
if flag.NArg() != 1 { | |
flag.Usage() | |
os.Exit(1) | |
} | |
target := flag.Arg(0) | |
if content, err = ioutil.ReadFile(target); err == nil { | |
previous = string(content) | |
} | |
if content, err = ioutil.ReadAll(os.Stdin); err == nil { | |
actual = string(content) | |
} else { | |
fmt.Fprintf(os.Stderr, "read STDIN problem %s\n", err) | |
// TODO: translate error to suitable exit code | |
os.Exit(1) | |
} | |
parent := filepath.Dir(target) | |
if err := os.MkdirAll(parent, 0750); err != nil { | |
fmt.Fprintf(os.Stderr, "create parent directory '%s' problem %s\n", parent, err) | |
// TODO: translate error to suitable exit code | |
os.Exit(1) | |
} | |
if actual != previous { | |
if err := ioutil.WriteFile(target, []byte(actual), 0664); err != nil { | |
fmt.Fprintf(os.Stderr, "write <signature-file> '%s' problem %s\n", target, err) | |
// TODO: translate error to suitable exit code | |
os.Exit(1) | |
} | |
} | |
fmt.Fprintf(os.Stdout, "%s", target) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment