/
build.go
72 lines (65 loc) · 1.71 KB
/
build.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
65
66
67
68
69
70
71
72
package build
import (
"fmt"
"os"
"path/filepath"
"github.com/apex/log"
"github.com/tarantool/tt/cli/cmdcontext"
"github.com/tarantool/tt/cli/config"
"github.com/tarantool/tt/cli/util"
)
// BuildCtx contains information for application building.
type BuildCtx struct {
// BuildDir is an application directory.
BuildDir string
// SpecFile is a rockspec file to be used for build.
SpecFile string
}
// FillCtx fills build context.
func FillCtx(buildCtx *BuildCtx, cliOpts *config.CliOpts, args []string) error {
workingDir, err := os.Getwd()
if err != nil {
return err
}
if len(args) > 1 {
return fmt.Errorf("too many args")
} else if len(args) == 1 {
appPath := args[0]
appName := filepath.Base(appPath)
if !filepath.IsAbs(appPath) {
var err error
appPath, err = filepath.Abs(filepath.Join(workingDir, appPath))
if err != nil {
return err
}
}
fileInfo, err := os.Stat(appPath)
if err != nil {
if !os.IsNotExist(err) {
return err
}
log.Debugf("%q does not exist. Looking for %q in instances enabled directory.",
appPath, appName)
appLink := filepath.Join(cliOpts.App.InstancesEnabled, appName)
if appPath, err = util.ResolveSymlink(appLink); err != nil {
return err
}
fileInfo, err = os.Stat(appPath)
if err != nil {
return err
}
}
if !fileInfo.IsDir() {
return fmt.Errorf("%s is not a directory", appPath)
}
buildCtx.BuildDir = appPath
log.Debugf("Application %q build directory: %q", appName, buildCtx.BuildDir)
} else {
buildCtx.BuildDir = workingDir
}
return nil
}
// Run builds an application.
func Run(cmdCtx *cmdcontext.CmdCtx, cliOpts *config.CliOpts, buildCtx *BuildCtx) error {
return buildLocal(cmdCtx, cliOpts, buildCtx)
}