Skip to content

Commit

Permalink
Enable configuration of whether or not to generate history
Browse files Browse the repository at this point in the history
  • Loading branch information
ReillyBrogan committed Oct 23, 2023
1 parent 7b95acf commit d9aca92
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
2 changes: 2 additions & 0 deletions builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
// Config defines the global defaults for solbuild.
type Config struct {
DefaultProfile string `toml:"default_profile"` // Name of the default profile to use
EnableHistory bool `toml:"enable_history"` // Whether to enable history generation or not
EnableTmpfs bool `toml:"enable_tmpfs"` // Whether to enable tmpfs builds or
OverlayRootDir string `toml:"overlay_root_dir"` // Custom Overlay Root Dir
TmpfsSize string `toml:"tmpfs_size"` // Bounding size on the tmpfs
Expand All @@ -50,6 +51,7 @@ func NewConfig() (*Config, error) {
// Set up some sane defaults just in case someone mangles the configs
config := &Config{
DefaultProfile: "main-x86_64",
EnableHistory: false,
EnableTmpfs: false,
OverlayRootDir: "/var/cache/solbuild",
TmpfsSize: "",
Expand Down
30 changes: 17 additions & 13 deletions builder/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,25 @@ func (m *Manager) SetPackage(pkg *Package) error {
return ErrProfileNotInstalled
}

// Obtain package history for git builds
if pkg.Type == PackageTypeYpkg {
repo, err := git.PlainOpenWithOptions(filepath.Dir(pkg.Path),
&git.PlainOpenOptions{DetectDotGit: true})
if err != nil && !errors.Is(err, git.ErrRepositoryNotExists) {
return fmt.Errorf("cannot open Git repository: %w", err)
}
if m.Config.EnableHistory {
log.Infoln("History generation enabled")

Check failure on line 189 in builder/manager.go

View workflow job for this annotation

GitHub Actions / lint

undefined: log.Infoln (typecheck)

Check failure on line 189 in builder/manager.go

View workflow job for this annotation

GitHub Actions / lint

undefined: log.Infoln) (typecheck)

Check failure on line 189 in builder/manager.go

View workflow job for this annotation

GitHub Actions / lint

undefined: log.Infoln) (typecheck)

Check failure on line 189 in builder/manager.go

View workflow job for this annotation

GitHub Actions / lint

undefined: log.Infoln) (typecheck)

// Obtain package history for git builds
if pkg.Type == PackageTypeYpkg {
repo, err := git.PlainOpenWithOptions(filepath.Dir(pkg.Path),
&git.PlainOpenOptions{DetectDotGit: true})
if err != nil && !errors.Is(err, git.ErrRepositoryNotExists) {
return fmt.Errorf("cannot open Git repository: %w", err)
}

if err == nil {
if history, err := NewPackageHistory(repo, pkg.Path); err == nil {
slog.Debug("Obtained package history")
if err == nil {
if history, err := NewPackageHistory(repo, pkg.Path); err == nil {
slog.Debug("Obtained package history")

m.history = history
} else {
slog.Warn("Failed to obtain package git history", "err", err)
m.history = history
} else {
slog.Warn("Failed to obtain package git history", "err", err)
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions cli/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type BuildFlags struct {
Memory string `short:"m" long:"memory" desc:"Set the tmpfs size to use, e.g. 8G"`
TransitManifest string ` long:"transit-manifest" desc:"Create transit manifest for the given target"`
ABIReport bool `short:"r" long:"disable-abi-report" desc:"Don't generate an ABI report of the completed build"`
History bool `short:"h" long:"history" desc:"Enable history generation for this build"`
}

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

// Enable history generation
if sFlags.History {
manager.Config.EnableHistory = true
}

pkg, err := builder.NewPackage(pkgPath)
if err != nil {
log.Panic("Failed to load package", "err", err)
Expand Down
4 changes: 4 additions & 0 deletions data/00_solbuild.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
# "-p" profile argument to solbuild
default_profile = "main-x86_64"

# Setting this to true will enable package history generation
# Note you can still override this at runtime with the -h flag
enable_history = false

# Setting this to true will default the builder to using tmpfs
# Note you can still override this at runtime with the -t flag
enable_tmpfs = false
Expand Down

0 comments on commit d9aca92

Please sign in to comment.