Skip to content

Commit

Permalink
pkg/{distro,platform}: move BootMode to platform
Browse files Browse the repository at this point in the history
Move the BootMode enum from pkg/distro to pkg/platform.  We want to
import BootMode to the disk package, which would create an import loop
with distro.
  • Loading branch information
achilleas-k authored and ondrejbudai committed Nov 1, 2024
1 parent 8e6780b commit 6ce0227
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 34 deletions.
24 changes: 2 additions & 22 deletions pkg/distro/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,16 @@ import (
"github.com/osbuild/images/pkg/disk"
"github.com/osbuild/images/pkg/manifest"
"github.com/osbuild/images/pkg/ostree"
"github.com/osbuild/images/pkg/platform"
"github.com/osbuild/images/pkg/rhsm/facts"
"github.com/osbuild/images/pkg/rpmmd"
)

type BootMode uint64

const (
BOOT_NONE BootMode = iota
BOOT_LEGACY
BOOT_UEFI
BOOT_HYBRID
UnsupportedCustomizationError = "unsupported blueprint customizations found for image type %q: (allowed: %s)"
NoCustomizationsAllowedError = "image type %q does not support customizations"
)

func (m BootMode) String() string {
switch m {
case BOOT_NONE:
return "none"
case BOOT_LEGACY:
return "legacy"
case BOOT_UEFI:
return "uefi"
case BOOT_HYBRID:
return "hybrid"
default:
panic("invalid boot mode")
}
}

// A Distro represents composer's notion of what a given distribution is.
type Distro interface {
// Returns the name of the distro.
Expand Down Expand Up @@ -121,7 +101,7 @@ type ImageType interface {
PartitionType() string

// Returns the corresponding boot mode ("legacy", "uefi", "hybrid") or "none"
BootMode() BootMode
BootMode() platform.BootMode

// Returns the names of the pipelines that set up the build environment (buildroot).
BuildPipelines() []string
Expand Down
10 changes: 5 additions & 5 deletions pkg/distro/fedora/imagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ func (t *imageType) Exports() []string {
return []string{"assembler"}
}

func (t *imageType) BootMode() distro.BootMode {
func (t *imageType) BootMode() platform.BootMode {
if t.platform.GetUEFIVendor() != "" && t.platform.GetBIOSPlatform() != "" {
return distro.BOOT_HYBRID
return platform.BOOT_HYBRID
} else if t.platform.GetUEFIVendor() != "" {
return distro.BOOT_UEFI
return platform.BOOT_UEFI
} else if t.platform.GetBIOSPlatform() != "" || t.platform.GetZiplSupport() {
return distro.BOOT_LEGACY
return platform.BOOT_LEGACY
}
return distro.BOOT_NONE
return platform.BOOT_NONE
}

func (t *imageType) getPartitionTable(
Expand Down
10 changes: 5 additions & 5 deletions pkg/distro/rhel/imagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ func (t *ImageType) Exports() []string {
return []string{"assembler"}
}

func (t *ImageType) BootMode() distro.BootMode {
func (t *ImageType) BootMode() platform.BootMode {
if t.platform.GetUEFIVendor() != "" && t.platform.GetBIOSPlatform() != "" {
return distro.BOOT_HYBRID
return platform.BOOT_HYBRID
} else if t.platform.GetUEFIVendor() != "" {
return distro.BOOT_UEFI
return platform.BOOT_UEFI
} else if t.platform.GetBIOSPlatform() != "" || t.platform.GetZiplSupport() {
return distro.BOOT_LEGACY
return platform.BOOT_LEGACY
}
return distro.BOOT_NONE
return platform.BOOT_NONE
}

func (t *ImageType) GetPartitionTable(
Expand Down
5 changes: 3 additions & 2 deletions pkg/distro/test_distro/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/osbuild/images/pkg/distro"
"github.com/osbuild/images/pkg/manifest"
"github.com/osbuild/images/pkg/ostree"
"github.com/osbuild/images/pkg/platform"
"github.com/osbuild/images/pkg/policies"
"github.com/osbuild/images/pkg/rpmmd"
)
Expand Down Expand Up @@ -210,8 +211,8 @@ func (t *TestImageType) PartitionType() string {
return ""
}

func (t *TestImageType) BootMode() distro.BootMode {
return distro.BOOT_HYBRID
func (t *TestImageType) BootMode() platform.BootMode {
return platform.BOOT_HYBRID
}

func (t *TestImageType) BuildPipelines() []string {
Expand Down
25 changes: 25 additions & 0 deletions pkg/platform/bootmode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package platform

type BootMode uint64

const (
BOOT_NONE BootMode = iota
BOOT_LEGACY
BOOT_UEFI
BOOT_HYBRID
)

func (m BootMode) String() string {
switch m {
case BOOT_NONE:
return "none"
case BOOT_LEGACY:
return "legacy"
case BOOT_UEFI:
return "uefi"
case BOOT_HYBRID:
return "hybrid"
default:
panic("invalid boot mode")
}
}

0 comments on commit 6ce0227

Please sign in to comment.