Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions plugins/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type BuildOptions struct {
Plugins []UsePluginInfo
BuildOutput string
Debug bool
Tags []string
}

var validPkgNameRegex = regexp.MustCompile(`^[a-zA-Z0-9]+$`)
Expand Down Expand Up @@ -212,6 +213,11 @@ func (b *Builder) goBuild(ctx context.Context) error {
args = append(args, "-trimpath")
}
args = append(args, "-ldflags", strings.Join(ldflags, " "))

if len(b.Tags) > 0 {
args = append(args, "-tags", strings.Join(b.Tags, " "))
}

// Run build.
cmd := b.env.NewCommand(ctx, b.env.Go(), args...)
err = b.env.RunCmd(ctx, cmd)
Expand Down Expand Up @@ -248,6 +254,11 @@ func (b *Builder) preBuild(ctx context.Context) error {
}

for pluginName, v := range pluginVersionMap {
if _, ok := b.BuildOptions.ModReplace[pluginName]; ok {
log.Debug("skipping prebuild script for replaced plugin %s", pluginName)
continue
}

packagePath, _ := getModulePath(pluginName, v)
if _, err = os.Stat(packagePath); os.IsNotExist(err) {
log.Debug("you don't have this module/version installed (%s)", packagePath)
Expand Down
3 changes: 3 additions & 0 deletions plugins/builder/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type builderInput struct {
out string
timeout string
version string
tags []string
plugins []string
replace []string
debug bool
Expand All @@ -53,6 +54,7 @@ func (p *Plugin) CobraAddCommands(rootCmd *cobra.Command) error {
buildCmd.Flags().StringVarP(&flags.out, "output", "o", "", `Build output file, by default application name is used`)
buildCmd.Flags().StringVar(&flags.version, "build-version", "", `Arbitrary version of application`)
buildCmd.Flags().StringVarP(&flags.timeout, "timeout", "t", "120s", `Build timeout duration, example: 0, 100ms, 1h23m`)
buildCmd.Flags().StringSliceVarP(&flags.tags, "tag", "", nil, `Add build tags`)
buildCmd.Flags().StringSliceVarP(&flags.plugins, "plugin", "p", nil, `Include PLUGIN into the build with an optional version`)
buildCmd.Flags().StringSliceVarP(&flags.replace, "replace", "r", nil, `Replace go dependency, see "go mod edit -replace"`)
buildCmd.Flags().BoolVarP(&flags.debug, "debug", "d", false, `Include debug flags into the build to support go debugging with "delve". If not specified, debugging info is trimmed`)
Expand Down Expand Up @@ -96,6 +98,7 @@ func Execute(ctx context.Context, flags *builderInput) error {
PkgName: flags.name,
ModReplace: replace,
Plugins: plugins,
Tags: flags.tags,
BuildOutput: flags.out,
Debug: flags.debug,
}
Expand Down