diff --git a/plugins/builder/builder.go b/plugins/builder/builder.go index ddd070f..8bf1ae1 100644 --- a/plugins/builder/builder.go +++ b/plugins/builder/builder.go @@ -60,6 +60,7 @@ type BuildOptions struct { Plugins []UsePluginInfo BuildOutput string Debug bool + Tags []string } var validPkgNameRegex = regexp.MustCompile(`^[a-zA-Z0-9]+$`) @@ -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) @@ -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) diff --git a/plugins/builder/plugin.go b/plugins/builder/plugin.go index ecc414f..f69f7bb 100644 --- a/plugins/builder/plugin.go +++ b/plugins/builder/plugin.go @@ -29,6 +29,7 @@ type builderInput struct { out string timeout string version string + tags []string plugins []string replace []string debug bool @@ -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`) @@ -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, }