Skip to content

Commit 9d53d40

Browse files
authored
Enable configuration of whether or not to generate history (#45)
This adds the flag `-h` (long form `--history`) which enables history generation. It is also possible to set a config item for this.
1 parent 51a0ee5 commit 9d53d40

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

builder/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
// Config defines the global defaults for solbuild.
2929
type Config struct {
3030
DefaultProfile string `toml:"default_profile"` // Name of the default profile to use
31+
EnableHistory bool `toml:"enable_history"` // Whether to enable history generation or not
3132
EnableTmpfs bool `toml:"enable_tmpfs"` // Whether to enable tmpfs builds or
3233
OverlayRootDir string `toml:"overlay_root_dir"` // Custom Overlay Root Dir
3334
TmpfsSize string `toml:"tmpfs_size"` // Bounding size on the tmpfs
@@ -50,6 +51,7 @@ func NewConfig() (*Config, error) {
5051
// Set up some sane defaults just in case someone mangles the configs
5152
config := &Config{
5253
DefaultProfile: "main-x86_64",
54+
EnableHistory: false,
5355
EnableTmpfs: false,
5456
OverlayRootDir: "/var/cache/solbuild",
5557
TmpfsSize: "",

builder/manager.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,25 @@ func (m *Manager) SetPackage(pkg *Package) error {
187187
return ErrProfileNotInstalled
188188
}
189189

190-
// Obtain package history for git builds
191-
if pkg.Type == PackageTypeYpkg {
192-
repo, err := git.PlainOpenWithOptions(filepath.Dir(pkg.Path),
193-
&git.PlainOpenOptions{DetectDotGit: true})
194-
if err != nil && !errors.Is(err, git.ErrRepositoryNotExists) {
195-
return fmt.Errorf("cannot open Git repository: %w", err)
196-
}
190+
if m.Config.EnableHistory {
191+
slog.Info("History generation enabled")
192+
193+
// Obtain package history for git builds
194+
if pkg.Type == PackageTypeYpkg {
195+
repo, err := git.PlainOpenWithOptions(filepath.Dir(pkg.Path),
196+
&git.PlainOpenOptions{DetectDotGit: true})
197+
if err != nil && !errors.Is(err, git.ErrRepositoryNotExists) {
198+
return fmt.Errorf("cannot open Git repository: %w", err)
199+
}
197200

198-
if err == nil {
199-
if history, err := NewPackageHistory(repo, pkg.Path); err == nil {
200-
slog.Debug("Obtained package history")
201+
if err == nil {
202+
if history, err := NewPackageHistory(repo, pkg.Path); err == nil {
203+
slog.Debug("Obtained package history")
201204

202-
m.history = history
203-
} else {
204-
slog.Warn("Failed to obtain package git history", "err", err)
205+
m.history = history
206+
} else {
207+
slog.Warn("Failed to obtain package git history", "err", err)
208+
}
205209
}
206210
}
207211
}

cli/build.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type BuildFlags struct {
5151
Memory string `short:"m" long:"memory" desc:"Set the tmpfs size to use, e.g. 8G"`
5252
TransitManifest string ` long:"transit-manifest" desc:"Create transit manifest for the given target"`
5353
ABIReport bool `short:"r" long:"disable-abi-report" desc:"Don't generate an ABI report of the completed build"`
54+
History bool `short:"h" long:"history" desc:"Enable history generation for this build"`
5455
}
5556

5657
// BuildArgs are arguments for the "build" sub-command.
@@ -105,6 +106,11 @@ func BuildRun(r *cmd.Root, s *cmd.Sub) {
105106
os.Exit(1)
106107
}
107108

109+
// Enable history generation
110+
if sFlags.History {
111+
manager.Config.EnableHistory = true
112+
}
113+
108114
pkg, err := builder.NewPackage(pkgPath)
109115
if err != nil {
110116
log.Panic("Failed to load package", "err", err)

data/00_solbuild.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
# "-p" profile argument to solbuild
1111
default_profile = "main-x86_64"
1212

13+
# Setting this to true will enable package history generation
14+
# Note you can still override this at runtime with the -h flag
15+
enable_history = false
16+
1317
# Setting this to true will default the builder to using tmpfs
1418
# Note you can still override this at runtime with the -t flag
1519
enable_tmpfs = false

0 commit comments

Comments
 (0)