1- #[ cfg( any( target_arch = "x86_64" , target_arch = "powerpc64" ) ) ]
1+ #[ cfg( all(
2+ any( target_arch = "x86_64" , target_arch = "powerpc64" ) ,
3+ feature = "grub"
4+ ) ) ]
25use crate :: bios;
36use crate :: component;
4- use crate :: component:: { Component , ValidationResult } ;
7+ use crate :: component:: Component ;
8+ #[ cfg( feature = "grub" ) ]
9+ use crate :: component:: ValidationResult ;
510use crate :: coreos;
611#[ cfg( any(
712 target_arch = "x86_64" ,
813 target_arch = "aarch64" ,
914 target_arch = "riscv64"
1015) ) ]
1116use crate :: efi;
17+
18+ #[ cfg( feature = "grub" ) ]
1219use crate :: freezethaw:: fsfreeze_thaw_cycle;
1320use crate :: model:: { ComponentStatus , ComponentUpdatable , ContentMetadata , SavedState , Status } ;
14- use crate :: { ostreeutil, util} ;
21+ #[ cfg( feature = "grub" ) ]
22+ use crate :: ostreeutil;
23+ use crate :: util;
1524use anyhow:: { anyhow, bail, Context , Result } ;
1625use camino:: { Utf8Path , Utf8PathBuf } ;
26+ #[ cfg( feature = "grub" ) ]
1727use clap:: crate_version;
28+ #[ cfg( feature = "grub" ) ]
1829use fn_error_context:: context;
30+ #[ cfg( feature = "grub" ) ]
1931use libc:: mode_t;
32+ #[ cfg( feature = "grub" ) ]
2033use libc:: { S_IRGRP , S_IROTH , S_IRUSR , S_IWUSR } ;
2134use serde:: { Deserialize , Serialize } ;
2235use std:: borrow:: Cow ;
2336use std:: collections:: BTreeMap ;
37+
38+ #[ cfg( feature = "grub" ) ]
2439use std:: fs:: { self , File } ;
25- use std:: io:: { BufRead , BufReader , BufWriter , Write } ;
26- use std:: path:: { Path , PathBuf } ;
40+ #[ cfg( feature = "grub" ) ]
41+ use std:: io:: { BufRead , BufWriter , Write } ;
42+
43+ #[ cfg( feature = "grub" ) ]
44+ use std:: io:: BufReader ;
45+ use std:: path:: Path ;
46+ #[ cfg( feature = "grub" ) ]
47+ use std:: path:: PathBuf ;
2748
2849#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
2950pub ( crate ) enum ConfigMode {
3051 None ,
3152 Static ,
3253 WithUUID ,
33- SystemdBoot ,
3454}
3555
56+ #[ cfg( feature = "grub" ) ]
3657impl ConfigMode {
3758 pub ( crate ) fn enabled_with_uuid ( & self ) -> Option < bool > {
3859 match self {
3960 ConfigMode :: None => None ,
4061 ConfigMode :: Static => Some ( false ) ,
4162 ConfigMode :: WithUUID => Some ( true ) ,
42- ConfigMode :: SystemdBoot => Some ( false ) ,
4363 }
4464 }
4565}
@@ -48,7 +68,8 @@ pub(crate) fn install(
4868 source_root : & str ,
4969 dest_root : & str ,
5070 device : Option < & str > ,
51- configs : ConfigMode ,
71+ #[ cfg( feature = "grub" ) ] configs : ConfigMode ,
72+ #[ cfg( not( feature = "grub" ) ) ] _configs : ConfigMode ,
5273 update_firmware : bool ,
5374 target_components : Option < & [ String ] > ,
5475 auto_components : bool ,
@@ -85,6 +106,7 @@ pub(crate) fn install(
85106 }
86107
87108 let mut state = SavedState :: default ( ) ;
109+ #[ cfg( feature = "grub" ) ]
88110 let mut installed_efi_vendor = None ;
89111 for & component in target_components. iter ( ) {
90112 // skip for BIOS if device is empty
@@ -101,18 +123,18 @@ pub(crate) fn install(
101123 . with_context ( || format ! ( "installing component {}" , component. name( ) ) ) ?;
102124 log:: info!( "Installed {} {}" , component. name( ) , meta. meta. version) ;
103125 state. installed . insert ( component. name ( ) . into ( ) , meta) ;
104- // If not systemd-boot, try to get the efi vendor
105- if configs != ConfigMode :: SystemdBoot {
106- // Yes this is a hack...the Component thing just turns out to be too generic.
107- if let Some ( vendor) = component. get_efi_vendor ( & source_root) ? {
108- assert ! ( installed_efi_vendor. is_none( ) ) ;
109- installed_efi_vendor = Some ( vendor) ;
110- }
126+
127+ // Yes this is a hack...the Component thing just turns out to be too generic.
128+ #[ cfg( feature = "grub" ) ]
129+ if let Some ( vendor) = component. get_efi_vendor ( & source_root) ? {
130+ assert ! ( installed_efi_vendor. is_none( ) ) ;
131+ installed_efi_vendor = Some ( vendor) ;
111132 }
112133 }
113134
114135 let sysroot = & openat:: Dir :: open ( dest_root) ?;
115136
137+ #[ cfg( feature = "grub" ) ]
116138 match configs. enabled_with_uuid ( ) {
117139 Some ( uuid) => {
118140 let meta = get_static_config_meta ( ) ?;
@@ -129,7 +151,8 @@ pub(crate) fn install(
129151 None => { }
130152 }
131153
132- if configs == ConfigMode :: SystemdBoot {
154+ #[ cfg( feature = "systemd-boot" ) ]
155+ {
133156 let efi = crate :: efi:: Efi :: default ( ) ;
134157 log:: warn!( "Installing systemd-boot entries" ) ;
135158 if let Ok ( Some ( mnt) ) = efi. get_mounted_esp ( Path :: new ( dest_root) ) {
@@ -153,6 +176,7 @@ pub(crate) fn install(
153176}
154177
155178#[ context( "Get static config metadata" ) ]
179+ #[ cfg( feature = "grub" ) ]
156180fn get_static_config_meta ( ) -> Result < ContentMetadata > {
157181 let self_bin_meta = std:: fs:: metadata ( "/proc/self/exe" ) . context ( "Querying self meta" ) ?;
158182 let self_meta = ContentMetadata {
@@ -185,9 +209,11 @@ pub(crate) fn get_components_impl(auto: bool) -> Components {
185209 if is_efi_booted {
186210 insert_component ( & mut components, Box :: new ( efi:: Efi :: default ( ) ) ) ;
187211 } else {
212+ #[ cfg( feature = "grub" ) ]
188213 insert_component ( & mut components, Box :: new ( bios:: Bios :: default ( ) ) ) ;
189214 }
190215 } else {
216+ #[ cfg( feature = "grub" ) ]
191217 insert_component ( & mut components, Box :: new ( bios:: Bios :: default ( ) ) ) ;
192218 insert_component ( & mut components, Box :: new ( efi:: Efi :: default ( ) ) ) ;
193219 }
@@ -281,6 +307,7 @@ pub(crate) fn update(name: &str, rootcxt: &RootContext) -> Result<ComponentUpdat
281307}
282308
283309/// daemon implementation of component adoption
310+ #[ cfg( feature = "grub" ) ]
284311pub ( crate ) fn adopt_and_update (
285312 name : & str ,
286313 rootcxt : & RootContext ,
@@ -327,6 +354,7 @@ pub(crate) fn adopt_and_update(
327354}
328355
329356/// daemon implementation of component validate
357+ #[ cfg( feature = "grub" ) ]
330358pub ( crate ) fn validate ( name : & str ) -> Result < ValidationResult > {
331359 let state = SavedState :: load_from_disk ( "/" ) ?. unwrap_or_default ( ) ;
332360 let component = component:: new_from_name ( name) ?;
@@ -532,6 +560,8 @@ pub(crate) fn client_run_update() -> Result<()> {
532560 }
533561 updated = true ;
534562 }
563+
564+ #[ cfg( feature = "grub" ) ]
535565 for ( name, adoptable) in status. adoptable . iter ( ) {
536566 if adoptable. confident {
537567 if let Some ( r) = adopt_and_update ( name, & rootcxt, false ) ? {
@@ -548,6 +578,7 @@ pub(crate) fn client_run_update() -> Result<()> {
548578 Ok ( ( ) )
549579}
550580
581+ #[ cfg( feature = "grub" ) ]
551582pub ( crate ) fn client_run_adopt_and_update ( with_static_config : bool ) -> Result < ( ) > {
552583 let rootcxt = prep_before_update ( ) ?;
553584 let status: Status = status ( ) ?;
@@ -563,6 +594,7 @@ pub(crate) fn client_run_adopt_and_update(with_static_config: bool) -> Result<()
563594 Ok ( ( ) )
564595}
565596
597+ #[ cfg( feature = "grub" ) ]
566598pub ( crate ) fn client_run_validate ( ) -> Result < ( ) > {
567599 let status: Status = status ( ) ?;
568600 if status. components . is_empty ( ) {
@@ -593,6 +625,7 @@ pub(crate) fn client_run_validate() -> Result<()> {
593625}
594626
595627#[ context( "Migrating to a static GRUB config" ) ]
628+ #[ cfg( feature = "grub" ) ]
596629pub ( crate ) fn client_run_migrate_static_grub_config ( ) -> Result < ( ) > {
597630 // Did we already complete the migration?
598631 // We need to migrate if bootloader is not none (or not set)
@@ -679,6 +712,7 @@ pub(crate) fn client_run_migrate_static_grub_config() -> Result<()> {
679712
680713/// Writes a stripped GRUB config to `stripped_config_name`, removing lines between
681714/// `### BEGIN /etc/grub.d/15_ostree ###` and `### END /etc/grub.d/15_ostree ###`.
715+ #[ cfg( feature = "grub" ) ]
682716fn strip_grub_config_file (
683717 current_config_content : impl BufRead ,
684718 dirfd : & openat:: Dir ,
@@ -739,6 +773,7 @@ mod tests {
739773 }
740774
741775 #[ test]
776+ #[ cfg( feature = "grub" ) ]
742777 fn test_strip_grub_config_file ( ) -> Result < ( ) > {
743778 let root: & tempfile:: TempDir = & tempfile:: tempdir ( ) ?;
744779 let root_path = root. path ( ) ;
0 commit comments