Skip to content

Commit 5b5d3fb

Browse files
Brian Gibbinsjpkrohling
Brian Gibbins
andauthored
Add option to generate go code only (no compile) (#40)
* 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 <[email protected]> * 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 <[email protected]>
1 parent 4f061ca commit 5b5d3fb

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

cmd/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func Execute() error {
6868
cmd.Flags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.otelcol-builder.yaml)")
6969

7070
// the distribution parameters, which we accept as CLI flags as well
71+
cmd.Flags().BoolVar(&cfg.SkipCompilation, "skip-compilation", false, "Whether builder should only generate go code with no compile of the collector (default false)")
7172
cmd.Flags().StringVar(&cfg.Distribution.ExeName, "name", "otelcol-custom", "The executable name for the OpenTelemetry Collector distribution")
7273
cmd.Flags().StringVar(&cfg.Distribution.LongName, "description", "Custom OpenTelemetry Collector distribution", "A descriptive name for the OpenTelemetry Collector distribution")
7374
cmd.Flags().StringVar(&cfg.Distribution.Version, "version", "1.0.0", "The version for the OpenTelemetry Collector distribution")

internal/builder/config.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ var ErrInvalidGoMod = errors.New("invalid gomod specification for module")
3333

3434
// Config holds the builder's configuration
3535
type Config struct {
36-
Logger logr.Logger
36+
Logger logr.Logger
37+
SkipCompilation bool
3738

3839
Distribution Distribution `mapstructure:"dist"`
3940
Exporters []Module `mapstructure:"exporters"`

internal/builder/main.go

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ func Generate(cfg Config) error {
9393

9494
// Compile generates a binary from the sources based on the configuration
9595
func Compile(cfg Config) error {
96+
if cfg.SkipCompilation {
97+
cfg.Logger.Info("Generating source codes only, the distribution will not be compiled.")
98+
return nil
99+
}
100+
96101
// first, we test to check if we have Go at all
97102
goBinary, err := getGoPath(cfg)
98103
if err != nil {

0 commit comments

Comments
 (0)