Skip to content

Commit 428ba0c

Browse files
authored
allow to specify build tags (#54)
1 parent 220b183 commit 428ba0c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

plugins/builder/builder.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type BuildOptions struct {
6060
Plugins []UsePluginInfo
6161
BuildOutput string
6262
Debug bool
63+
Tags []string
6364
}
6465

6566
var validPkgNameRegex = regexp.MustCompile(`^[a-zA-Z0-9]+$`)
@@ -212,6 +213,11 @@ func (b *Builder) goBuild(ctx context.Context) error {
212213
args = append(args, "-trimpath")
213214
}
214215
args = append(args, "-ldflags", strings.Join(ldflags, " "))
216+
217+
if len(b.Tags) > 0 {
218+
args = append(args, "-tags", strings.Join(b.Tags, " "))
219+
}
220+
215221
// Run build.
216222
cmd := b.env.NewCommand(ctx, b.env.Go(), args...)
217223
err = b.env.RunCmd(ctx, cmd)
@@ -248,6 +254,11 @@ func (b *Builder) preBuild(ctx context.Context) error {
248254
}
249255

250256
for pluginName, v := range pluginVersionMap {
257+
if _, ok := b.BuildOptions.ModReplace[pluginName]; ok {
258+
log.Debug("skipping prebuild script for replaced plugin %s", pluginName)
259+
continue
260+
}
261+
251262
packagePath, _ := getModulePath(pluginName, v)
252263
if _, err = os.Stat(packagePath); os.IsNotExist(err) {
253264
log.Debug("you don't have this module/version installed (%s)", packagePath)

plugins/builder/plugin.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type builderInput struct {
2929
out string
3030
timeout string
3131
version string
32+
tags []string
3233
plugins []string
3334
replace []string
3435
debug bool
@@ -53,6 +54,7 @@ func (p *Plugin) CobraAddCommands(rootCmd *cobra.Command) error {
5354
buildCmd.Flags().StringVarP(&flags.out, "output", "o", "", `Build output file, by default application name is used`)
5455
buildCmd.Flags().StringVar(&flags.version, "build-version", "", `Arbitrary version of application`)
5556
buildCmd.Flags().StringVarP(&flags.timeout, "timeout", "t", "120s", `Build timeout duration, example: 0, 100ms, 1h23m`)
57+
buildCmd.Flags().StringSliceVarP(&flags.tags, "tag", "", nil, `Add build tags`)
5658
buildCmd.Flags().StringSliceVarP(&flags.plugins, "plugin", "p", nil, `Include PLUGIN into the build with an optional version`)
5759
buildCmd.Flags().StringSliceVarP(&flags.replace, "replace", "r", nil, `Replace go dependency, see "go mod edit -replace"`)
5860
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`)
@@ -96,6 +98,7 @@ func Execute(ctx context.Context, flags *builderInput) error {
9698
PkgName: flags.name,
9799
ModReplace: replace,
98100
Plugins: plugins,
101+
Tags: flags.tags,
99102
BuildOutput: flags.out,
100103
Debug: flags.debug,
101104
}

0 commit comments

Comments
 (0)