mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
clean up Makefile
This commit is contained in:
parent
cd3f0e37b4
commit
9e38d0f6b6
6 changed files with 10 additions and 1507 deletions
85
Makefile
85
Makefile
|
|
@ -1,12 +1,6 @@
|
||||||
# This Makefile is meant to be used by people that do not usually work
|
.PHONY: XDC XDC-cross evm all test clean
|
||||||
# with Go source code. If you know what GOPATH is then you probably
|
|
||||||
# don't need to bother with make.
|
|
||||||
|
|
||||||
.PHONY: XDC android ios XDC-cross swarm evm all test clean
|
|
||||||
.PHONY: XDC-linux XDC-linux-386 XDC-linux-amd64 XDC-linux-mips64 XDC-linux-mips64le
|
.PHONY: XDC-linux XDC-linux-386 XDC-linux-amd64 XDC-linux-mips64 XDC-linux-mips64le
|
||||||
.PHONY: XDC-linux-arm XDC-linux-arm-5 XDC-linux-arm-6 XDC-linux-arm-7 XDC-linux-arm64
|
|
||||||
.PHONY: XDC-darwin XDC-darwin-386 XDC-darwin-amd64
|
.PHONY: XDC-darwin XDC-darwin-386 XDC-darwin-amd64
|
||||||
.PHONY: XDC-windows XDC-windows-386 XDC-windows-amd64
|
|
||||||
|
|
||||||
GOBIN = $(shell pwd)/build/bin
|
GOBIN = $(shell pwd)/build/bin
|
||||||
GOFMT = gofmt
|
GOFMT = gofmt
|
||||||
|
|
@ -14,7 +8,7 @@ GO ?= latest
|
||||||
GO_PACKAGES = .
|
GO_PACKAGES = .
|
||||||
GO_FILES := $(shell find $(shell go list -f '{{.Dir}}' $(GO_PACKAGES)) -name \*.go)
|
GO_FILES := $(shell find $(shell go list -f '{{.Dir}}' $(GO_PACKAGES)) -name \*.go)
|
||||||
|
|
||||||
GIT = git
|
GIT = git
|
||||||
|
|
||||||
XDC:
|
XDC:
|
||||||
build/env.sh go run build/ci.go install ./cmd/XDC
|
build/env.sh go run build/ci.go install ./cmd/XDC
|
||||||
|
|
@ -26,50 +20,27 @@ bootnode:
|
||||||
@echo "Done building."
|
@echo "Done building."
|
||||||
@echo "Run \"$(GOBIN)/bootnode\" to launch a bootnode."
|
@echo "Run \"$(GOBIN)/bootnode\" to launch a bootnode."
|
||||||
|
|
||||||
swarm:
|
puppeth:
|
||||||
build/env.sh go run build/ci.go install ./cmd/swarm
|
build/env.sh go run build/ci.go install ./cmd/puppeth
|
||||||
@echo "Done building."
|
@echo "Done building."
|
||||||
@echo "Run \"$(GOBIN)/swarm\" to launch swarm."
|
@echo "Run \"$(GOBIN)/puppeth\" to launch puppeth."
|
||||||
|
|
||||||
all:
|
all:
|
||||||
build/env.sh go run build/ci.go install
|
build/env.sh go run build/ci.go install
|
||||||
|
|
||||||
android:
|
|
||||||
build/env.sh go run build/ci.go aar --local
|
|
||||||
@echo "Done building."
|
|
||||||
@echo "Import \"$(GOBIN)/XDC.aar\" to use the library."
|
|
||||||
|
|
||||||
ios:
|
|
||||||
build/env.sh go run build/ci.go xcode --local
|
|
||||||
@echo "Done building."
|
|
||||||
@echo "Import \"$(GOBIN)/XDC.framework\" to use the library."
|
|
||||||
|
|
||||||
test: all
|
test: all
|
||||||
build/env.sh go run build/ci.go test
|
build/env.sh go run build/ci.go test
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -fr build/_workspace/pkg/ $(GOBIN)/*
|
rm -fr build/_workspace/pkg/ $(GOBIN)/*
|
||||||
|
|
||||||
# The devtools target installs tools required for 'go generate'.
|
|
||||||
# You need to put $GOBIN (or $GOPATH/bin) in your PATH to use 'go generate'.
|
|
||||||
|
|
||||||
devtools:
|
|
||||||
env GOBIN= go get -u golang.org/x/tools/cmd/stringer
|
|
||||||
env GOBIN= go get -u github.com/kevinburke/go-bindata/go-bindata
|
|
||||||
env GOBIN= go get -u github.com/fjl/gencodec
|
|
||||||
env GOBIN= go get -u github.com/golang/protobuf/protoc-gen-go
|
|
||||||
env GOBIN= go install ./cmd/abigen
|
|
||||||
@type "npm" 2> /dev/null || echo 'Please install node.js and npm'
|
|
||||||
@type "solc" 2> /dev/null || echo 'Please install solc'
|
|
||||||
@type "protoc" 2> /dev/null || echo 'Please install protoc'
|
|
||||||
|
|
||||||
# Cross Compilation Targets (xgo)
|
# Cross Compilation Targets (xgo)
|
||||||
|
|
||||||
XDC-cross: XDC-linux XDC-darwin XDC-windows XDC-android XDC-ios
|
XDC-cross: XDC-linux XDC-darwin
|
||||||
@echo "Full cross compilation done:"
|
@echo "Full cross compilation done:"
|
||||||
@ls -ld $(GOBIN)/XDC-*
|
@ls -ld $(GOBIN)/XDC-*
|
||||||
|
|
||||||
XDC-linux: XDC-linux-386 XDC-linux-amd64 XDC-linux-arm XDC-linux-mips64 XDC-linux-mips64le
|
XDC-linux: XDC-linux-386 XDC-linux-amd64 XDC-linux-mips64 XDC-linux-mips64le
|
||||||
@echo "Linux cross compilation done:"
|
@echo "Linux cross compilation done:"
|
||||||
@ls -ld $(GOBIN)/XDC-linux-*
|
@ls -ld $(GOBIN)/XDC-linux-*
|
||||||
|
|
||||||
|
|
@ -83,30 +54,6 @@ XDC-linux-amd64:
|
||||||
@echo "Linux amd64 cross compilation done:"
|
@echo "Linux amd64 cross compilation done:"
|
||||||
@ls -ld $(GOBIN)/XDC-linux-* | grep amd64
|
@ls -ld $(GOBIN)/XDC-linux-* | grep amd64
|
||||||
|
|
||||||
XDC-linux-arm: XDC-linux-arm-5 XDC-linux-arm-6 XDC-linux-arm-7 XDC-linux-arm64
|
|
||||||
@echo "Linux ARM cross compilation done:"
|
|
||||||
@ls -ld $(GOBIN)/XDC-linux-* | grep arm
|
|
||||||
|
|
||||||
XDC-linux-arm-5:
|
|
||||||
build/env.sh go run build/ci.go xgo -- --go=$(GO) --targets=linux/arm-5 -v ./cmd/XDC
|
|
||||||
@echo "Linux ARMv5 cross compilation done:"
|
|
||||||
@ls -ld $(GOBIN)/XDC-linux-* | grep arm-5
|
|
||||||
|
|
||||||
XDC-linux-arm-6:
|
|
||||||
build/env.sh go run build/ci.go xgo -- --go=$(GO) --targets=linux/arm-6 -v ./cmd/XDC
|
|
||||||
@echo "Linux ARMv6 cross compilation done:"
|
|
||||||
@ls -ld $(GOBIN)/XDC-linux-* | grep arm-6
|
|
||||||
|
|
||||||
XDC-linux-arm-7:
|
|
||||||
build/env.sh go run build/ci.go xgo -- --go=$(GO) --targets=linux/arm-7 -v ./cmd/XDC
|
|
||||||
@echo "Linux ARMv7 cross compilation done:"
|
|
||||||
@ls -ld $(GOBIN)/XDC-linux-* | grep arm-7
|
|
||||||
|
|
||||||
XDC-linux-arm64:
|
|
||||||
build/env.sh go run build/ci.go xgo -- --go=$(GO) --targets=linux/arm64 -v ./cmd/XDC
|
|
||||||
@echo "Linux ARM64 cross compilation done:"
|
|
||||||
@ls -ld $(GOBIN)/XDC-linux-* | grep arm64
|
|
||||||
|
|
||||||
XDC-linux-mips:
|
XDC-linux-mips:
|
||||||
build/env.sh go run build/ci.go xgo -- --go=$(GO) --targets=linux/mips --ldflags '-extldflags "-static"' -v ./cmd/XDC
|
build/env.sh go run build/ci.go xgo -- --go=$(GO) --targets=linux/mips --ldflags '-extldflags "-static"' -v ./cmd/XDC
|
||||||
@echo "Linux MIPS cross compilation done:"
|
@echo "Linux MIPS cross compilation done:"
|
||||||
|
|
@ -141,20 +88,6 @@ XDC-darwin-amd64:
|
||||||
@echo "Darwin amd64 cross compilation done:"
|
@echo "Darwin amd64 cross compilation done:"
|
||||||
@ls -ld $(GOBIN)/XDC-darwin-* | grep amd64
|
@ls -ld $(GOBIN)/XDC-darwin-* | grep amd64
|
||||||
|
|
||||||
XDC-windows: XDC-windows-386 XDC-windows-amd64
|
gofmt:
|
||||||
@echo "Windows cross compilation done:"
|
|
||||||
@ls -ld $(GOBIN)/XDC-windows-*
|
|
||||||
|
|
||||||
XDC-windows-386:
|
|
||||||
build/env.sh go run build/ci.go xgo -- --go=$(GO) --targets=windows/386 -v ./cmd/XDC
|
|
||||||
@echo "Windows 386 cross compilation done:"
|
|
||||||
@ls -ld $(GOBIN)/XDC-windows-* | grep 386
|
|
||||||
|
|
||||||
XDC-windows-amd64:
|
|
||||||
build/env.sh go run build/ci.go xgo -- --go=$(GO) --targets=windows/amd64 -v ./cmd/XDC
|
|
||||||
@echo "Windows amd64 cross compilation done:"
|
|
||||||
@ls -ld $(GOBIN)/geth-windows-* | grep amd64
|
|
||||||
|
|
||||||
gofmt:
|
|
||||||
$(GOFMT) -s -w $(GO_FILES)
|
$(GOFMT) -s -w $(GO_FILES)
|
||||||
$(GIT) checkout vendor
|
$(GIT) checkout vendor
|
||||||
1037
build/ci.go
1037
build/ci.go
File diff suppressed because it is too large
Load diff
|
|
@ -1,185 +0,0 @@
|
||||||
// Copyright 2016 The go-ethereum Authors
|
|
||||||
// This file is part of the go-ethereum library.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
|
||||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package build
|
|
||||||
|
|
||||||
import (
|
|
||||||
"archive/tar"
|
|
||||||
"archive/zip"
|
|
||||||
"compress/gzip"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Archive interface {
|
|
||||||
// Directory adds a new directory entry to the archive and sets the
|
|
||||||
// directory for subsequent calls to Header.
|
|
||||||
Directory(name string) error
|
|
||||||
|
|
||||||
// Header adds a new file to the archive. The file is added to the directory
|
|
||||||
// set by Directory. The content of the file must be written to the returned
|
|
||||||
// writer.
|
|
||||||
Header(os.FileInfo) (io.Writer, error)
|
|
||||||
|
|
||||||
// Close flushes the archive and closes the underlying file.
|
|
||||||
Close() error
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewArchive(file *os.File) (Archive, string) {
|
|
||||||
switch {
|
|
||||||
case strings.HasSuffix(file.Name(), ".zip"):
|
|
||||||
return NewZipArchive(file), strings.TrimSuffix(file.Name(), ".zip")
|
|
||||||
case strings.HasSuffix(file.Name(), ".tar.gz"):
|
|
||||||
return NewTarballArchive(file), strings.TrimSuffix(file.Name(), ".tar.gz")
|
|
||||||
default:
|
|
||||||
return nil, ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddFile appends an existing file to an archive.
|
|
||||||
func AddFile(a Archive, file string) error {
|
|
||||||
fd, err := os.Open(file)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer fd.Close()
|
|
||||||
fi, err := fd.Stat()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
w, err := a.Header(fi)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := io.Copy(w, fd); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteArchive creates an archive containing the given files.
|
|
||||||
func WriteArchive(name string, files []string) (err error) {
|
|
||||||
archfd, err := os.Create(name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
archfd.Close()
|
|
||||||
// Remove the half-written archive on failure.
|
|
||||||
if err != nil {
|
|
||||||
os.Remove(name)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
archive, basename := NewArchive(archfd)
|
|
||||||
if archive == nil {
|
|
||||||
return fmt.Errorf("unknown archive extension")
|
|
||||||
}
|
|
||||||
fmt.Println(name)
|
|
||||||
if err := archive.Directory(basename); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, file := range files {
|
|
||||||
fmt.Println(" +", filepath.Base(file))
|
|
||||||
if err := AddFile(archive, file); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return archive.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
type ZipArchive struct {
|
|
||||||
dir string
|
|
||||||
zipw *zip.Writer
|
|
||||||
file io.Closer
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewZipArchive(w io.WriteCloser) Archive {
|
|
||||||
return &ZipArchive{"", zip.NewWriter(w), w}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *ZipArchive) Directory(name string) error {
|
|
||||||
a.dir = name + "/"
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *ZipArchive) Header(fi os.FileInfo) (io.Writer, error) {
|
|
||||||
head, err := zip.FileInfoHeader(fi)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't make zip header: %v", err)
|
|
||||||
}
|
|
||||||
head.Name = a.dir + head.Name
|
|
||||||
head.Method = zip.Deflate
|
|
||||||
w, err := a.zipw.CreateHeader(head)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't add zip header: %v", err)
|
|
||||||
}
|
|
||||||
return w, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *ZipArchive) Close() error {
|
|
||||||
if err := a.zipw.Close(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return a.file.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
type TarballArchive struct {
|
|
||||||
dir string
|
|
||||||
tarw *tar.Writer
|
|
||||||
gzw *gzip.Writer
|
|
||||||
file io.Closer
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewTarballArchive(w io.WriteCloser) Archive {
|
|
||||||
gzw := gzip.NewWriter(w)
|
|
||||||
tarw := tar.NewWriter(gzw)
|
|
||||||
return &TarballArchive{"", tarw, gzw, w}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *TarballArchive) Directory(name string) error {
|
|
||||||
a.dir = name + "/"
|
|
||||||
return a.tarw.WriteHeader(&tar.Header{
|
|
||||||
Name: a.dir,
|
|
||||||
Mode: 0755,
|
|
||||||
Typeflag: tar.TypeDir,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *TarballArchive) Header(fi os.FileInfo) (io.Writer, error) {
|
|
||||||
head, err := tar.FileInfoHeader(fi, "")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't make tar header: %v", err)
|
|
||||||
}
|
|
||||||
head.Name = a.dir + head.Name
|
|
||||||
if err := a.tarw.WriteHeader(head); err != nil {
|
|
||||||
return nil, fmt.Errorf("can't add tar header: %v", err)
|
|
||||||
}
|
|
||||||
return a.tarw, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *TarballArchive) Close() error {
|
|
||||||
if err := a.tarw.Close(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := a.gzw.Close(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return a.file.Close()
|
|
||||||
}
|
|
||||||
|
|
@ -1,111 +0,0 @@
|
||||||
// Copyright 2016 The go-ethereum Authors
|
|
||||||
// This file is part of the go-ethereum library.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
|
||||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package build
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
storage "github.com/Azure/azure-storage-go"
|
|
||||||
)
|
|
||||||
|
|
||||||
// AzureBlobstoreConfig is an authentication and configuration struct containing
|
|
||||||
// the data needed by the Azure SDK to interact with a speicifc container in the
|
|
||||||
// blobstore.
|
|
||||||
type AzureBlobstoreConfig struct {
|
|
||||||
Account string // Account name to authorize API requests with
|
|
||||||
Token string // Access token for the above account
|
|
||||||
Container string // Blob container to upload files into
|
|
||||||
}
|
|
||||||
|
|
||||||
// AzureBlobstoreUpload uploads a local file to the Azure Blob Storage. Note, this
|
|
||||||
// method assumes a max file size of 64MB (Azure limitation). Larger files will
|
|
||||||
// need a multi API call approach implemented.
|
|
||||||
//
|
|
||||||
// See: https://msdn.microsoft.com/en-us/library/azure/dd179451.aspx#Anchor_3
|
|
||||||
func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig) error {
|
|
||||||
if *DryRunFlag {
|
|
||||||
fmt.Printf("would upload %q to %s/%s/%s\n", path, config.Account, config.Container, name)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
// Create an authenticated client against the Azure cloud
|
|
||||||
rawClient, err := storage.NewBasicClient(config.Account, config.Token)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
client := rawClient.GetBlobService()
|
|
||||||
|
|
||||||
// Stream the file to upload into the designated blobstore container
|
|
||||||
in, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer in.Close()
|
|
||||||
|
|
||||||
info, err := in.Stat()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return client.CreateBlockBlobFromReader(config.Container, name, uint64(info.Size()), in, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AzureBlobstoreList lists all the files contained within an azure blobstore.
|
|
||||||
func AzureBlobstoreList(config AzureBlobstoreConfig) ([]storage.Blob, error) {
|
|
||||||
// Create an authenticated client against the Azure cloud
|
|
||||||
rawClient, err := storage.NewBasicClient(config.Account, config.Token)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
client := rawClient.GetBlobService()
|
|
||||||
|
|
||||||
// List all the blobs from the container and return them
|
|
||||||
container := client.GetContainerReference(config.Container)
|
|
||||||
|
|
||||||
blobs, err := container.ListBlobs(storage.ListBlobsParameters{
|
|
||||||
MaxResults: 1024 * 1024 * 1024, // Yes, fetch all of them
|
|
||||||
Timeout: 3600, // Yes, wait for all of them
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return blobs.Blobs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// AzureBlobstoreDelete iterates over a list of files to delete and removes them
|
|
||||||
// from the blobstore.
|
|
||||||
func AzureBlobstoreDelete(config AzureBlobstoreConfig, blobs []storage.Blob) error {
|
|
||||||
if *DryRunFlag {
|
|
||||||
for _, blob := range blobs {
|
|
||||||
fmt.Printf("would delete %s (%s) from %s/%s\n", blob.Name, blob.Properties.LastModified, config.Account, config.Container)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
// Create an authenticated client against the Azure cloud
|
|
||||||
rawClient, err := storage.NewBasicClient(config.Account, config.Token)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
client := rawClient.GetBlobService()
|
|
||||||
|
|
||||||
// Iterate over the blobs and delete them
|
|
||||||
for _, blob := range blobs {
|
|
||||||
if err := client.DeleteBlob(config.Container, blob.Name, nil); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
// Copyright 2016 The go-ethereum Authors
|
|
||||||
// This file is part of the go-ethereum library.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
|
||||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
// signFile reads the contents of an input file and signs it (in armored format)
|
|
||||||
// with the key provided, placing the signature into the output file.
|
|
||||||
|
|
||||||
package build
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"golang.org/x/crypto/openpgp"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PGPSignFile parses a PGP private key from the specified string and creates a
|
|
||||||
// signature file into the output parameter of the input file.
|
|
||||||
//
|
|
||||||
// Note, this method assumes a single key will be container in the pgpkey arg,
|
|
||||||
// furthermore that it is in armored format.
|
|
||||||
func PGPSignFile(input string, output string, pgpkey string) error {
|
|
||||||
// Parse the keyring and make sure we only have a single private key in it
|
|
||||||
keys, err := openpgp.ReadArmoredKeyRing(bytes.NewBufferString(pgpkey))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(keys) != 1 {
|
|
||||||
return fmt.Errorf("key count mismatch: have %d, want %d", len(keys), 1)
|
|
||||||
}
|
|
||||||
// Create the input and output streams for signing
|
|
||||||
in, err := os.Open(input)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer in.Close()
|
|
||||||
|
|
||||||
out, err := os.Create(output)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer out.Close()
|
|
||||||
|
|
||||||
// Generate the signature and return
|
|
||||||
return openpgp.ArmoredDetachSign(out, keys[0], in, nil)
|
|
||||||
}
|
|
||||||
|
|
@ -29,7 +29,6 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var DryRunFlag = flag.Bool("n", false, "dry run, don't execute commands")
|
var DryRunFlag = flag.Bool("n", false, "dry run, don't execute commands")
|
||||||
|
|
@ -60,15 +59,6 @@ func GOPATH() string {
|
||||||
return os.Getenv("GOPATH")
|
return os.Getenv("GOPATH")
|
||||||
}
|
}
|
||||||
|
|
||||||
// VERSION returns the content of the VERSION file.
|
|
||||||
func VERSION() string {
|
|
||||||
version, err := ioutil.ReadFile("VERSION")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
return string(bytes.TrimSpace(version))
|
|
||||||
}
|
|
||||||
|
|
||||||
var warnedAboutGit bool
|
var warnedAboutGit bool
|
||||||
|
|
||||||
// RunGit runs a git subcommand and returns its output.
|
// RunGit runs a git subcommand and returns its output.
|
||||||
|
|
@ -98,34 +88,6 @@ func readGitFile(file string) string {
|
||||||
return strings.TrimSpace(string(content))
|
return strings.TrimSpace(string(content))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render renders the given template file into outputFile.
|
|
||||||
func Render(templateFile, outputFile string, outputPerm os.FileMode, x interface{}) {
|
|
||||||
tpl := template.Must(template.ParseFiles(templateFile))
|
|
||||||
render(tpl, outputFile, outputPerm, x)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RenderString renders the given template string into outputFile.
|
|
||||||
func RenderString(templateContent, outputFile string, outputPerm os.FileMode, x interface{}) {
|
|
||||||
tpl := template.Must(template.New("").Parse(templateContent))
|
|
||||||
render(tpl, outputFile, outputPerm, x)
|
|
||||||
}
|
|
||||||
|
|
||||||
func render(tpl *template.Template, outputFile string, outputPerm os.FileMode, x interface{}) {
|
|
||||||
if err := os.MkdirAll(filepath.Dir(outputFile), 0755); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
out, err := os.OpenFile(outputFile, os.O_CREATE|os.O_WRONLY|os.O_EXCL, outputPerm)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := tpl.Execute(out, x); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := out.Close(); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CopyFile copies a file.
|
// CopyFile copies a file.
|
||||||
func CopyFile(dst, src string, mode os.FileMode) {
|
func CopyFile(dst, src string, mode os.FileMode) {
|
||||||
if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
|
if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
|
||||||
|
|
@ -185,4 +147,4 @@ func ExpandPackagesNoVendor(patterns []string) []string {
|
||||||
return packages
|
return packages
|
||||||
}
|
}
|
||||||
return patterns
|
return patterns
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue