Compute `root prefix` as mamba install path (#3447)

* Compute root prefix as mamba install path

* Run test only on linux

* Test conflict between conda and mamba with same base env in CI

* Change strategy

* Use target_compile_definitions instead of add_definitions

* Add test logs

* Add ENABLE_MAMBA_ROOT_PREFIX_FALLBACK OPTION
This commit is contained in:
Hind-M 2024-09-20 14:36:17 +02:00 committed by GitHub
parent 1c755675bf
commit ad8ca3cf02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 38 additions and 2 deletions

View File

@ -40,7 +40,8 @@ jobs:
--preset mamba-unix-shared-${{ inputs.build_type }} \
-D CMAKE_CXX_COMPILER_LAUNCHER=sccache \
-D CMAKE_C_COMPILER_LAUNCHER=sccache \
-D BUILD_LIBMAMBAPY=OFF
-D BUILD_LIBMAMBAPY=OFF \
-D ENABLE_MAMBA_ROOT_PREFIX_FALLBACK=OFF
cmake --build build/ --parallel
- name: Show build cache statistics
run: sccache --show-stats

View File

@ -42,7 +42,8 @@ jobs:
-D CMAKE_MSVC_RUNTIME_LIBRARY="MultiThreadedDLL" ^
-D CMAKE_CXX_COMPILER_LAUNCHER=sccache ^
-D CMAKE_C_COMPILER_LAUNCHER=sccache ^
-D BUILD_LIBMAMBAPY=OFF
-D BUILD_LIBMAMBAPY=OFF ^
-D ENABLE_MAMBA_ROOT_PREFIX_FALLBACK=OFF
if %errorlevel% neq 0 exit /b %errorlevel%
cmake --build build/ --parallel
if %errorlevel% neq 0 exit /b %errorlevel%

View File

@ -659,9 +659,19 @@ endmacro()
set(libmamba_targets "")
option(
ENABLE_MAMBA_ROOT_PREFIX_FALLBACK
"Enable mamba (shared) root prefix to be set to install prefix"
ON
)
if(BUILD_SHARED)
message(STATUS "Adding shared libmamba target")
libmamba_create_target(libmamba-dyn SHARED libmamba)
if(ENABLE_MAMBA_ROOT_PREFIX_FALLBACK)
# Use mamba installation prefix to set root prefix (base)
target_compile_definitions(libmamba-dyn PUBLIC MAMBA_USE_INSTALL_PREFIX_AS_BASE)
endif()
endif()
if(BUILD_STATIC)

View File

@ -629,6 +629,21 @@ namespace mamba
}
}
auto
get_root_prefix_from_mamba_bin(const fs::u8path& mamba_bin_path) -> expected_t<fs::u8path>
{
if (mamba_bin_path.empty())
{
return make_unexpected(
"`mamba` binary not found.\nPlease set `MAMBA_ROOT_PREFIX`.",
mamba_error_code::incorrect_usage
);
}
// In linux and osx, the install path would be install_prefix/bin/mamba
// In windows, install_prefix/Scripts/mamba.exe
return { fs::weakly_canonical(mamba_bin_path.parent_path().parent_path()) };
}
auto validate_existing_root_prefix(const fs::u8path& candidate) -> expected_t<fs::u8path>
{
auto prefix = fs::u8path(util::expand_home(candidate.string()));
@ -724,11 +739,20 @@ namespace mamba
}
else
{
#ifdef MAMBA_USE_INSTALL_PREFIX_AS_BASE
// mamba case
// set the root prefix as the mamba installation path
get_root_prefix_from_mamba_bin(util::which("mamba"))
.transform([&](fs::u8path&& p) { prefix = std::move(p); })
.or_else([](mamba_error&& error) { throw std::move(error); });
#else
// micromamba case
validate_existing_root_prefix(default_root_prefix_v1())
.or_else([](const auto& /* error */)
{ return validate_root_prefix(default_root_prefix_v2()); })
.transform([&](fs::u8path&& p) { prefix = std::move(p); })
.or_else([](mamba_error&& error) { throw std::move(error); });
#endif
}
if (env_name.configured())