ci.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. // Copyright 2016 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. // +build none
  17. /*
  18. The ci command is called from Continuous Integration scripts.
  19. Usage: go run ci.go <command> <command flags/arguments>
  20. Available commands are:
  21. install [-arch architecture] [ packages... ] -- builds packages and executables
  22. test [ -coverage ] [ -vet ] [ packages... ] -- runs the tests
  23. archive [-arch architecture] [ -type zip|tar ] [ -signer key-envvar ] [ -upload dest ] -- archives build artefacts
  24. importkeys -- imports signing keys from env
  25. debsrc [ -signer key-id ] [ -upload dest ] -- creates a debian source package
  26. nsis -- creates a Windows NSIS installer
  27. xgo [ options ] -- cross builds according to options
  28. For all commands, -n prevents execution of external programs (dry run mode).
  29. */
  30. package main
  31. import (
  32. "bytes"
  33. "encoding/base64"
  34. "flag"
  35. "fmt"
  36. "go/parser"
  37. "go/token"
  38. "io/ioutil"
  39. "log"
  40. "os"
  41. "os/exec"
  42. "path/filepath"
  43. "runtime"
  44. "strings"
  45. "time"
  46. "github.com/ethereum/go-ethereum/internal/build"
  47. )
  48. var (
  49. // Files that end up in the geth*.zip archive.
  50. gethArchiveFiles = []string{
  51. "COPYING",
  52. executablePath("geth"),
  53. }
  54. // Files that end up in the geth-alltools*.zip archive.
  55. allToolsArchiveFiles = []string{
  56. "COPYING",
  57. executablePath("abigen"),
  58. executablePath("evm"),
  59. executablePath("geth"),
  60. executablePath("rlpdump"),
  61. }
  62. // A debian package is created for all executables listed here.
  63. debExecutables = []debExecutable{
  64. {
  65. Name: "geth",
  66. Description: "Ethereum CLI client.",
  67. },
  68. {
  69. Name: "rlpdump",
  70. Description: "Developer utility tool that prints RLP structures.",
  71. },
  72. {
  73. Name: "evm",
  74. Description: "Developer utility version of the EVM (Ethereum Virtual Machine) that is capable of running bytecode snippets within a configurable environment and execution mode.",
  75. },
  76. {
  77. Name: "abigen",
  78. Description: "Source code generator to convert Ethereum contract definitions into easy to use, compile-time type-safe Go packages.",
  79. },
  80. }
  81. // Distros for which packages are created.
  82. // Note: vivid is unsupported because there is no golang-1.6 package for it.
  83. debDistros = []string{"trusty", "wily", "xenial", "yakkety"}
  84. )
  85. var GOBIN, _ = filepath.Abs(filepath.Join("build", "bin"))
  86. func executablePath(name string) string {
  87. if runtime.GOOS == "windows" {
  88. name += ".exe"
  89. }
  90. return filepath.Join(GOBIN, name)
  91. }
  92. func main() {
  93. log.SetFlags(log.Lshortfile)
  94. if _, err := os.Stat(filepath.Join("build", "ci.go")); os.IsNotExist(err) {
  95. log.Fatal("this script must be run from the root of the repository")
  96. }
  97. if len(os.Args) < 2 {
  98. log.Fatal("need subcommand as first argument")
  99. }
  100. switch os.Args[1] {
  101. case "install":
  102. doInstall(os.Args[2:])
  103. case "test":
  104. doTest(os.Args[2:])
  105. case "archive":
  106. doArchive(os.Args[2:])
  107. case "debsrc":
  108. doDebianSource(os.Args[2:])
  109. case "nsis":
  110. doWindowsInstaller(os.Args[2:])
  111. case "xgo":
  112. doXgo(os.Args[2:])
  113. default:
  114. log.Fatal("unknown command ", os.Args[1])
  115. }
  116. }
  117. // Compiling
  118. func doInstall(cmdline []string) {
  119. var (
  120. arch = flag.String("arch", "", "Architecture to cross build for")
  121. )
  122. flag.CommandLine.Parse(cmdline)
  123. env := build.Env()
  124. // Check Go version. People regularly open issues about compilation
  125. // failure with outdated Go. This should save them the trouble.
  126. if runtime.Version() < "go1.4" && !strings.HasPrefix(runtime.Version(), "devel") {
  127. log.Println("You have Go version", runtime.Version())
  128. log.Println("go-ethereum requires at least Go version 1.4 and cannot")
  129. log.Println("be compiled with an earlier version. Please upgrade your Go installation.")
  130. os.Exit(1)
  131. }
  132. // Compile packages given as arguments, or everything if there are no arguments.
  133. packages := []string{"./..."}
  134. if flag.NArg() > 0 {
  135. packages = flag.Args()
  136. }
  137. if *arch == "" || *arch == runtime.GOARCH {
  138. goinstall := goTool("install", buildFlags(env)...)
  139. goinstall.Args = append(goinstall.Args, "-v")
  140. goinstall.Args = append(goinstall.Args, packages...)
  141. build.MustRun(goinstall)
  142. return
  143. }
  144. // If we are cross compiling to ARMv5 ARMv6 or ARMv7, clean any prvious builds
  145. if *arch == "arm" {
  146. os.RemoveAll(filepath.Join(runtime.GOROOT(), "pkg", runtime.GOOS+"_arm"))
  147. for _, path := range filepath.SplitList(build.GOPATH()) {
  148. os.RemoveAll(filepath.Join(path, "pkg", runtime.GOOS+"_arm"))
  149. }
  150. }
  151. // Seems we are cross compiling, work around forbidden GOBIN
  152. goinstall := goToolArch(*arch, "install", buildFlags(env)...)
  153. goinstall.Args = append(goinstall.Args, "-v")
  154. goinstall.Args = append(goinstall.Args, []string{"-buildmode", "archive"}...)
  155. goinstall.Args = append(goinstall.Args, packages...)
  156. build.MustRun(goinstall)
  157. if cmds, err := ioutil.ReadDir("cmd"); err == nil {
  158. for _, cmd := range cmds {
  159. pkgs, err := parser.ParseDir(token.NewFileSet(), filepath.Join(".", "cmd", cmd.Name()), nil, parser.PackageClauseOnly)
  160. if err != nil {
  161. log.Fatal(err)
  162. }
  163. for name, _ := range pkgs {
  164. if name == "main" {
  165. gobuild := goToolArch(*arch, "build", buildFlags(env)...)
  166. gobuild.Args = append(gobuild.Args, "-v")
  167. gobuild.Args = append(gobuild.Args, []string{"-o", executablePath(cmd.Name())}...)
  168. gobuild.Args = append(gobuild.Args, "."+string(filepath.Separator)+filepath.Join("cmd", cmd.Name()))
  169. build.MustRun(gobuild)
  170. break
  171. }
  172. }
  173. }
  174. }
  175. }
  176. func buildFlags(env build.Environment) (flags []string) {
  177. if os.Getenv("GO_OPENCL") != "" {
  178. flags = append(flags, "-tags", "opencl")
  179. }
  180. // Since Go 1.5, the separator char for link time assignments
  181. // is '=' and using ' ' prints a warning. However, Go < 1.5 does
  182. // not support using '='.
  183. sep := " "
  184. if runtime.Version() > "go1.5" || strings.Contains(runtime.Version(), "devel") {
  185. sep = "="
  186. }
  187. // Set gitCommit constant via link-time assignment.
  188. if env.Commit != "" {
  189. flags = append(flags, "-ldflags", "-X main.gitCommit"+sep+env.Commit)
  190. }
  191. return flags
  192. }
  193. func goTool(subcmd string, args ...string) *exec.Cmd {
  194. return goToolArch(runtime.GOARCH, subcmd, args...)
  195. }
  196. func goToolArch(arch string, subcmd string, args ...string) *exec.Cmd {
  197. gocmd := filepath.Join(runtime.GOROOT(), "bin", "go")
  198. cmd := exec.Command(gocmd, subcmd)
  199. cmd.Args = append(cmd.Args, args...)
  200. cmd.Env = []string{
  201. "GO15VENDOREXPERIMENT=1",
  202. "GOPATH=" + build.GOPATH(),
  203. }
  204. if arch == "" || arch == runtime.GOARCH {
  205. cmd.Env = append(cmd.Env, "GOBIN="+GOBIN)
  206. } else {
  207. cmd.Env = append(cmd.Env, "CGO_ENABLED=1")
  208. cmd.Env = append(cmd.Env, "GOARCH="+arch)
  209. }
  210. for _, e := range os.Environ() {
  211. if strings.HasPrefix(e, "GOPATH=") || strings.HasPrefix(e, "GOBIN=") {
  212. continue
  213. }
  214. cmd.Env = append(cmd.Env, e)
  215. }
  216. return cmd
  217. }
  218. // Running The Tests
  219. //
  220. // "tests" also includes static analysis tools such as vet.
  221. func doTest(cmdline []string) {
  222. var (
  223. vet = flag.Bool("vet", false, "Whether to run go vet")
  224. coverage = flag.Bool("coverage", false, "Whether to record code coverage")
  225. )
  226. flag.CommandLine.Parse(cmdline)
  227. packages := []string{"./..."}
  228. if len(flag.CommandLine.Args()) > 0 {
  229. packages = flag.CommandLine.Args()
  230. }
  231. if len(packages) == 1 && packages[0] == "./..." {
  232. // Resolve ./... manually since go vet will fail on vendored stuff
  233. out, err := goTool("list", "./...").CombinedOutput()
  234. if err != nil {
  235. log.Fatalf("package listing failed: %v\n%s", err, string(out))
  236. }
  237. packages = []string{}
  238. for _, line := range strings.Split(string(out), "\n") {
  239. if !strings.Contains(line, "vendor") {
  240. packages = append(packages, strings.TrimSpace(line))
  241. }
  242. }
  243. }
  244. // Run analysis tools before the tests.
  245. if *vet {
  246. build.MustRun(goTool("vet", packages...))
  247. }
  248. // Run the actual tests.
  249. gotest := goTool("test")
  250. // Test a single package at a time. CI builders are slow
  251. // and some tests run into timeouts under load.
  252. gotest.Args = append(gotest.Args, "-p", "1")
  253. if *coverage {
  254. gotest.Args = append(gotest.Args, "-covermode=atomic", "-cover")
  255. }
  256. gotest.Args = append(gotest.Args, packages...)
  257. build.MustRun(gotest)
  258. }
  259. // Release Packaging
  260. func doArchive(cmdline []string) {
  261. var (
  262. arch = flag.String("arch", runtime.GOARCH, "Architecture cross packaging")
  263. atype = flag.String("type", "zip", "Type of archive to write (zip|tar)")
  264. signer = flag.String("signer", "", `Environment variable holding the signing key (e.g. LINUX_SIGNING_KEY)`)
  265. upload = flag.String("upload", "", `Destination to upload the archives (usually "gethstore/builds")`)
  266. ext string
  267. )
  268. flag.CommandLine.Parse(cmdline)
  269. switch *atype {
  270. case "zip":
  271. ext = ".zip"
  272. case "tar":
  273. ext = ".tar.gz"
  274. default:
  275. log.Fatal("unknown archive type: ", atype)
  276. }
  277. var (
  278. env = build.Env()
  279. base = archiveBasename(*arch, env)
  280. geth = "geth-" + base + ext
  281. alltools = "geth-alltools-" + base + ext
  282. )
  283. maybeSkipArchive(env)
  284. if err := build.WriteArchive(geth, gethArchiveFiles); err != nil {
  285. log.Fatal(err)
  286. }
  287. if err := build.WriteArchive(alltools, allToolsArchiveFiles); err != nil {
  288. log.Fatal(err)
  289. }
  290. for _, archive := range []string{geth, alltools} {
  291. if err := archiveUpload(archive, *upload, *signer); err != nil {
  292. log.Fatal(err)
  293. }
  294. }
  295. }
  296. func archiveBasename(arch string, env build.Environment) string {
  297. platform := runtime.GOOS + "-" + arch
  298. if arch == "arm" {
  299. platform += os.Getenv("GOARM")
  300. }
  301. archive := platform + "-" + build.VERSION()
  302. if isUnstableBuild(env) {
  303. archive += "-unstable"
  304. }
  305. if env.Commit != "" {
  306. archive += "-" + env.Commit[:8]
  307. }
  308. return archive
  309. }
  310. func archiveUpload(archive string, blobstore string, signer string) error {
  311. // If signing was requested, generate the signature files
  312. if signer != "" {
  313. pgpkey, err := base64.StdEncoding.DecodeString(os.Getenv(signer))
  314. if err != nil {
  315. return fmt.Errorf("invalid base64 %s", signer)
  316. }
  317. if err := build.PGPSignFile(archive, archive+".asc", string(pgpkey)); err != nil {
  318. return err
  319. }
  320. }
  321. // If uploading to Azure was requested, push the archive possibly with its signature
  322. if blobstore != "" {
  323. auth := build.AzureBlobstoreConfig{
  324. Account: strings.Split(blobstore, "/")[0],
  325. Token: os.Getenv("AZURE_BLOBSTORE_TOKEN"),
  326. Container: strings.SplitN(blobstore, "/", 2)[1],
  327. }
  328. if err := build.AzureBlobstoreUpload(archive, archive, auth); err != nil {
  329. return err
  330. }
  331. if signer != "" {
  332. if err := build.AzureBlobstoreUpload(archive+".asc", archive+".asc", auth); err != nil {
  333. return err
  334. }
  335. }
  336. }
  337. return nil
  338. }
  339. // skips archiving for some build configurations.
  340. func maybeSkipArchive(env build.Environment) {
  341. if env.IsPullRequest {
  342. log.Printf("skipping because this is a PR build")
  343. os.Exit(0)
  344. }
  345. if env.Branch != "develop" && !strings.HasPrefix(env.Tag, "v1.") {
  346. log.Printf("skipping because branch %q, tag %q is not on the whitelist", env.Branch, env.Tag)
  347. os.Exit(0)
  348. }
  349. }
  350. // Debian Packaging
  351. func doDebianSource(cmdline []string) {
  352. var (
  353. signer = flag.String("signer", "", `Signing key name, also used as package author`)
  354. upload = flag.String("upload", "", `Where to upload the source package (usually "ppa:ethereum/ethereum")`)
  355. workdir = flag.String("workdir", "", `Output directory for packages (uses temp dir if unset)`)
  356. now = time.Now()
  357. )
  358. flag.CommandLine.Parse(cmdline)
  359. *workdir = makeWorkdir(*workdir)
  360. env := build.Env()
  361. maybeSkipArchive(env)
  362. // Import the signing key.
  363. if b64key := os.Getenv("PPA_SIGNING_KEY"); b64key != "" {
  364. key, err := base64.StdEncoding.DecodeString(b64key)
  365. if err != nil {
  366. log.Fatal("invalid base64 PPA_SIGNING_KEY")
  367. }
  368. gpg := exec.Command("gpg", "--import")
  369. gpg.Stdin = bytes.NewReader(key)
  370. build.MustRun(gpg)
  371. }
  372. // Create the packages.
  373. for _, distro := range debDistros {
  374. meta := newDebMetadata(distro, *signer, env, now)
  375. pkgdir := stageDebianSource(*workdir, meta)
  376. debuild := exec.Command("debuild", "-S", "-sa", "-us", "-uc")
  377. debuild.Dir = pkgdir
  378. build.MustRun(debuild)
  379. changes := fmt.Sprintf("%s_%s_source.changes", meta.Name(), meta.VersionString())
  380. changes = filepath.Join(*workdir, changes)
  381. if *signer != "" {
  382. build.MustRunCommand("debsign", changes)
  383. }
  384. if *upload != "" {
  385. build.MustRunCommand("dput", *upload, changes)
  386. }
  387. }
  388. }
  389. func makeWorkdir(wdflag string) string {
  390. var err error
  391. if wdflag != "" {
  392. err = os.MkdirAll(wdflag, 0744)
  393. } else {
  394. wdflag, err = ioutil.TempDir("", "geth-build-")
  395. }
  396. if err != nil {
  397. log.Fatal(err)
  398. }
  399. return wdflag
  400. }
  401. func isUnstableBuild(env build.Environment) bool {
  402. if env.Branch != "develop" && env.Tag != "" {
  403. return false
  404. }
  405. return true
  406. }
  407. type debMetadata struct {
  408. Env build.Environment
  409. // go-ethereum version being built. Note that this
  410. // is not the debian package version. The package version
  411. // is constructed by VersionString.
  412. Version string
  413. Author string // "name <email>", also selects signing key
  414. Distro, Time string
  415. Executables []debExecutable
  416. }
  417. type debExecutable struct {
  418. Name, Description string
  419. }
  420. func newDebMetadata(distro, author string, env build.Environment, t time.Time) debMetadata {
  421. if author == "" {
  422. // No signing key, use default author.
  423. author = "Ethereum Builds <fjl@ethereum.org>"
  424. }
  425. return debMetadata{
  426. Env: env,
  427. Author: author,
  428. Distro: distro,
  429. Version: build.VERSION(),
  430. Time: t.Format(time.RFC1123Z),
  431. Executables: debExecutables,
  432. }
  433. }
  434. // Name returns the name of the metapackage that depends
  435. // on all executable packages.
  436. func (meta debMetadata) Name() string {
  437. if isUnstableBuild(meta.Env) {
  438. return "ethereum-unstable"
  439. }
  440. return "ethereum"
  441. }
  442. // VersionString returns the debian version of the packages.
  443. func (meta debMetadata) VersionString() string {
  444. vsn := meta.Version
  445. if meta.Env.Buildnum != "" {
  446. vsn += "+build" + meta.Env.Buildnum
  447. }
  448. if meta.Distro != "" {
  449. vsn += "+" + meta.Distro
  450. }
  451. return vsn
  452. }
  453. // ExeList returns the list of all executable packages.
  454. func (meta debMetadata) ExeList() string {
  455. names := make([]string, len(meta.Executables))
  456. for i, e := range meta.Executables {
  457. names[i] = meta.ExeName(e)
  458. }
  459. return strings.Join(names, ", ")
  460. }
  461. // ExeName returns the package name of an executable package.
  462. func (meta debMetadata) ExeName(exe debExecutable) string {
  463. if isUnstableBuild(meta.Env) {
  464. return exe.Name + "-unstable"
  465. }
  466. return exe.Name
  467. }
  468. // ExeConflicts returns the content of the Conflicts field
  469. // for executable packages.
  470. func (meta debMetadata) ExeConflicts(exe debExecutable) string {
  471. if isUnstableBuild(meta.Env) {
  472. // Set up the conflicts list so that the *-unstable packages
  473. // cannot be installed alongside the regular version.
  474. //
  475. // https://www.debian.org/doc/debian-policy/ch-relationships.html
  476. // is very explicit about Conflicts: and says that Breaks: should
  477. // be preferred and the conflicting files should be handled via
  478. // alternates. We might do this eventually but using a conflict is
  479. // easier now.
  480. return "ethereum, " + exe.Name
  481. }
  482. return ""
  483. }
  484. func stageDebianSource(tmpdir string, meta debMetadata) (pkgdir string) {
  485. pkg := meta.Name() + "-" + meta.VersionString()
  486. pkgdir = filepath.Join(tmpdir, pkg)
  487. if err := os.Mkdir(pkgdir, 0755); err != nil {
  488. log.Fatal(err)
  489. }
  490. // Copy the source code.
  491. build.MustRunCommand("git", "checkout-index", "-a", "--prefix", pkgdir+string(filepath.Separator))
  492. // Put the debian build files in place.
  493. debian := filepath.Join(pkgdir, "debian")
  494. build.Render("build/deb.rules", filepath.Join(debian, "rules"), 0755, meta)
  495. build.Render("build/deb.changelog", filepath.Join(debian, "changelog"), 0644, meta)
  496. build.Render("build/deb.control", filepath.Join(debian, "control"), 0644, meta)
  497. build.Render("build/deb.copyright", filepath.Join(debian, "copyright"), 0644, meta)
  498. build.RenderString("8\n", filepath.Join(debian, "compat"), 0644, meta)
  499. build.RenderString("3.0 (native)\n", filepath.Join(debian, "source/format"), 0644, meta)
  500. for _, exe := range meta.Executables {
  501. install := filepath.Join(debian, meta.ExeName(exe)+".install")
  502. docs := filepath.Join(debian, meta.ExeName(exe)+".docs")
  503. build.Render("build/deb.install", install, 0644, exe)
  504. build.Render("build/deb.docs", docs, 0644, exe)
  505. }
  506. return pkgdir
  507. }
  508. // Windows installer
  509. func doWindowsInstaller(cmdline []string) {
  510. // Parse the flags and make skip installer generation on PRs
  511. var (
  512. arch = flag.String("arch", runtime.GOARCH, "Architecture for cross build packaging")
  513. signer = flag.String("signer", "", `Environment variable holding the signing key (e.g. WINDOWS_SIGNING_KEY)`)
  514. upload = flag.String("upload", "", `Destination to upload the archives (usually "gethstore/builds")`)
  515. workdir = flag.String("workdir", "", `Output directory for packages (uses temp dir if unset)`)
  516. )
  517. flag.CommandLine.Parse(cmdline)
  518. *workdir = makeWorkdir(*workdir)
  519. env := build.Env()
  520. maybeSkipArchive(env)
  521. // Aggregate binaries that are included in the installer
  522. var (
  523. devTools []string
  524. allTools []string
  525. gethTool string
  526. )
  527. for _, file := range allToolsArchiveFiles {
  528. if file == "COPYING" { // license, copied later
  529. continue
  530. }
  531. allTools = append(allTools, filepath.Base(file))
  532. if filepath.Base(file) == "geth.exe" {
  533. gethTool = file
  534. } else {
  535. devTools = append(devTools, file)
  536. }
  537. }
  538. // Render NSIS scripts: Installer NSIS contains two installer sections,
  539. // first section contains the geth binary, second section holds the dev tools.
  540. templateData := map[string]interface{}{
  541. "License": "COPYING",
  542. "Geth": gethTool,
  543. "DevTools": devTools,
  544. }
  545. build.Render("build/nsis.geth.nsi", filepath.Join(*workdir, "geth.nsi"), 0644, nil)
  546. build.Render("build/nsis.install.nsh", filepath.Join(*workdir, "install.nsh"), 0644, templateData)
  547. build.Render("build/nsis.uninstall.nsh", filepath.Join(*workdir, "uninstall.nsh"), 0644, allTools)
  548. build.Render("build/nsis.envvarupdate.nsh", filepath.Join(*workdir, "EnvVarUpdate.nsh"), 0644, nil)
  549. build.CopyFile(filepath.Join(*workdir, "SimpleFC.dll"), "build/nsis.simplefc.dll", 0755)
  550. build.CopyFile(filepath.Join(*workdir, "COPYING"), "COPYING", 0755)
  551. // Build the installer. This assumes that all the needed files have been previously
  552. // built (don't mix building and packaging to keep cross compilation complexity to a
  553. // minimum).
  554. version := strings.Split(build.VERSION(), ".")
  555. if env.Commit != "" {
  556. version[2] += "-" + env.Commit[:8]
  557. }
  558. installer, _ := filepath.Abs("geth-" + archiveBasename(*arch, env) + ".exe")
  559. build.MustRunCommand("makensis.exe",
  560. "/DOUTPUTFILE="+installer,
  561. "/DMAJORVERSION="+version[0],
  562. "/DMINORVERSION="+version[1],
  563. "/DBUILDVERSION="+version[2],
  564. "/DARCH="+*arch,
  565. filepath.Join(*workdir, "geth.nsi"),
  566. )
  567. // Sign and publish installer.
  568. if err := archiveUpload(installer, *upload, *signer); err != nil {
  569. log.Fatal(err)
  570. }
  571. }
  572. // Cross compilation
  573. func doXgo(cmdline []string) {
  574. flag.CommandLine.Parse(cmdline)
  575. env := build.Env()
  576. // Make sure xgo is available for cross compilation
  577. gogetxgo := goTool("get", "github.com/karalabe/xgo")
  578. build.MustRun(gogetxgo)
  579. // Execute the actual cross compilation
  580. xgo := xgoTool(append(buildFlags(env), flag.Args()...))
  581. build.MustRun(xgo)
  582. }
  583. func xgoTool(args []string) *exec.Cmd {
  584. cmd := exec.Command(filepath.Join(GOBIN, "xgo"), args...)
  585. cmd.Env = []string{
  586. "GOPATH=" + build.GOPATH(),
  587. "GOBIN=" + GOBIN,
  588. }
  589. for _, e := range os.Environ() {
  590. if strings.HasPrefix(e, "GOPATH=") || strings.HasPrefix(e, "GOBIN=") {
  591. continue
  592. }
  593. cmd.Env = append(cmd.Env, e)
  594. }
  595. return cmd
  596. }