goc/pkg/build/build.go

41 lines
933 B
Go
Raw Normal View History

2021-05-23 14:23:35 +00:00
package build
import (
2021-06-17 11:53:00 +00:00
"github.com/qiniu/goc/v2/pkg/cover"
2021-05-23 14:23:35 +00:00
"github.com/qiniu/goc/v2/pkg/flag"
"github.com/qiniu/goc/v2/pkg/log"
"github.com/spf13/cobra"
)
// Build struct a build
// most configurations are stored in global variables: config.GocConfig & config.GoConfig
type Build struct {
}
// NewBuild creates a Build struct
//
// consumes args, get package dirs, read project meta info.
func NewBuild(cmd *cobra.Command, args []string) *Build {
b := &Build{}
remainedArgs := flag.BuildCmdArgsParse(cmd, args)
flag.GetPackagesDir(remainedArgs)
b.readProjectMetaInfo()
b.displayProjectMetaInfo()
return b
}
// Build starts go build
//
// 1. copy project to temp,
// 2. inject cover variables and functions into the project,
// 3. build the project in temp.
func (b *Build) Build() {
b.copyProjectToTmp()
2021-06-17 11:53:00 +00:00
// defer b.clean()
2021-05-23 14:23:35 +00:00
log.Donef("project copied to temporary directory")
2021-06-17 11:53:00 +00:00
// inject cover vars
cover.Inject()
2021-05-23 14:23:35 +00:00
}