~sergiusens/snappy/tools-parted

« back to all changes in this revision

Viewing changes to _integration-tests/testutils/build/build.go

  • Committer: Sergio Schvezov
  • Date: 2015-07-30 18:46:22 UTC
  • mfrom: (576.1.1 tools-grub)
  • Revision ID: sergio.schvezov@canonical.com-20150730184622-mga36e3aevz09qw5
Merged tools-grub into tools-parted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- Mode: Go; indent-tabs-mode: t -*-
 
2
 
 
3
/*
 
4
 * Copyright (C) 2015 Canonical Ltd
 
5
 *
 
6
 * This program is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License version 3 as
 
8
 * published by the Free Software Foundation.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 *
 
18
 */
 
19
 
 
20
package build
 
21
 
 
22
import (
 
23
        "fmt"
 
24
        "os"
 
25
 
 
26
        "launchpad.net/snappy/_integration-tests/testutils"
 
27
)
 
28
 
 
29
const (
 
30
        // IntegrationTestName is the name of the test binary.
 
31
        IntegrationTestName = "integration.test"
 
32
        defaultGoArm        = "7"
 
33
        testsBinDir         = "_integration-tests/bin/"
 
34
)
 
35
 
 
36
// Assets builds the snappy and integration tests binaries for the target
 
37
// architecture.
 
38
func Assets(useSnappyFromBranch bool, arch string) {
 
39
        testutils.PrepareTargetDir(testsBinDir)
 
40
 
 
41
        if useSnappyFromBranch {
 
42
                // FIXME We need to build an image that has the snappy from the branch
 
43
                // installed. --elopio - 2015-06-25.
 
44
                buildSnappyCLI(arch)
 
45
        }
 
46
        buildTests(arch)
 
47
}
 
48
 
 
49
func buildSnappyCLI(arch string) {
 
50
        fmt.Println("Building snappy CLI...")
 
51
        // On the root of the project we have a directory called snappy, so we
 
52
        // output the binary for the tests in the tests directory.
 
53
        goCall(arch, "build", "-o", testsBinDir+"snappy", "./cmd/snappy")
 
54
}
 
55
 
 
56
func buildTests(arch string) {
 
57
        fmt.Println("Building tests...")
 
58
 
 
59
        goCall(arch, "test", "-c", "./_integration-tests/tests")
 
60
        // XXX Go test 1.3 does not have the output flag, so we move the
 
61
        // binaries after they are generated.
 
62
        os.Rename("tests.test", testsBinDir+IntegrationTestName)
 
63
}
 
64
 
 
65
func goCall(arch string, cmds ...string) {
 
66
        if arch != "" {
 
67
                defer os.Setenv("GOARCH", os.Getenv("GOARCH"))
 
68
                os.Setenv("GOARCH", arch)
 
69
                if arch == "arm" {
 
70
                        defer os.Setenv("GOARM", os.Getenv("GOARM"))
 
71
                        os.Setenv("GOARM", defaultGoArm)
 
72
                }
 
73
        }
 
74
        goCmd := append([]string{"go"}, cmds...)
 
75
        testutils.ExecCommand(goCmd...)
 
76
}