From 612cb368ab1ac0f907dc4b4ed1d7531532643a82 Mon Sep 17 00:00:00 2001 From: Abhijit Gadgil Date: Tue, 30 Jul 2024 10:20:02 +0000 Subject: [PATCH] Fixed issues while compiling on Linux Signed-off-by: Abhijit Gadgil --- components/hab/src/cli_v4.rs | 10 +++++----- components/hab/src/cli_v4/pkg.rs | 6 +++--- components/hab/src/cli_v4/pkg/build.rs | 10 ++++++---- components/hab/src/main_v4.rs | 7 ++++--- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/components/hab/src/cli_v4.rs b/components/hab/src/cli_v4.rs index f44ea221b6..bb593955e0 100644 --- a/components/hab/src/cli_v4.rs +++ b/components/hab/src/cli_v4.rs @@ -2,7 +2,7 @@ use clap_v4 as clap; use clap::Parser; -use habitat_common::ui::UI; +use habitat_common::{FeatureFlag, ui::UI}; use crate::{cli::AFTER_HELP, error::Result as HabResult, @@ -73,9 +73,9 @@ enum Hab { } impl Hab { - async fn do_cli_command(&self, ui: &mut UI) -> HabResult<()> { + async fn do_cli_command(&self, ui: &mut UI, feature_flags: FeatureFlag) -> HabResult<()> { match self { - Self::Pkg(pkg_command) => pkg_command.do_command(ui).await, + Self::Pkg(pkg_command) => pkg_command.do_command(ui, feature_flags).await, _ => todo!(), } } @@ -132,7 +132,7 @@ pub(crate) struct SvcStartCommand; #[derive(Clone, Debug, Parser)] pub(crate) struct SvcStopCommand; -pub async fn cli_driver(ui: &mut UI) -> HabResult<()> { +pub async fn cli_driver(ui: &mut UI, feature_flags: FeatureFlag) -> HabResult<()> { let cli = Hab::parse(); - cli.do_cli_command(ui).await + cli.do_cli_command(ui, feature_flags).await } diff --git a/components/hab/src/cli_v4/pkg.rs b/components/hab/src/cli_v4/pkg.rs index 84027c3176..1a17336a47 100644 --- a/components/hab/src/cli_v4/pkg.rs +++ b/components/hab/src/cli_v4/pkg.rs @@ -3,7 +3,7 @@ use clap_v4 as clap; use clap::{Parser, Subcommand}; -use habitat_common::ui::UI; +use habitat_common::{FeatureFlag, ui::UI}; use crate::error::Result as HabResult; @@ -108,12 +108,12 @@ pub(super) enum PkgCommand { } impl PkgCommand { - pub(crate) async fn do_command(&self, ui: &mut UI) -> HabResult<()> { + pub(crate) async fn do_command(&self, ui: &mut UI, feature_flags: FeatureFlag) -> HabResult<()> { match self { Self::Binds(opts) => opts.do_binds(), Self::Binlink(opts) => opts.do_binlink(ui), Self::Path(opts) => opts.do_path(), - Self::Build(opts) => opts.do_build(ui).await, + Self::Build(opts) => opts.do_build(ui, feature_flags).await, Self::Config(opts) => opts.do_config(), Self::Env(opts) => opts.do_env(), Self::Hash(opts) => opts.do_hash(), diff --git a/components/hab/src/cli_v4/pkg/build.rs b/components/hab/src/cli_v4/pkg/build.rs index d98b0c9b12..be8b06c674 100644 --- a/components/hab/src/cli_v4/pkg/build.rs +++ b/components/hab/src/cli_v4/pkg/build.rs @@ -16,7 +16,7 @@ use habitat_core::{crypto, origin::Origin}; use crate::{command::pkg::build, - error::Result as HabResult}; + error::Result as HabResult, error::Error as HabError}; use crate::cli_v4::utils::CacheKeyPath; @@ -68,7 +68,9 @@ pub(crate) struct PkgBuildOptions { } impl PkgBuildOptions { - pub(super) async fn do_build(&self, ui: &mut UI) -> HabResult<()> { + // Required because of lot of `cfg`... + #[allow(unused_variables)] + pub(super) async fn do_build(&self, ui: &mut UI, feature_flags: FeatureFlag) -> HabResult<()> { if !self.hab_origin_keys.is_empty() { crypto::init()?; let key_cache = KeyCache::new::((&self.cache_key_path).into()); @@ -81,10 +83,10 @@ impl PkgBuildOptions { let native_package = false; - #[cfg(target_os = "linux")] + #[cfg(target_family = "unix")] let native_package = if self.native_package { if !feature_flags.contains(FeatureFlag::NATIVE_PACKAGE_SUPPORT) { - return Err(Error::ArgumentError(String::from("`--native-package` is \ + return Err(HabError::ArgumentError(String::from("`--native-package` is \ only available when \ `HAB_FEAT_NATIVE_PACKAGE_SUPPORT` \ is set"))); diff --git a/components/hab/src/main_v4.rs b/components/hab/src/main_v4.rs index 49c461480c..91b42c3470 100644 --- a/components/hab/src/main_v4.rs +++ b/components/hab/src/main_v4.rs @@ -1,6 +1,6 @@ #[cfg(feature = "v4")] -use habitat_common::ui::{UIWriter, - UI}; +use habitat_common::{FeatureFlag, ui::{UIWriter, + UI}}; #[cfg(feature = "v4")] use hab::cli_driver; @@ -8,7 +8,8 @@ use hab::cli_driver; #[cfg(feature = "v4")] pub(crate) async fn main_v4() { let mut ui = UI::default_with_env(); - if let Err(e) = cli_driver(&mut ui).await { + let features = FeatureFlag::from_env(&mut ui); + if let Err(e) = cli_driver(&mut ui, features).await { let exit_code = e.exit_code(); ui.fatal(e).unwrap(); std::process::exit(exit_code)