forked from vanadium-archive/go.devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile.go
64 lines (54 loc) · 2.01 KB
/
makefile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package test
import (
"time"
"v.io/jiri"
"v.io/jiri/collect"
"v.io/jiri/runutil"
"v.io/x/devtools/internal/test"
"v.io/x/lib/envvar"
)
// runMakefileTest is a helper for running tests through make commands.
func runMakefileTest(jirix *jiri.X, testName, testDir, target string, env map[string]string, profiles []string, timeout time.Duration) (_ *test.Result, e error) {
return runMakefileTestWithExtraDeps(jirix, testName, testDir, target, env, profiles, nil, timeout)
}
// runMakefileTestWithExtraDeps is a helper for running tests through make commands with extra dependencies.
func runMakefileTestWithExtraDeps(jirix *jiri.X, testName, testDir, target string, env map[string]string, profiles []string, initExtraDeps func() (func() error, error), timeout time.Duration) (_ *test.Result, e error) {
// Install base profile first, before any test-specific profiles.
profiles = append([]string{"v23:base"}, profiles...)
// Initialize the test.
cleanup, err := initTest(jirix, testName, profiles)
if err != nil {
return nil, newInternalError(err, "Init")
}
defer collect.Error(func() error { return cleanup() }, &e)
if initExtraDeps != nil {
cleanup, err := initExtraDeps()
if err != nil {
return nil, newInternalError(err, "InitExtraDeps")
}
defer collect.Error(func() error { return cleanup() }, &e)
}
s := jirix.NewSeq()
// Set up the environment
merged := envvar.MergeMaps(jirix.Env(), env)
// Navigate to project directory, run make clean and make target.
err = s.Pushd(testDir).
Verbose(true).
Run("make", "clean").
Verbose(true).
Timeout(timeout).Env(merged).Last("make", target)
if err != nil {
if runutil.IsTimeout(err) {
return &test.Result{
Status: test.TimedOut,
TimeoutValue: timeout,
}, nil
} else {
return nil, newInternalError(err, "Make "+target)
}
}
return &test.Result{Status: test.Passed}, nil
}