From 5b5d3fbbf6da92c41ebe53fcc4db91f25206c583 Mon Sep 17 00:00:00 2001 From: Brian Gibbins Date: Wed, 12 May 2021 14:07:22 +0100 Subject: [PATCH] Add option to generate go code only (no compile) (#40) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Issue#24 Add option to generate go code only (no compile) * Update cmd/root.go logging Suggested by @jpkkrohling Co-authored-by: Juraci Paixão Kröhling * remove verbose help .. created by corba * suggestion by jpkrohling to keep generateandcompile * lint error: remove unused var * reword cmd option and add back help message for default Co-authored-by: Juraci Paixão Kröhling --- cmd/root.go | 1 + internal/builder/config.go | 3 ++- internal/builder/main.go | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index 5a6b3bc60f1..0eb823b23a3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -68,6 +68,7 @@ func Execute() error { cmd.Flags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.otelcol-builder.yaml)") // the distribution parameters, which we accept as CLI flags as well + cmd.Flags().BoolVar(&cfg.SkipCompilation, "skip-compilation", false, "Whether builder should only generate go code with no compile of the collector (default false)") cmd.Flags().StringVar(&cfg.Distribution.ExeName, "name", "otelcol-custom", "The executable name for the OpenTelemetry Collector distribution") cmd.Flags().StringVar(&cfg.Distribution.LongName, "description", "Custom OpenTelemetry Collector distribution", "A descriptive name for the OpenTelemetry Collector distribution") cmd.Flags().StringVar(&cfg.Distribution.Version, "version", "1.0.0", "The version for the OpenTelemetry Collector distribution") diff --git a/internal/builder/config.go b/internal/builder/config.go index 0fecfccd1b3..8b9bc865797 100644 --- a/internal/builder/config.go +++ b/internal/builder/config.go @@ -33,7 +33,8 @@ var ErrInvalidGoMod = errors.New("invalid gomod specification for module") // Config holds the builder's configuration type Config struct { - Logger logr.Logger + Logger logr.Logger + SkipCompilation bool Distribution Distribution `mapstructure:"dist"` Exporters []Module `mapstructure:"exporters"` diff --git a/internal/builder/main.go b/internal/builder/main.go index 1b514023179..12228414a54 100644 --- a/internal/builder/main.go +++ b/internal/builder/main.go @@ -93,6 +93,11 @@ func Generate(cfg Config) error { // Compile generates a binary from the sources based on the configuration func Compile(cfg Config) error { + if cfg.SkipCompilation { + cfg.Logger.Info("Generating source codes only, the distribution will not be compiled.") + return nil + } + // first, we test to check if we have Go at all goBinary, err := getGoPath(cfg) if err != nil {