Skip to content

Commit

Permalink
Add option to generate go code only (no compile) (#40)
Browse files Browse the repository at this point in the history
* 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 <juraci.github@kroehling.de>

* 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 <juraci.github@kroehling.de>
  • Loading branch information
Brian Gibbins and jpkrohling authored May 12, 2021
1 parent 4f061ca commit 5b5d3fb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion internal/builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
5 changes: 5 additions & 0 deletions internal/builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5b5d3fb

Please sign in to comment.