2016-05-25 15:07:57 +03:00
// 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/>.
// +build none
/ *
The ci command is called from Continuous Integration scripts .
2017-11-28 12:45:48 +03:00
Usage : go run build / ci . go < command > < command flags / arguments >
2016-05-25 15:07:57 +03:00
Available commands are :
2018-01-02 13:40:56 +03:00
install [ - arch architecture ] [ - cc compiler ] [ packages ... ] -- builds packages and executables
2017-11-09 13:46:03 +03:00
test [ - coverage ] [ packages ... ] -- runs the tests
lint -- runs certain pre - selected linters
2018-07-15 09:13:11 +03:00
archive [ - arch architecture ] [ - type zip | tar ] [ - signer key - envvar ] [ - upload dest ] -- archives build artifacts
2017-03-01 11:47:55 +03:00
importkeys -- imports signing keys from env
debsrc [ - signer key - id ] [ - upload dest ] -- creates a debian source package
nsis -- creates a Windows NSIS installer
aar [ - local ] [ - sign key - id ] [ - deploy repo ] [ - upload dest ] -- creates an Android archive
xcode [ - local ] [ - sign key - id ] [ - deploy repo ] [ - upload dest ] -- creates an iOS XCode framework
xgo [ - alltools ] [ options ] -- cross builds according to options
2017-04-06 13:53:33 +03:00
purge [ - store blobstore ] [ - days threshold ] -- purges old archives from the blobstore
2016-05-25 15:07:57 +03:00
For all commands , - n prevents execution of external programs ( dry run mode ) .
* /
package main
import (
2016-10-17 15:17:14 +03:00
"bufio"
2016-05-25 15:07:57 +03:00
"bytes"
"encoding/base64"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
2020-11-11 16:34:43 +03:00
"path"
2016-05-25 15:07:57 +03:00
"path/filepath"
2016-10-17 15:17:14 +03:00
"regexp"
2016-05-25 15:07:57 +03:00
"runtime"
"strings"
"time"
2019-11-18 21:29:01 +03:00
"github.com/cespare/cp"
2016-11-02 19:21:05 +03:00
"github.com/ethereum/go-ethereum/internal/build"
2018-07-30 11:56:40 +03:00
"github.com/ethereum/go-ethereum/params"
2016-05-25 15:07:57 +03:00
)
var (
// Files that end up in the geth*.zip archive.
gethArchiveFiles = [ ] string {
"COPYING" ,
executablePath ( "geth" ) ,
}
// Files that end up in the geth-alltools*.zip archive.
allToolsArchiveFiles = [ ] string {
"COPYING" ,
executablePath ( "abigen" ) ,
2017-03-02 16:23:15 +03:00
executablePath ( "bootnode" ) ,
2016-05-25 15:07:57 +03:00
executablePath ( "evm" ) ,
executablePath ( "geth" ) ,
2017-04-11 02:25:53 +03:00
executablePath ( "puppeth" ) ,
2016-05-25 15:07:57 +03:00
executablePath ( "rlpdump" ) ,
2019-03-04 14:02:58 +03:00
executablePath ( "clef" ) ,
2016-05-25 15:07:57 +03:00
}
// A debian package is created for all executables listed here.
debExecutables = [ ] debExecutable {
{
2018-07-30 11:56:40 +03:00
BinaryName : "abigen" ,
2017-04-11 02:25:53 +03:00
Description : "Source code generator to convert Ethereum contract definitions into easy to use, compile-time type-safe Go packages." ,
2016-05-25 15:07:57 +03:00
} ,
2017-03-09 13:02:43 +03:00
{
2018-07-30 11:56:40 +03:00
BinaryName : "bootnode" ,
2017-03-09 13:02:43 +03:00
Description : "Ethereum bootnode." ,
} ,
2016-05-25 15:07:57 +03:00
{
2018-07-30 11:56:40 +03:00
BinaryName : "evm" ,
2016-05-25 15:07:57 +03:00
Description : "Developer utility version of the EVM (Ethereum Virtual Machine) that is capable of running bytecode snippets within a configurable environment and execution mode." ,
} ,
2016-11-28 13:25:19 +03:00
{
2018-07-30 11:56:40 +03:00
BinaryName : "geth" ,
2017-04-11 02:25:53 +03:00
Description : "Ethereum CLI client." ,
2016-11-28 13:25:19 +03:00
} ,
2016-05-25 15:07:57 +03:00
{
2018-07-30 11:56:40 +03:00
BinaryName : "puppeth" ,
2017-04-11 02:25:53 +03:00
Description : "Ethereum private network manager." ,
} ,
{
2018-07-30 11:56:40 +03:00
BinaryName : "rlpdump" ,
2017-04-11 02:25:53 +03:00
Description : "Developer utility tool that prints RLP structures." ,
} ,
2019-03-04 14:02:58 +03:00
{
BinaryName : "clef" ,
Description : "Ethereum account management tool." ,
} ,
2018-07-30 11:56:40 +03:00
}
// A debian package is created for all executables listed here.
2016-05-25 15:07:57 +03:00
2018-07-30 11:56:40 +03:00
debEthereum = debPackage {
Name : "ethereum" ,
Version : params . Version ,
Executables : debExecutables ,
}
// Debian meta packages to build and push to Ubuntu PPA
debPackages = [ ] debPackage {
debEthereum ,
}
2016-05-25 15:07:57 +03:00
// Distros for which packages are created.
// Note: vivid is unsupported because there is no golang-1.6 package for it.
2019-05-20 16:11:23 +03:00
// Note: wily is unsupported because it was officially deprecated on Launchpad.
// Note: yakkety is unsupported because it was officially deprecated on Launchpad.
// Note: zesty is unsupported because it was officially deprecated on Launchpad.
// Note: artful is unsupported because it was officially deprecated on Launchpad.
2019-08-13 14:04:03 +03:00
// Note: cosmic is unsupported because it was officially deprecated on Launchpad.
2020-08-19 10:28:08 +03:00
// Note: disco is unsupported because it was officially deprecated on Launchpad.
2020-11-09 18:43:54 +03:00
// Note: eoan is unsupported because it was officially deprecated on Launchpad.
travis, build, internal: use own Go bundle for PPA builds (#20240)
* build: bump PPAs to Go 1.13 (via longsleep), keep Trusty on 1.11
* travis, build, vendor: use own Go bundle for PPA builds
* travis, build, internal, vendor: smarter Go bundler, own untar
* build: updated ci-notes with new Go bundling, only make, don't test
2019-11-05 16:32:42 +03:00
debDistroGoBoots = map [ string ] string {
"trusty" : "golang-1.11" ,
"xenial" : "golang-go" ,
"bionic" : "golang-go" ,
2020-01-16 14:28:32 +03:00
"focal" : "golang-go" ,
2020-08-19 10:28:08 +03:00
"groovy" : "golang-go" ,
travis, build, internal: use own Go bundle for PPA builds (#20240)
* build: bump PPAs to Go 1.13 (via longsleep), keep Trusty on 1.11
* travis, build, vendor: use own Go bundle for PPA builds
* travis, build, internal, vendor: smarter Go bundler, own untar
* build: updated ci-notes with new Go bundling, only make, don't test
2019-11-05 16:32:42 +03:00
}
debGoBootPaths = map [ string ] string {
"golang-1.11" : "/usr/lib/go-1.11" ,
"golang-go" : "/usr/lib/go" ,
}
2020-11-11 16:34:43 +03:00
// This is the version of go that will be downloaded by
//
// go run ci.go install -dlgo
2020-11-12 23:10:15 +03:00
dlgoVersion = "1.15.5"
2016-05-25 15:07:57 +03:00
)
var GOBIN , _ = filepath . Abs ( filepath . Join ( "build" , "bin" ) )
func executablePath ( name string ) string {
if runtime . GOOS == "windows" {
name += ".exe"
}
return filepath . Join ( GOBIN , name )
}
func main ( ) {
log . SetFlags ( log . Lshortfile )
if _ , err := os . Stat ( filepath . Join ( "build" , "ci.go" ) ) ; os . IsNotExist ( err ) {
log . Fatal ( "this script must be run from the root of the repository" )
}
if len ( os . Args ) < 2 {
log . Fatal ( "need subcommand as first argument" )
}
switch os . Args [ 1 ] {
case "install" :
doInstall ( os . Args [ 2 : ] )
case "test" :
doTest ( os . Args [ 2 : ] )
2017-11-09 13:46:03 +03:00
case "lint" :
doLint ( os . Args [ 2 : ] )
2016-05-25 15:07:57 +03:00
case "archive" :
doArchive ( os . Args [ 2 : ] )
case "debsrc" :
doDebianSource ( os . Args [ 2 : ] )
2016-11-09 00:55:39 +03:00
case "nsis" :
doWindowsInstaller ( os . Args [ 2 : ] )
2016-10-17 15:17:14 +03:00
case "aar" :
doAndroidArchive ( os . Args [ 2 : ] )
2016-11-09 12:13:37 +03:00
case "xcode" :
doXCodeFramework ( os . Args [ 2 : ] )
2016-08-08 13:41:55 +03:00
case "xgo" :
doXgo ( os . Args [ 2 : ] )
2017-04-06 13:53:33 +03:00
case "purge" :
doPurge ( os . Args [ 2 : ] )
2016-05-25 15:07:57 +03:00
default :
log . Fatal ( "unknown command " , os . Args [ 1 ] )
}
}
// Compiling
func doInstall ( cmdline [ ] string ) {
2016-11-02 20:36:48 +03:00
var (
2020-11-11 16:34:43 +03:00
dlgo = flag . Bool ( "dlgo" , false , "Download Go and build with it" )
2016-11-02 20:36:48 +03:00
arch = flag . String ( "arch" , "" , "Architecture to cross build for" )
2018-01-02 13:40:56 +03:00
cc = flag . String ( "cc" , "" , "C compiler to cross build with" )
2016-11-02 20:36:48 +03:00
)
2016-05-25 15:07:57 +03:00
flag . CommandLine . Parse ( cmdline )
2016-09-30 23:03:08 +03:00
env := build . Env ( )
2016-05-25 15:07:57 +03:00
2020-11-11 16:34:43 +03:00
// Check local Go version. People regularly open issues about compilation
2016-05-25 15:07:57 +03:00
// failure with outdated Go. This should save them the trouble.
2018-01-02 13:28:07 +03:00
if ! strings . Contains ( runtime . Version ( ) , "devel" ) {
2018-03-19 19:13:54 +03:00
// Figure out the minor version number since we can't textually compare (1.10 < 1.9)
2018-01-02 13:28:07 +03:00
var minor int
fmt . Sscanf ( strings . TrimPrefix ( runtime . Version ( ) , "go1." ) , "%d" , & minor )
2020-07-29 13:48:03 +03:00
if minor < 13 {
2018-01-02 13:28:07 +03:00
log . Println ( "You have Go version" , runtime . Version ( ) )
2020-07-29 13:48:03 +03:00
log . Println ( "go-ethereum requires at least Go version 1.13 and cannot" )
2018-01-02 13:28:07 +03:00
log . Println ( "be compiled with an earlier version. Please upgrade your Go installation." )
os . Exit ( 1 )
}
2016-05-25 15:07:57 +03:00
}
2020-11-11 16:34:43 +03:00
// Choose which go command we're going to use.
var gobuild * exec . Cmd
if ! * dlgo {
// Default behavior: use the go version which runs ci.go right now.
gobuild = goTool ( "build" )
} else {
// Download of Go requested. This is for build environments where the
// installed version is too old and cannot be upgraded easily.
cachedir := filepath . Join ( "build" , "cache" )
goroot := downloadGo ( runtime . GOARCH , runtime . GOOS , cachedir )
gobuild = localGoTool ( goroot , "build" )
2016-05-25 15:07:57 +03:00
}
2017-03-23 16:56:06 +03:00
2020-11-11 16:34:43 +03:00
// Configure environment for cross build.
if * arch != "" || * arch != runtime . GOARCH {
gobuild . Env = append ( gobuild . Env , "CGO_ENABLED=1" )
gobuild . Env = append ( gobuild . Env , "GOARCH=" + * arch )
}
// Configure C compiler.
2020-11-12 00:08:22 +03:00
if * cc != "" {
2020-11-11 16:34:43 +03:00
gobuild . Env = append ( gobuild . Env , "CC=" + * cc )
} else if os . Getenv ( "CC" ) != "" {
gobuild . Env = append ( gobuild . Env , "CC=" + os . Getenv ( "CC" ) )
}
// arm64 CI builders are memory-constrained and can't handle concurrent builds,
// better disable it. This check isn't the best, it should probably
// check for something in env instead.
if runtime . GOARCH == "arm64" {
gobuild . Args = append ( gobuild . Args , "-p" , "1" )
}
// Put the default settings in.
gobuild . Args = append ( gobuild . Args , buildFlags ( env ) ... )
2020-11-12 00:08:22 +03:00
// We use -trimpath to avoid leaking local paths into the built executables.
gobuild . Args = append ( gobuild . Args , "-trimpath" )
2020-11-11 16:34:43 +03:00
// Show packages during build.
gobuild . Args = append ( gobuild . Args , "-v" )
// Now we choose what we're even building.
// Default: collect all 'main' packages in cmd/ and build those.
packages := flag . Args ( )
if len ( packages ) == 0 {
packages = build . FindMainPackages ( "./cmd" )
}
// Do the build!
for _ , pkg := range packages {
args := make ( [ ] string , len ( gobuild . Args ) )
copy ( args , gobuild . Args )
args = append ( args , "-o" , executablePath ( path . Base ( pkg ) ) )
args = append ( args , pkg )
build . MustRun ( & exec . Cmd { Path : gobuild . Path , Args : args , Env : gobuild . Env } )
2016-11-02 20:36:48 +03:00
}
2016-05-25 15:07:57 +03:00
}
2020-11-11 16:34:43 +03:00
// buildFlags returns the go tool flags for building.
2016-09-30 23:03:08 +03:00
func buildFlags ( env build . Environment ) ( flags [ ] string ) {
2017-03-29 13:20:57 +03:00
var ld [ ] string
2016-09-30 23:03:08 +03:00
if env . Commit != "" {
2017-03-29 13:20:57 +03:00
ld = append ( ld , "-X" , "main.gitCommit=" + env . Commit )
2019-05-08 16:44:28 +03:00
ld = append ( ld , "-X" , "main.gitDate=" + env . Date )
2017-03-29 13:20:57 +03:00
}
2020-11-11 16:34:43 +03:00
// Strip DWARF on darwin. This used to be required for certain things,
// and there is no downside to this, so we just keep doing it.
2017-03-29 13:20:57 +03:00
if runtime . GOOS == "darwin" {
ld = append ( ld , "-s" )
}
if len ( ld ) > 0 {
flags = append ( flags , "-ldflags" , strings . Join ( ld , " " ) )
2016-05-25 15:07:57 +03:00
}
return flags
}
2020-11-11 16:34:43 +03:00
// goTool returns the go tool. This uses the Go version which runs ci.go.
2016-05-25 15:07:57 +03:00
func goTool ( subcmd string , args ... string ) * exec . Cmd {
2020-11-11 16:34:43 +03:00
cmd := build . GoTool ( subcmd , args ... )
goToolSetEnv ( cmd )
return cmd
2016-11-02 20:36:48 +03:00
}
2020-11-11 16:34:43 +03:00
// localGoTool returns the go tool from the given GOROOT.
func localGoTool ( goroot string , subcmd string , args ... string ) * exec . Cmd {
gotool := filepath . Join ( goroot , "bin" , "go" )
cmd := exec . Command ( gotool , subcmd )
goToolSetEnv ( cmd )
cmd . Env = append ( cmd . Env , "GOROOT=" + goroot )
cmd . Args = append ( cmd . Args , args ... )
return cmd
}
// goToolSetEnv forwards the build environment to the go tool.
func goToolSetEnv ( cmd * exec . Cmd ) {
2020-11-12 00:08:22 +03:00
cmd . Env = append ( cmd . Env , "GOBIN=" + GOBIN )
2016-05-25 15:07:57 +03:00
for _ , e := range os . Environ ( ) {
2020-11-11 16:34:43 +03:00
if strings . HasPrefix ( e , "GOBIN=" ) || strings . HasPrefix ( e , "CC=" ) {
2016-05-25 15:07:57 +03:00
continue
}
cmd . Env = append ( cmd . Env , e )
}
}
// Running The Tests
//
// "tests" also includes static analysis tools such as vet.
func doTest ( cmdline [ ] string ) {
2018-10-08 17:37:06 +03:00
coverage := flag . Bool ( "coverage" , false , "Whether to record code coverage" )
2019-11-18 17:48:20 +03:00
verbose := flag . Bool ( "v" , false , "Whether to log verbosely" )
2016-05-25 15:07:57 +03:00
flag . CommandLine . Parse ( cmdline )
2017-03-29 13:20:57 +03:00
env := build . Env ( )
2016-10-28 20:05:01 +03:00
2016-05-25 15:07:57 +03:00
packages := [ ] string { "./..." }
if len ( flag . CommandLine . Args ( ) ) > 0 {
packages = flag . CommandLine . Args ( )
}
2017-03-23 17:46:03 +03:00
2016-05-25 15:07:57 +03:00
// Run the actual tests.
2016-09-26 14:41:18 +03:00
// Test a single package at a time. CI builders are slow
// and some tests run into timeouts under load.
2018-10-08 17:37:06 +03:00
gotest := goTool ( "test" , buildFlags ( env ) ... )
2020-05-05 15:11:00 +03:00
gotest . Args = append ( gotest . Args , "-p" , "1" )
2016-05-25 15:07:57 +03:00
if * coverage {
gotest . Args = append ( gotest . Args , "-covermode=atomic" , "-cover" )
}
2019-11-18 17:48:20 +03:00
if * verbose {
gotest . Args = append ( gotest . Args , "-v" )
}
2017-11-09 13:46:03 +03:00
2016-05-25 15:07:57 +03:00
gotest . Args = append ( gotest . Args , packages ... )
build . MustRun ( gotest )
}
2019-11-18 11:49:18 +03:00
// doLint runs golangci-lint on requested packages.
2017-11-09 13:46:03 +03:00
func doLint ( cmdline [ ] string ) {
2019-11-18 11:49:18 +03:00
var (
cachedir = flag . String ( "cachedir" , "./build/cache" , "directory for caching golangci-lint binary." )
)
2017-11-09 13:46:03 +03:00
flag . CommandLine . Parse ( cmdline )
packages := [ ] string { "./..." }
if len ( flag . CommandLine . Args ( ) ) > 0 {
packages = flag . CommandLine . Args ( )
2017-01-13 12:54:17 +03:00
}
2019-11-18 11:49:18 +03:00
linter := downloadLinter ( * cachedir )
lflags := [ ] string { "run" , "--config" , ".golangci.yml" }
build . MustRunCommand ( linter , append ( lflags , packages ... ) ... )
fmt . Println ( "You have achieved perfection." )
}
// downloadLinter downloads and unpacks golangci-lint.
func downloadLinter ( cachedir string ) string {
2020-05-26 14:24:22 +03:00
const version = "1.27.0"
2019-11-18 11:49:18 +03:00
csdb := build . MustLoadChecksums ( "build/checksums.txt" )
base := fmt . Sprintf ( "golangci-lint-%s-%s-%s" , version , runtime . GOOS , runtime . GOARCH )
url := fmt . Sprintf ( "https://github.com/golangci/golangci-lint/releases/download/v%s/%s.tar.gz" , version , base )
archivePath := filepath . Join ( cachedir , base + ".tar.gz" )
if err := csdb . DownloadFile ( url , archivePath ) ; err != nil {
log . Fatal ( err )
}
2020-11-11 16:34:43 +03:00
if err := build . ExtractArchive ( archivePath , cachedir ) ; err != nil {
2019-11-18 11:49:18 +03:00
log . Fatal ( err )
2017-11-10 20:06:45 +03:00
}
2019-11-18 11:49:18 +03:00
return filepath . Join ( cachedir , base , "golangci-lint" )
2017-01-13 12:54:17 +03:00
}
2016-05-25 15:07:57 +03:00
// Release Packaging
func doArchive ( cmdline [ ] string ) {
var (
2016-11-02 20:36:48 +03:00
arch = flag . String ( "arch" , runtime . GOARCH , "Architecture cross packaging" )
2016-11-02 19:21:05 +03:00
atype = flag . String ( "type" , "zip" , "Type of archive to write (zip|tar)" )
signer = flag . String ( "signer" , "" , ` Environment variable holding the signing key (e.g. LINUX_SIGNING_KEY) ` )
upload = flag . String ( "upload" , "" , ` Destination to upload the archives (usually "gethstore/builds") ` )
ext string
2016-05-25 15:07:57 +03:00
)
flag . CommandLine . Parse ( cmdline )
switch * atype {
case "zip" :
ext = ".zip"
case "tar" :
ext = ".tar.gz"
default :
log . Fatal ( "unknown archive type: " , atype )
}
2016-09-30 23:03:08 +03:00
2016-11-03 15:44:16 +03:00
var (
2018-07-30 11:56:40 +03:00
env = build . Env ( )
basegeth = archiveBasename ( * arch , params . ArchiveVersion ( env . Commit ) )
geth = "geth-" + basegeth + ext
alltools = "geth-alltools-" + basegeth + ext
2016-11-03 15:44:16 +03:00
)
2016-09-30 23:03:08 +03:00
maybeSkipArchive ( env )
2016-11-03 15:44:16 +03:00
if err := build . WriteArchive ( geth , gethArchiveFiles ) ; err != nil {
2016-05-25 15:07:57 +03:00
log . Fatal ( err )
}
2016-11-03 15:44:16 +03:00
if err := build . WriteArchive ( alltools , allToolsArchiveFiles ) ; err != nil {
2016-05-25 15:07:57 +03:00
log . Fatal ( err )
}
2019-05-17 02:06:20 +03:00
for _ , archive := range [ ] string { geth , alltools } {
2016-11-02 19:21:05 +03:00
if err := archiveUpload ( archive , * upload , * signer ) ; err != nil {
log . Fatal ( err )
}
}
2016-05-25 15:07:57 +03:00
}
2018-07-30 11:56:40 +03:00
func archiveBasename ( arch string , archiveVersion string ) string {
2016-11-02 20:36:48 +03:00
platform := runtime . GOOS + "-" + arch
2016-11-04 14:48:20 +03:00
if arch == "arm" {
platform += os . Getenv ( "GOARM" )
}
2016-10-17 15:17:14 +03:00
if arch == "android" {
platform = "android-all"
}
2016-11-09 12:13:37 +03:00
if arch == "ios" {
platform = "ios-all"
}
2018-07-30 11:56:40 +03:00
return platform + "-" + archiveVersion
2016-05-25 15:07:57 +03:00
}
2016-11-02 19:21:05 +03:00
func archiveUpload ( archive string , blobstore string , signer string ) error {
// If signing was requested, generate the signature files
if signer != "" {
2019-02-12 12:55:25 +03:00
key := getenvBase64 ( signer )
if err := build . PGPSignFile ( archive , archive + ".asc" , string ( key ) ) ; err != nil {
2016-11-02 19:21:05 +03:00
return err
}
}
// If uploading to Azure was requested, push the archive possibly with its signature
if blobstore != "" {
auth := build . AzureBlobstoreConfig {
Account : strings . Split ( blobstore , "/" ) [ 0 ] ,
Token : os . Getenv ( "AZURE_BLOBSTORE_TOKEN" ) ,
Container : strings . SplitN ( blobstore , "/" , 2 ) [ 1 ] ,
}
2016-11-09 01:46:46 +03:00
if err := build . AzureBlobstoreUpload ( archive , filepath . Base ( archive ) , auth ) ; err != nil {
2016-11-02 19:21:05 +03:00
return err
}
if signer != "" {
2016-11-09 01:46:46 +03:00
if err := build . AzureBlobstoreUpload ( archive + ".asc" , filepath . Base ( archive + ".asc" ) , auth ) ; err != nil {
2016-11-02 19:21:05 +03:00
return err
}
}
}
return nil
}
2016-09-30 23:03:08 +03:00
// skips archiving for some build configurations.
func maybeSkipArchive ( env build . Environment ) {
if env . IsPullRequest {
log . Printf ( "skipping because this is a PR build" )
os . Exit ( 0 )
}
2017-04-06 13:53:33 +03:00
if env . IsCronJob {
log . Printf ( "skipping because this is a cron job" )
os . Exit ( 0 )
}
2016-11-15 16:11:27 +03:00
if env . Branch != "master" && ! strings . HasPrefix ( env . Tag , "v1." ) {
2016-09-30 23:03:08 +03:00
log . Printf ( "skipping because branch %q, tag %q is not on the whitelist" , env . Branch , env . Tag )
os . Exit ( 0 )
}
}
2016-05-25 15:07:57 +03:00
// Debian Packaging
2016-09-30 23:03:08 +03:00
func doDebianSource ( cmdline [ ] string ) {
var (
2020-11-11 16:34:43 +03:00
cachedir = flag . String ( "cachedir" , "./build/cache" , ` Filesystem path to cache the downloaded Go bundles at ` )
signer = flag . String ( "signer" , "" , ` Signing key name, also used as package author ` )
upload = flag . String ( "upload" , "" , ` Where to upload the source package (usually "ethereum/ethereum") ` )
sshUser = flag . String ( "sftp-user" , "" , ` Username for SFTP upload (usually "geth-ci") ` )
workdir = flag . String ( "workdir" , "" , ` Output directory for packages (uses temp dir if unset) ` )
now = time . Now ( )
2016-09-30 23:03:08 +03:00
)
2016-05-25 15:07:57 +03:00
flag . CommandLine . Parse ( cmdline )
2016-09-30 23:03:08 +03:00
* workdir = makeWorkdir ( * workdir )
env := build . Env ( )
maybeSkipArchive ( env )
2016-05-25 15:07:57 +03:00
// Import the signing key.
2019-02-12 12:55:25 +03:00
if key := getenvBase64 ( "PPA_SIGNING_KEY" ) ; len ( key ) > 0 {
2016-05-25 15:07:57 +03:00
gpg := exec . Command ( "gpg" , "--import" )
gpg . Stdin = bytes . NewReader ( key )
build . MustRun ( gpg )
}
2019-11-18 11:49:18 +03:00
// Download and verify the Go source package.
2020-11-11 16:34:43 +03:00
gobundle := downloadGoSources ( * cachedir )
2019-11-18 11:49:18 +03:00
2019-11-21 17:14:31 +03:00
// Download all the dependencies needed to build the sources and run the ci script
2020-11-12 00:08:22 +03:00
srcdepfetch := goTool ( "mod" , "download" )
2019-11-21 17:14:31 +03:00
srcdepfetch . Env = append ( os . Environ ( ) , "GOPATH=" + filepath . Join ( * workdir , "modgopath" ) )
build . MustRun ( srcdepfetch )
cidepfetch := goTool ( "run" , "./build/ci.go" )
cidepfetch . Env = append ( os . Environ ( ) , "GOPATH=" + filepath . Join ( * workdir , "modgopath" ) )
cidepfetch . Run ( ) // Command fails, don't care, we only need the deps to start it
2019-11-20 15:56:07 +03:00
2019-11-18 11:49:18 +03:00
// Create Debian packages and upload them.
2018-07-30 11:56:40 +03:00
for _ , pkg := range debPackages {
travis, build, internal: use own Go bundle for PPA builds (#20240)
* build: bump PPAs to Go 1.13 (via longsleep), keep Trusty on 1.11
* travis, build, vendor: use own Go bundle for PPA builds
* travis, build, internal, vendor: smarter Go bundler, own untar
* build: updated ci-notes with new Go bundling, only make, don't test
2019-11-05 16:32:42 +03:00
for distro , goboot := range debDistroGoBoots {
2019-11-18 11:49:18 +03:00
// Prepare the debian package with the go-ethereum sources.
travis, build, internal: use own Go bundle for PPA builds (#20240)
* build: bump PPAs to Go 1.13 (via longsleep), keep Trusty on 1.11
* travis, build, vendor: use own Go bundle for PPA builds
* travis, build, internal, vendor: smarter Go bundler, own untar
* build: updated ci-notes with new Go bundling, only make, don't test
2019-11-05 16:32:42 +03:00
meta := newDebMetadata ( distro , goboot , * signer , env , now , pkg . Name , pkg . Version , pkg . Executables )
2018-07-30 11:56:40 +03:00
pkgdir := stageDebianSource ( * workdir , meta )
travis, build, internal: use own Go bundle for PPA builds (#20240)
* build: bump PPAs to Go 1.13 (via longsleep), keep Trusty on 1.11
* travis, build, vendor: use own Go bundle for PPA builds
* travis, build, internal, vendor: smarter Go bundler, own untar
* build: updated ci-notes with new Go bundling, only make, don't test
2019-11-05 16:32:42 +03:00
2019-11-18 20:18:50 +03:00
// Add Go source code
2020-11-11 16:34:43 +03:00
if err := build . ExtractArchive ( gobundle , pkgdir ) ; err != nil {
travis, build, internal: use own Go bundle for PPA builds (#20240)
* build: bump PPAs to Go 1.13 (via longsleep), keep Trusty on 1.11
* travis, build, vendor: use own Go bundle for PPA builds
* travis, build, internal, vendor: smarter Go bundler, own untar
* build: updated ci-notes with new Go bundling, only make, don't test
2019-11-05 16:32:42 +03:00
log . Fatalf ( "Failed to extract Go sources: %v" , err )
}
if err := os . Rename ( filepath . Join ( pkgdir , "go" ) , filepath . Join ( pkgdir , ".go" ) ) ; err != nil {
log . Fatalf ( "Failed to rename Go source folder: %v" , err )
}
2019-11-18 20:18:50 +03:00
// Add all dependency modules in compressed form
2019-11-20 15:56:07 +03:00
os . MkdirAll ( filepath . Join ( pkgdir , ".mod" , "cache" ) , 0755 )
if err := cp . CopyAll ( filepath . Join ( pkgdir , ".mod" , "cache" , "download" ) , filepath . Join ( * workdir , "modgopath" , "pkg" , "mod" , "cache" , "download" ) ) ; err != nil {
2019-11-18 21:29:01 +03:00
log . Fatalf ( "Failed to copy Go module dependencies: %v" , err )
}
travis, build, internal: use own Go bundle for PPA builds (#20240)
* build: bump PPAs to Go 1.13 (via longsleep), keep Trusty on 1.11
* travis, build, vendor: use own Go bundle for PPA builds
* travis, build, internal, vendor: smarter Go bundler, own untar
* build: updated ci-notes with new Go bundling, only make, don't test
2019-11-05 16:32:42 +03:00
// Run the packaging and upload to the PPA
2019-11-21 19:18:59 +03:00
debuild := exec . Command ( "debuild" , "-S" , "-sa" , "-us" , "-uc" , "-d" , "-Zxz" , "-nc" )
2018-07-30 11:56:40 +03:00
debuild . Dir = pkgdir
build . MustRun ( debuild )
2016-05-25 15:07:57 +03:00
2019-02-14 18:10:09 +03:00
var (
basename = fmt . Sprintf ( "%s_%s" , meta . Name ( ) , meta . VersionString ( ) )
source = filepath . Join ( * workdir , basename + ".tar.xz" )
dsc = filepath . Join ( * workdir , basename + ".dsc" )
changes = filepath . Join ( * workdir , basename + "_source.changes" )
)
2018-07-30 11:56:40 +03:00
if * signer != "" {
build . MustRunCommand ( "debsign" , changes )
}
if * upload != "" {
2019-02-14 18:10:09 +03:00
ppaUpload ( * workdir , * upload , * sshUser , [ ] string { source , dsc , changes } )
2018-07-30 11:56:40 +03:00
}
2016-05-25 15:07:57 +03:00
}
}
}
2020-11-11 16:34:43 +03:00
// downloadGoSources downloads the Go source tarball.
func downloadGoSources ( cachedir string ) string {
2019-11-18 11:49:18 +03:00
csdb := build . MustLoadChecksums ( "build/checksums.txt" )
2020-11-11 16:34:43 +03:00
file := fmt . Sprintf ( "go%s.src.tar.gz" , dlgoVersion )
2019-11-18 11:49:18 +03:00
url := "https://dl.google.com/go/" + file
dst := filepath . Join ( cachedir , file )
if err := csdb . DownloadFile ( url , dst ) ; err != nil {
log . Fatal ( err )
}
return dst
}
2020-11-11 16:34:43 +03:00
// downloadGo downloads the Go binary distribution and unpacks it into a temporary
// directory. It returns the GOROOT of the unpacked toolchain.
func downloadGo ( goarch , goos , cachedir string ) string {
if goarch == "arm" {
goarch = "armv6l"
}
csdb := build . MustLoadChecksums ( "build/checksums.txt" )
file := fmt . Sprintf ( "go%s.%s-%s" , dlgoVersion , goos , goarch )
if goos == "windows" {
file += ".zip"
} else {
file += ".tar.gz"
}
url := "https://golang.org/dl/" + file
dst := filepath . Join ( cachedir , file )
if err := csdb . DownloadFile ( url , dst ) ; err != nil {
log . Fatal ( err )
}
ucache , err := os . UserCacheDir ( )
if err != nil {
log . Fatal ( err )
}
godir := filepath . Join ( ucache , fmt . Sprintf ( "geth-go-%s-%s-%s" , dlgoVersion , goos , goarch ) )
if err := build . ExtractArchive ( dst , godir ) ; err != nil {
log . Fatal ( err )
}
goroot , err := filepath . Abs ( filepath . Join ( godir , "go" ) )
if err != nil {
log . Fatal ( err )
}
return goroot
}
2019-02-14 18:10:09 +03:00
func ppaUpload ( workdir , ppa , sshUser string , files [ ] string ) {
2019-02-12 12:55:25 +03:00
p := strings . Split ( ppa , "/" )
if len ( p ) != 2 {
log . Fatal ( "-upload PPA name must contain single /" )
}
2019-02-14 18:10:09 +03:00
if sshUser == "" {
sshUser = p [ 0 ]
2019-02-12 12:55:25 +03:00
}
2019-02-14 18:10:09 +03:00
incomingDir := fmt . Sprintf ( "~%s/ubuntu/%s" , p [ 0 ] , p [ 1 ] )
// Create the SSH identity file if it doesn't exist.
var idfile string
2019-02-12 12:55:25 +03:00
if sshkey := getenvBase64 ( "PPA_SSH_KEY" ) ; len ( sshkey ) > 0 {
2019-02-14 18:10:09 +03:00
idfile = filepath . Join ( workdir , "sshkey" )
if _ , err := os . Stat ( idfile ) ; os . IsNotExist ( err ) {
ioutil . WriteFile ( idfile , sshkey , 0600 )
}
}
// Upload
dest := sshUser + "@ppa.launchpad.net"
if err := build . UploadSFTP ( idfile , dest , incomingDir , files ) ; err != nil {
log . Fatal ( err )
2019-02-12 12:55:25 +03:00
}
}
func getenvBase64 ( variable string ) [ ] byte {
dec , err := base64 . StdEncoding . DecodeString ( os . Getenv ( variable ) )
if err != nil {
log . Fatal ( "invalid base64 " + variable )
}
return [ ] byte ( dec )
}
2016-09-30 23:03:08 +03:00
func makeWorkdir ( wdflag string ) string {
var err error
if wdflag != "" {
err = os . MkdirAll ( wdflag , 0744 )
} else {
2016-11-09 00:55:39 +03:00
wdflag , err = ioutil . TempDir ( "" , "geth-build-" )
2016-09-30 23:03:08 +03:00
}
if err != nil {
log . Fatal ( err )
}
return wdflag
}
func isUnstableBuild ( env build . Environment ) bool {
2016-11-18 21:55:19 +03:00
if env . Tag != "" {
2016-09-30 23:03:08 +03:00
return false
}
return true
2016-05-25 15:07:57 +03:00
}
2018-07-30 11:56:40 +03:00
type debPackage struct {
2019-05-17 02:06:20 +03:00
Name string // the name of the Debian package to produce, e.g. "ethereum"
Version string // the clean version of the debPackage, e.g. 1.8.12, without any metadata
2018-07-30 11:56:40 +03:00
Executables [ ] debExecutable // executables to be included in the package
}
2016-05-25 15:07:57 +03:00
type debMetadata struct {
travis, build, internal: use own Go bundle for PPA builds (#20240)
* build: bump PPAs to Go 1.13 (via longsleep), keep Trusty on 1.11
* travis, build, vendor: use own Go bundle for PPA builds
* travis, build, internal, vendor: smarter Go bundler, own untar
* build: updated ci-notes with new Go bundling, only make, don't test
2019-11-05 16:32:42 +03:00
Env build . Environment
GoBootPackage string
GoBootPath string
2016-09-30 23:03:08 +03:00
2018-07-30 11:56:40 +03:00
PackageName string
2016-05-25 15:07:57 +03:00
// go-ethereum version being built. Note that this
// is not the debian package version. The package version
// is constructed by VersionString.
Version string
2016-09-30 23:03:08 +03:00
Author string // "name <email>", also selects signing key
Distro , Time string
Executables [ ] debExecutable
2016-05-25 15:07:57 +03:00
}
2016-09-30 23:03:08 +03:00
type debExecutable struct {
2018-07-30 11:56:40 +03:00
PackageName string
BinaryName string
Description string
}
// Package returns the name of the package if present, or
// fallbacks to BinaryName
func ( d debExecutable ) Package ( ) string {
if d . PackageName != "" {
return d . PackageName
}
return d . BinaryName
2016-09-30 23:03:08 +03:00
}
travis, build, internal: use own Go bundle for PPA builds (#20240)
* build: bump PPAs to Go 1.13 (via longsleep), keep Trusty on 1.11
* travis, build, vendor: use own Go bundle for PPA builds
* travis, build, internal, vendor: smarter Go bundler, own untar
* build: updated ci-notes with new Go bundling, only make, don't test
2019-11-05 16:32:42 +03:00
func newDebMetadata ( distro , goboot , author string , env build . Environment , t time . Time , name string , version string , exes [ ] debExecutable ) debMetadata {
2016-05-25 15:07:57 +03:00
if author == "" {
// No signing key, use default author.
author = "Ethereum Builds <fjl@ethereum.org>"
}
return debMetadata {
travis, build, internal: use own Go bundle for PPA builds (#20240)
* build: bump PPAs to Go 1.13 (via longsleep), keep Trusty on 1.11
* travis, build, vendor: use own Go bundle for PPA builds
* travis, build, internal, vendor: smarter Go bundler, own untar
* build: updated ci-notes with new Go bundling, only make, don't test
2019-11-05 16:32:42 +03:00
GoBootPackage : goboot ,
GoBootPath : debGoBootPaths [ goboot ] ,
PackageName : name ,
Env : env ,
Author : author ,
Distro : distro ,
Version : version ,
Time : t . Format ( time . RFC1123Z ) ,
Executables : exes ,
2016-05-25 15:07:57 +03:00
}
}
// Name returns the name of the metapackage that depends
// on all executable packages.
func ( meta debMetadata ) Name ( ) string {
2016-09-30 23:03:08 +03:00
if isUnstableBuild ( meta . Env ) {
2018-07-30 11:56:40 +03:00
return meta . PackageName + "-unstable"
2016-05-25 15:07:57 +03:00
}
2018-07-30 11:56:40 +03:00
return meta . PackageName
2016-05-25 15:07:57 +03:00
}
// VersionString returns the debian version of the packages.
func ( meta debMetadata ) VersionString ( ) string {
vsn := meta . Version
2016-09-30 23:03:08 +03:00
if meta . Env . Buildnum != "" {
vsn += "+build" + meta . Env . Buildnum
2016-05-25 15:07:57 +03:00
}
if meta . Distro != "" {
vsn += "+" + meta . Distro
}
return vsn
}
// ExeList returns the list of all executable packages.
func ( meta debMetadata ) ExeList ( ) string {
names := make ( [ ] string , len ( meta . Executables ) )
for i , e := range meta . Executables {
names [ i ] = meta . ExeName ( e )
}
return strings . Join ( names , ", " )
}
// ExeName returns the package name of an executable package.
func ( meta debMetadata ) ExeName ( exe debExecutable ) string {
2016-09-30 23:03:08 +03:00
if isUnstableBuild ( meta . Env ) {
2018-07-30 11:56:40 +03:00
return exe . Package ( ) + "-unstable"
2016-05-25 15:07:57 +03:00
}
2018-07-30 11:56:40 +03:00
return exe . Package ( )
}
2016-05-25 15:07:57 +03:00
// ExeConflicts returns the content of the Conflicts field
// for executable packages.
func ( meta debMetadata ) ExeConflicts ( exe debExecutable ) string {
2016-09-30 23:03:08 +03:00
if isUnstableBuild ( meta . Env ) {
2016-05-25 15:07:57 +03:00
// Set up the conflicts list so that the *-unstable packages
// cannot be installed alongside the regular version.
//
// https://www.debian.org/doc/debian-policy/ch-relationships.html
// is very explicit about Conflicts: and says that Breaks: should
// be preferred and the conflicting files should be handled via
// alternates. We might do this eventually but using a conflict is
// easier now.
2018-07-30 11:56:40 +03:00
return "ethereum, " + exe . Package ( )
2016-05-25 15:07:57 +03:00
}
return ""
}
func stageDebianSource ( tmpdir string , meta debMetadata ) ( pkgdir string ) {
pkg := meta . Name ( ) + "-" + meta . VersionString ( )
pkgdir = filepath . Join ( tmpdir , pkg )
if err := os . Mkdir ( pkgdir , 0755 ) ; err != nil {
log . Fatal ( err )
}
// Copy the source code.
build . MustRunCommand ( "git" , "checkout-index" , "-a" , "--prefix" , pkgdir + string ( filepath . Separator ) )
// Put the debian build files in place.
debian := filepath . Join ( pkgdir , "debian" )
2018-07-30 11:56:40 +03:00
build . Render ( "build/deb/" + meta . PackageName + "/deb.rules" , filepath . Join ( debian , "rules" ) , 0755 , meta )
build . Render ( "build/deb/" + meta . PackageName + "/deb.changelog" , filepath . Join ( debian , "changelog" ) , 0644 , meta )
build . Render ( "build/deb/" + meta . PackageName + "/deb.control" , filepath . Join ( debian , "control" ) , 0644 , meta )
build . Render ( "build/deb/" + meta . PackageName + "/deb.copyright" , filepath . Join ( debian , "copyright" ) , 0644 , meta )
2016-05-25 15:07:57 +03:00
build . RenderString ( "8\n" , filepath . Join ( debian , "compat" ) , 0644 , meta )
build . RenderString ( "3.0 (native)\n" , filepath . Join ( debian , "source/format" ) , 0644 , meta )
for _ , exe := range meta . Executables {
2016-09-30 23:03:08 +03:00
install := filepath . Join ( debian , meta . ExeName ( exe ) + ".install" )
docs := filepath . Join ( debian , meta . ExeName ( exe ) + ".docs" )
2018-07-30 11:56:40 +03:00
build . Render ( "build/deb/" + meta . PackageName + "/deb.install" , install , 0644 , exe )
build . Render ( "build/deb/" + meta . PackageName + "/deb.docs" , docs , 0644 , exe )
2016-05-25 15:07:57 +03:00
}
return pkgdir
}
2016-08-08 13:41:55 +03:00
2016-11-09 00:55:39 +03:00
// Windows installer
func doWindowsInstaller ( cmdline [ ] string ) {
// Parse the flags and make skip installer generation on PRs
var (
arch = flag . String ( "arch" , runtime . GOARCH , "Architecture for cross build packaging" )
signer = flag . String ( "signer" , "" , ` Environment variable holding the signing key (e.g. WINDOWS_SIGNING_KEY) ` )
upload = flag . String ( "upload" , "" , ` Destination to upload the archives (usually "gethstore/builds") ` )
workdir = flag . String ( "workdir" , "" , ` Output directory for packages (uses temp dir if unset) ` )
)
flag . CommandLine . Parse ( cmdline )
* workdir = makeWorkdir ( * workdir )
env := build . Env ( )
maybeSkipArchive ( env )
// Aggregate binaries that are included in the installer
var (
devTools [ ] string
allTools [ ] string
gethTool string
)
for _ , file := range allToolsArchiveFiles {
if file == "COPYING" { // license, copied later
continue
}
allTools = append ( allTools , filepath . Base ( file ) )
if filepath . Base ( file ) == "geth.exe" {
gethTool = file
} else {
devTools = append ( devTools , file )
}
}
// Render NSIS scripts: Installer NSIS contains two installer sections,
// first section contains the geth binary, second section holds the dev tools.
templateData := map [ string ] interface { } {
"License" : "COPYING" ,
"Geth" : gethTool ,
"DevTools" : devTools ,
}
build . Render ( "build/nsis.geth.nsi" , filepath . Join ( * workdir , "geth.nsi" ) , 0644 , nil )
build . Render ( "build/nsis.install.nsh" , filepath . Join ( * workdir , "install.nsh" ) , 0644 , templateData )
build . Render ( "build/nsis.uninstall.nsh" , filepath . Join ( * workdir , "uninstall.nsh" ) , 0644 , allTools )
2016-12-11 02:01:57 +03:00
build . Render ( "build/nsis.pathupdate.nsh" , filepath . Join ( * workdir , "PathUpdate.nsh" ) , 0644 , nil )
2016-11-09 00:55:39 +03:00
build . Render ( "build/nsis.envvarupdate.nsh" , filepath . Join ( * workdir , "EnvVarUpdate.nsh" ) , 0644 , nil )
2019-11-18 21:29:01 +03:00
if err := cp . CopyFile ( filepath . Join ( * workdir , "SimpleFC.dll" ) , "build/nsis.simplefc.dll" ) ; err != nil {
log . Fatal ( "Failed to copy SimpleFC.dll: %v" , err )
}
if err := cp . CopyFile ( filepath . Join ( * workdir , "COPYING" ) , "COPYING" ) ; err != nil {
log . Fatal ( "Failed to copy copyright note: %v" , err )
}
2016-11-09 00:55:39 +03:00
// Build the installer. This assumes that all the needed files have been previously
// built (don't mix building and packaging to keep cross compilation complexity to a
// minimum).
2018-07-30 11:56:40 +03:00
version := strings . Split ( params . Version , "." )
2016-11-09 00:55:39 +03:00
if env . Commit != "" {
version [ 2 ] += "-" + env . Commit [ : 8 ]
}
2018-07-30 11:56:40 +03:00
installer , _ := filepath . Abs ( "geth-" + archiveBasename ( * arch , params . ArchiveVersion ( env . Commit ) ) + ".exe" )
2016-11-09 00:55:39 +03:00
build . MustRunCommand ( "makensis.exe" ,
"/DOUTPUTFILE=" + installer ,
"/DMAJORVERSION=" + version [ 0 ] ,
"/DMINORVERSION=" + version [ 1 ] ,
"/DBUILDVERSION=" + version [ 2 ] ,
"/DARCH=" + * arch ,
filepath . Join ( * workdir , "geth.nsi" ) ,
)
// Sign and publish installer.
if err := archiveUpload ( installer , * upload , * signer ) ; err != nil {
log . Fatal ( err )
}
2016-11-09 12:13:37 +03:00
}
2016-10-17 15:17:14 +03:00
// Android archives
func doAndroidArchive ( cmdline [ ] string ) {
var (
2016-11-25 13:34:19 +03:00
local = flag . Bool ( "local" , false , ` Flag whether we're only doing a local build (skip Maven artifacts) ` )
2016-10-17 15:17:14 +03:00
signer = flag . String ( "signer" , "" , ` Environment variable holding the signing key (e.g. ANDROID_SIGNING_KEY) ` )
2016-11-09 12:13:37 +03:00
deploy = flag . String ( "deploy" , "" , ` Destination to deploy the archive (usually "https://oss.sonatype.org") ` )
upload = flag . String ( "upload" , "" , ` Destination to upload the archive (usually "gethstore/builds") ` )
2016-10-17 15:17:14 +03:00
)
flag . CommandLine . Parse ( cmdline )
env := build . Env ( )
2017-01-20 12:33:58 +03:00
// Sanity check that the SDK and NDK are installed and set
if os . Getenv ( "ANDROID_HOME" ) == "" {
log . Fatal ( "Please ensure ANDROID_HOME points to your Android SDK" )
}
2016-10-17 15:17:14 +03:00
// Build the Android archive and Maven resources
2018-03-19 20:00:45 +03:00
build . MustRun ( goTool ( "get" , "golang.org/x/mobile/cmd/gomobile" , "golang.org/x/mobile/cmd/gobind" ) )
2018-05-02 12:07:44 +03:00
build . MustRun ( gomobileTool ( "bind" , "-ldflags" , "-s -w" , "--target" , "android" , "--javapkg" , "org.ethereum" , "-v" , "github.com/ethereum/go-ethereum/mobile" ) )
2016-10-17 15:17:14 +03:00
2016-11-25 13:34:19 +03:00
if * local {
// If we're building locally, copy bundle to build dir and skip Maven
os . Rename ( "geth.aar" , filepath . Join ( GOBIN , "geth.aar" ) )
2020-09-28 21:11:30 +03:00
os . Rename ( "geth-sources.jar" , filepath . Join ( GOBIN , "geth-sources.jar" ) )
2016-11-25 13:34:19 +03:00
return
}
2016-10-17 15:17:14 +03:00
meta := newMavenMetadata ( env )
2016-11-09 12:13:37 +03:00
build . Render ( "build/mvn.pom" , meta . Package + ".pom" , 0755 , meta )
2016-10-17 15:17:14 +03:00
// Skip Maven deploy and Azure upload for PR builds
maybeSkipArchive ( env )
2016-11-15 11:25:51 +03:00
// Sign and upload the archive to Azure
2018-07-30 11:56:40 +03:00
archive := "geth-" + archiveBasename ( "android" , params . ArchiveVersion ( env . Commit ) ) + ".aar"
2016-11-15 11:25:51 +03:00
os . Rename ( "geth.aar" , archive )
if err := archiveUpload ( archive , * upload , * signer ) ; err != nil {
log . Fatal ( err )
}
2016-10-17 15:17:14 +03:00
// Sign and upload all the artifacts to Maven Central
2016-11-15 11:25:51 +03:00
os . Rename ( archive , meta . Package + ".aar" )
2016-10-17 15:17:14 +03:00
if * signer != "" && * deploy != "" {
// Import the signing key into the local GPG instance
2019-02-12 12:55:25 +03:00
key := getenvBase64 ( * signer )
2018-05-09 02:13:53 +03:00
gpg := exec . Command ( "gpg" , "--import" )
gpg . Stdin = bytes . NewReader ( key )
build . MustRun ( gpg )
keyID , err := build . PGPKeyID ( string ( key ) )
if err != nil {
log . Fatal ( err )
2016-10-17 15:17:14 +03:00
}
// Upload the artifacts to Sonatype and/or Maven Central
repo := * deploy + "/service/local/staging/deploy/maven2"
2016-11-09 12:13:37 +03:00
if meta . Develop {
2016-10-17 15:17:14 +03:00
repo = * deploy + "/content/repositories/snapshots"
}
2018-04-10 14:32:48 +03:00
build . MustRunCommand ( "mvn" , "gpg:sign-and-deploy-file" , "-e" , "-X" ,
2016-10-17 15:17:14 +03:00
"-settings=build/mvn.settings" , "-Durl=" + repo , "-DrepositoryId=ossrh" ,
2018-05-09 02:13:53 +03:00
"-Dgpg.keyname=" + keyID ,
2016-11-09 12:13:37 +03:00
"-DpomFile=" + meta . Package + ".pom" , "-Dfile=" + meta . Package + ".aar" )
2016-10-17 15:17:14 +03:00
}
}
func gomobileTool ( subcmd string , args ... string ) * exec . Cmd {
cmd := exec . Command ( filepath . Join ( GOBIN , "gomobile" ) , subcmd )
cmd . Args = append ( cmd . Args , args ... )
cmd . Env = [ ] string {
2018-03-19 20:00:45 +03:00
"PATH=" + GOBIN + string ( os . PathListSeparator ) + os . Getenv ( "PATH" ) ,
2016-10-17 15:17:14 +03:00
}
for _ , e := range os . Environ ( ) {
2020-07-23 13:34:08 +03:00
if strings . HasPrefix ( e , "GOPATH=" ) || strings . HasPrefix ( e , "PATH=" ) || strings . HasPrefix ( e , "GOBIN=" ) {
2016-10-17 15:17:14 +03:00
continue
}
cmd . Env = append ( cmd . Env , e )
}
2020-07-23 13:34:08 +03:00
cmd . Env = append ( cmd . Env , "GOBIN=" + GOBIN )
2016-10-17 15:17:14 +03:00
return cmd
}
type mavenMetadata struct {
Version string
2016-11-09 12:13:37 +03:00
Package string
Develop bool
2016-10-17 15:17:14 +03:00
Contributors [ ] mavenContributor
}
type mavenContributor struct {
Name string
Email string
}
func newMavenMetadata ( env build . Environment ) mavenMetadata {
// Collect the list of authors from the repo root
contribs := [ ] mavenContributor { }
if authors , err := os . Open ( "AUTHORS" ) ; err == nil {
defer authors . Close ( )
scanner := bufio . NewScanner ( authors )
for scanner . Scan ( ) {
// Skip any whitespace from the authors list
line := strings . TrimSpace ( scanner . Text ( ) )
if line == "" || line [ 0 ] == '#' {
continue
}
// Split the author and insert as a contributor
2016-11-22 19:35:49 +03:00
re := regexp . MustCompile ( "([^<]+) <(.+)>" )
2016-10-17 15:17:14 +03:00
parts := re . FindStringSubmatch ( line )
if len ( parts ) == 3 {
contribs = append ( contribs , mavenContributor { Name : parts [ 1 ] , Email : parts [ 2 ] } )
}
}
}
2016-11-09 12:13:37 +03:00
// Render the version and package strings
2018-07-30 11:56:40 +03:00
version := params . Version
2016-11-09 12:13:37 +03:00
if isUnstableBuild ( env ) {
version += "-SNAPSHOT"
}
2016-10-17 15:17:14 +03:00
return mavenMetadata {
2016-11-09 12:13:37 +03:00
Version : version ,
Package : "geth-" + version ,
Develop : isUnstableBuild ( env ) ,
2016-10-17 15:17:14 +03:00
Contributors : contribs ,
}
}
2016-11-09 12:13:37 +03:00
// XCode frameworks
func doXCodeFramework ( cmdline [ ] string ) {
var (
2016-11-25 13:34:19 +03:00
local = flag . Bool ( "local" , false , ` Flag whether we're only doing a local build (skip Maven artifacts) ` )
2016-11-09 12:13:37 +03:00
signer = flag . String ( "signer" , "" , ` Environment variable holding the signing key (e.g. IOS_SIGNING_KEY) ` )
deploy = flag . String ( "deploy" , "" , ` Destination to deploy the archive (usually "trunk") ` )
upload = flag . String ( "upload" , "" , ` Destination to upload the archives (usually "gethstore/builds") ` )
)
flag . CommandLine . Parse ( cmdline )
env := build . Env ( )
// Build the iOS XCode framework
2018-03-19 20:00:45 +03:00
build . MustRun ( goTool ( "get" , "golang.org/x/mobile/cmd/gomobile" , "golang.org/x/mobile/cmd/gobind" ) )
2016-11-25 13:34:19 +03:00
build . MustRun ( gomobileTool ( "init" ) )
2019-08-22 14:16:48 +03:00
bind := gomobileTool ( "bind" , "-ldflags" , "-s -w" , "--target" , "ios" , "-v" , "github.com/ethereum/go-ethereum/mobile" )
2016-11-09 12:13:37 +03:00
2016-11-25 13:34:19 +03:00
if * local {
// If we're building locally, use the build folder and stop afterwards
2020-07-23 13:34:08 +03:00
bind . Dir = GOBIN
2016-11-25 13:34:19 +03:00
build . MustRun ( bind )
return
}
2018-07-30 11:56:40 +03:00
archive := "geth-" + archiveBasename ( "ios" , params . ArchiveVersion ( env . Commit ) )
2016-11-09 12:13:37 +03:00
if err := os . Mkdir ( archive , os . ModePerm ) ; err != nil {
log . Fatal ( err )
2016-10-17 15:17:14 +03:00
}
2016-11-09 12:13:37 +03:00
bind . Dir , _ = filepath . Abs ( archive )
build . MustRun ( bind )
build . MustRunCommand ( "tar" , "-zcvf" , archive + ".tar.gz" , archive )
// Skip CocoaPods deploy and Azure upload for PR builds
maybeSkipArchive ( env )
// Sign and upload the framework to Azure
if err := archiveUpload ( archive + ".tar.gz" , * upload , * signer ) ; err != nil {
log . Fatal ( err )
}
// Prepare and upload a PodSpec to CocoaPods
if * deploy != "" {
2016-11-22 19:35:49 +03:00
meta := newPodMetadata ( env , archive )
2016-11-28 13:56:13 +03:00
build . Render ( "build/pod.podspec" , "Geth.podspec" , 0755 , meta )
2020-11-05 12:52:35 +03:00
build . MustRunCommand ( "pod" , * deploy , "push" , "Geth.podspec" , "--allow-warnings" )
2016-11-09 12:13:37 +03:00
}
}
type podMetadata struct {
Version string
Commit string
2016-11-22 19:35:49 +03:00
Archive string
2016-11-09 12:13:37 +03:00
Contributors [ ] podContributor
2016-10-17 15:17:14 +03:00
}
2016-11-09 12:13:37 +03:00
type podContributor struct {
Name string
Email string
}
2016-11-22 19:35:49 +03:00
func newPodMetadata ( env build . Environment , archive string ) podMetadata {
2016-11-09 12:13:37 +03:00
// Collect the list of authors from the repo root
contribs := [ ] podContributor { }
if authors , err := os . Open ( "AUTHORS" ) ; err == nil {
defer authors . Close ( )
scanner := bufio . NewScanner ( authors )
for scanner . Scan ( ) {
// Skip any whitespace from the authors list
line := strings . TrimSpace ( scanner . Text ( ) )
if line == "" || line [ 0 ] == '#' {
continue
}
// Split the author and insert as a contributor
2016-11-22 19:35:49 +03:00
re := regexp . MustCompile ( "([^<]+) <(.+)>" )
2016-11-09 12:13:37 +03:00
parts := re . FindStringSubmatch ( line )
if len ( parts ) == 3 {
contribs = append ( contribs , podContributor { Name : parts [ 1 ] , Email : parts [ 2 ] } )
}
}
}
2018-07-30 11:56:40 +03:00
version := params . Version
2016-11-09 12:13:37 +03:00
if isUnstableBuild ( env ) {
2016-11-28 13:56:13 +03:00
version += "-unstable." + env . Buildnum
2016-11-09 12:13:37 +03:00
}
return podMetadata {
2016-11-22 19:35:49 +03:00
Archive : archive ,
2016-11-28 13:56:13 +03:00
Version : version ,
2016-11-09 12:13:37 +03:00
Commit : env . Commit ,
Contributors : contribs ,
}
2016-11-09 00:55:39 +03:00
}
2016-08-08 13:41:55 +03:00
// Cross compilation
func doXgo ( cmdline [ ] string ) {
2017-03-01 11:47:55 +03:00
var (
alltools = flag . Bool ( "alltools" , false , ` Flag whether we're building all known tools, or only on in particular ` )
)
2016-09-30 23:03:08 +03:00
flag . CommandLine . Parse ( cmdline )
env := build . Env ( )
2016-08-08 13:41:55 +03:00
// Make sure xgo is available for cross compilation
gogetxgo := goTool ( "get" , "github.com/karalabe/xgo" )
build . MustRun ( gogetxgo )
2017-03-01 11:47:55 +03:00
// If all tools building is requested, build everything the builder wants
args := append ( buildFlags ( env ) , flag . Args ( ) ... )
if * alltools {
2017-03-03 13:18:44 +03:00
args = append ( args , [ ] string { "--dest" , GOBIN } ... )
2019-05-17 02:06:20 +03:00
for _ , res := range allToolsArchiveFiles {
2017-03-01 11:47:55 +03:00
if strings . HasPrefix ( res , GOBIN ) {
// Binary tool found, cross build it explicitly
args = append ( args , "./" + filepath . Join ( "cmd" , filepath . Base ( res ) ) )
xgo := xgoTool ( args )
build . MustRun ( xgo )
args = args [ : len ( args ) - 1 ]
}
}
return
}
// Otherwise xxecute the explicit cross compilation
2017-03-03 13:18:44 +03:00
path := args [ len ( args ) - 1 ]
args = append ( args [ : len ( args ) - 1 ] , [ ] string { "--dest" , GOBIN , path } ... )
2017-03-01 11:47:55 +03:00
xgo := xgoTool ( args )
2016-09-30 23:03:08 +03:00
build . MustRun ( xgo )
2016-08-08 13:41:55 +03:00
}
2016-09-30 23:03:08 +03:00
func xgoTool ( args [ ] string ) * exec . Cmd {
2016-08-08 13:41:55 +03:00
cmd := exec . Command ( filepath . Join ( GOBIN , "xgo" ) , args ... )
2019-11-20 15:56:07 +03:00
cmd . Env = os . Environ ( )
cmd . Env = append ( cmd . Env , [ ] string {
2016-08-08 13:41:55 +03:00
"GOBIN=" + GOBIN ,
2019-11-20 15:56:07 +03:00
} ... )
2016-08-08 13:41:55 +03:00
return cmd
}
2017-04-06 13:53:33 +03:00
// Binary distribution cleanups
func doPurge ( cmdline [ ] string ) {
var (
store = flag . String ( "store" , "" , ` Destination from where to purge archives (usually "gethstore/builds") ` )
2018-09-28 21:05:46 +03:00
limit = flag . Int ( "days" , 30 , ` Age threshold above which to delete unstable archives ` )
2017-04-06 13:53:33 +03:00
)
flag . CommandLine . Parse ( cmdline )
if env := build . Env ( ) ; ! env . IsCronJob {
log . Printf ( "skipping because not a cron job" )
os . Exit ( 0 )
}
// Create the azure authentication and list the current archives
auth := build . AzureBlobstoreConfig {
Account : strings . Split ( * store , "/" ) [ 0 ] ,
Token : os . Getenv ( "AZURE_BLOBSTORE_TOKEN" ) ,
Container : strings . SplitN ( * store , "/" , 2 ) [ 1 ] ,
}
blobs , err := build . AzureBlobstoreList ( auth )
if err != nil {
log . Fatal ( err )
}
2020-07-04 21:10:48 +03:00
fmt . Printf ( "Found %d blobs\n" , len ( blobs ) )
2017-04-06 13:53:33 +03:00
// Iterate over the blobs, collect and sort all unstable builds
for i := 0 ; i < len ( blobs ) ; i ++ {
if ! strings . Contains ( blobs [ i ] . Name , "unstable" ) {
blobs = append ( blobs [ : i ] , blobs [ i + 1 : ] ... )
i --
}
}
for i := 0 ; i < len ( blobs ) ; i ++ {
for j := i + 1 ; j < len ( blobs ) ; j ++ {
2018-07-25 17:51:24 +03:00
if blobs [ i ] . Properties . LastModified . After ( blobs [ j ] . Properties . LastModified ) {
2017-04-06 13:53:33 +03:00
blobs [ i ] , blobs [ j ] = blobs [ j ] , blobs [ i ]
}
}
}
// Filter out all archives more recent that the given threshold
for i , blob := range blobs {
2018-07-25 17:51:24 +03:00
if time . Since ( blob . Properties . LastModified ) < time . Duration ( * limit ) * 24 * time . Hour {
2017-04-06 13:53:33 +03:00
blobs = blobs [ : i ]
break
}
}
2020-07-04 21:10:48 +03:00
fmt . Printf ( "Deleting %d blobs\n" , len ( blobs ) )
2017-04-06 13:53:33 +03:00
// Delete all marked as such and return
if err := build . AzureBlobstoreDelete ( auth , blobs ) ; err != nil {
log . Fatal ( err )
}
}