feat: update user configuration example and add development package support
- Enhanced the user.depot.toml.example file with additional comments and options for user-local preferences. - Bumped version from 0.35.0 to 0.35.1 in meson.build. - Introduced a new option for DEPOT_DEVELOPMENT_PACKAGE in meson_options.txt. - Added functions to handle the requested development package in build_options.rs. - Updated various builder files (autotools.rs, cmake.rs, custom.rs, meson.rs, perl.rs) to support passing build flags. - Implemented checks for the required development package during source builds in commands.rs and commands/build_cmd.rs. - Added tests to ensure the correct behavior of development package requirements and source build warnings. - Modified manual source handling in source/mod.rs to validate local manual sources before proceeding with builds. - Updated cargo build and test scripts to accept a new development package argument. - Added VSCode settings to disable automatic configuration on open.
This commit is contained in:
@@ -134,7 +134,9 @@ pub fn build(
|
||||
let expanded = expand_configure_arg(spec, arg, &env_vars);
|
||||
configure_cmd.arg(expanded);
|
||||
}
|
||||
for arg in crate::builder::static_build_args_for(crate::package::BuildType::Autotools)? {
|
||||
for arg in
|
||||
crate::builder::static_build_args_for(crate::package::BuildType::Autotools, flags)?
|
||||
{
|
||||
add_auto_configure_arg_if_supported(&mut configure_cmd, help_text.as_deref(), &arg);
|
||||
}
|
||||
|
||||
@@ -444,7 +446,9 @@ pub(crate) fn ensure_host_build(
|
||||
let expanded = expand_configure_arg(&host_spec, arg, &env_vars);
|
||||
configure_cmd.arg(expanded);
|
||||
}
|
||||
for arg in crate::builder::static_build_args_for(crate::package::BuildType::Autotools)? {
|
||||
for arg in
|
||||
crate::builder::static_build_args_for(crate::package::BuildType::Autotools, flags)?
|
||||
{
|
||||
add_auto_configure_arg_if_supported(&mut configure_cmd, help_text.as_deref(), &arg);
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ pub fn build(
|
||||
let expanded = expand_with_envs(flag, &env_vars);
|
||||
cmake_cmd.arg(&expanded);
|
||||
}
|
||||
for arg in crate::builder::static_build_args_for(crate::package::BuildType::CMake)? {
|
||||
for arg in crate::builder::static_build_args_for(crate::package::BuildType::CMake, flags)? {
|
||||
cmake_cmd.arg(arg);
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ pub(crate) fn ensure_host_build(
|
||||
let expanded = expand_with_envs(flag, &env_vars);
|
||||
cmake_cmd.arg(&expanded);
|
||||
}
|
||||
for arg in crate::builder::static_build_args_for(crate::package::BuildType::CMake)? {
|
||||
for arg in crate::builder::static_build_args_for(crate::package::BuildType::CMake, flags)? {
|
||||
cmake_cmd.arg(arg);
|
||||
}
|
||||
|
||||
|
||||
+187
-32
@@ -8,6 +8,7 @@ use anyhow::{Context, Result};
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
pub fn build(
|
||||
spec: &PackageSpec,
|
||||
@@ -98,15 +99,6 @@ pub fn build(
|
||||
}
|
||||
|
||||
if !state.is_done(BuildStep::PostInstallDone) {
|
||||
crate::log_info!(
|
||||
"Running custom build script{}...",
|
||||
if fakeroot::is_root() {
|
||||
""
|
||||
} else {
|
||||
" (with fakeroot)"
|
||||
}
|
||||
);
|
||||
|
||||
crate::builder::set_env_var(
|
||||
&mut env_vars,
|
||||
"DESTDIR",
|
||||
@@ -139,13 +131,31 @@ pub fn build(
|
||||
std::env::current_dir()?.join(&build_script)
|
||||
};
|
||||
|
||||
// Use POSIX `sh` (more likely to be available in minimal/chroot environments)
|
||||
let mut cmd = if custom_function_mode_enabled(&abs_build_script)? {
|
||||
let function_mode = custom_function_mode_enabled(&abs_build_script)?;
|
||||
if function_mode {
|
||||
crate::log_info!(
|
||||
"Running custom build script (function mode; fakeroot only during install)..."
|
||||
);
|
||||
crate::log_info!(
|
||||
"Using custom build.sh function mode (per-output install functions enabled)"
|
||||
);
|
||||
build_function_mode_command(spec, &install_destdir, &abs_build_script)?
|
||||
run_function_mode_build_script(
|
||||
spec,
|
||||
&build_dir,
|
||||
&install_destdir,
|
||||
&abs_build_script,
|
||||
&env_vars,
|
||||
)?;
|
||||
} else {
|
||||
crate::log_info!(
|
||||
"Running custom build script{}...",
|
||||
if fakeroot::is_root() {
|
||||
""
|
||||
} else {
|
||||
" (with fakeroot)"
|
||||
}
|
||||
);
|
||||
// Use POSIX `sh` (doing something wrong if your system doesn't have it...)
|
||||
let mut cmd = fakeroot::wrap_install_command("sh", &install_destdir);
|
||||
let wrapper = crate::shell_helpers::wrap_shell_command(". \"$1\"");
|
||||
// Run custom scripts through `sh -c` so helper commands like `haul`
|
||||
@@ -155,23 +165,22 @@ pub fn build(
|
||||
.arg(wrapper)
|
||||
.arg("sh")
|
||||
.arg(&abs_build_script);
|
||||
cmd
|
||||
};
|
||||
cmd.current_dir(&build_dir);
|
||||
cmd.current_dir(&build_dir);
|
||||
|
||||
crate::builder::prepare_tool_command(&mut cmd, &env_vars);
|
||||
crate::builder::prepare_tool_command(&mut cmd, &env_vars);
|
||||
|
||||
// Run the command and include the OS error on spawn failures for clearer diagnostics
|
||||
let status = crate::interrupts::command_status(&mut cmd).map_err(|e| {
|
||||
anyhow::anyhow!(
|
||||
"Failed to run build script {}: {}",
|
||||
build_script.display(),
|
||||
e
|
||||
)
|
||||
})?;
|
||||
// Run the command and include the OS error on spawn failures for clearer diagnostics
|
||||
let status = crate::interrupts::command_status(&mut cmd).map_err(|e| {
|
||||
anyhow::anyhow!(
|
||||
"Failed to run build script {}: {}",
|
||||
build_script.display(),
|
||||
e
|
||||
)
|
||||
})?;
|
||||
|
||||
if !status.success() {
|
||||
anyhow::bail!("Custom build script failed with status: {}", status);
|
||||
if !status.success() {
|
||||
anyhow::bail!("Custom build script failed with status: {}", status);
|
||||
}
|
||||
}
|
||||
if flags.lib32_variant {
|
||||
crate::builder::stage_lib32_install_tree(&install_destdir, destdir)?;
|
||||
@@ -213,11 +222,7 @@ fn custom_function_mode_enabled(build_script: &Path) -> Result<bool> {
|
||||
|| contents.contains("install_"))
|
||||
}
|
||||
|
||||
fn build_function_mode_command(
|
||||
spec: &PackageSpec,
|
||||
destdir: &Path,
|
||||
build_script: &Path,
|
||||
) -> Result<Command> {
|
||||
fn function_mode_shell_prelude() -> String {
|
||||
let mut wrapper = crate::shell_helpers::wrap_shell_command("");
|
||||
wrapper.push_str("\nset -eu\n");
|
||||
wrapper.push_str("depot_has_function() {\n");
|
||||
@@ -226,11 +231,39 @@ fn build_function_mode_command(
|
||||
wrapper.push_str(" *) return 1 ;;\n");
|
||||
wrapper.push_str(" esac\n");
|
||||
wrapper.push_str("}\n");
|
||||
wrapper
|
||||
}
|
||||
|
||||
fn build_function_mode_build_command(build_script: &Path, state_file: &Path) -> Command {
|
||||
let mut wrapper = function_mode_shell_prelude();
|
||||
wrapper.push_str("depot_build_ran=0\n");
|
||||
wrapper.push_str(". \"$1\"\n");
|
||||
wrapper.push_str("if depot_has_function depot_build; then depot_build; depot_build_ran=1;\n");
|
||||
wrapper.push_str("elif depot_has_function build; then build; depot_build_ran=1;\n");
|
||||
wrapper.push_str("fi\n");
|
||||
wrapper.push_str("printf '%s\\n' \"$depot_build_ran\" > \"$2\"\n");
|
||||
|
||||
let mut cmd = Command::new("sh");
|
||||
cmd.arg("-c")
|
||||
.arg(wrapper)
|
||||
.arg("sh")
|
||||
.arg(build_script)
|
||||
.arg(state_file);
|
||||
cmd
|
||||
}
|
||||
|
||||
fn build_function_mode_install_command(
|
||||
spec: &PackageSpec,
|
||||
destdir: &Path,
|
||||
build_script: &Path,
|
||||
build_ran: bool,
|
||||
) -> Command {
|
||||
let mut wrapper = function_mode_shell_prelude();
|
||||
wrapper.push_str(&format!(
|
||||
"depot_build_ran={}\n",
|
||||
if build_ran { 1 } else { 0 }
|
||||
));
|
||||
wrapper.push_str(". \"$1\"\n");
|
||||
|
||||
let primary = &spec.package.name;
|
||||
for out in spec.outputs() {
|
||||
@@ -272,7 +305,65 @@ fn build_function_mode_command(
|
||||
|
||||
let mut cmd = fakeroot::wrap_install_command("sh", destdir);
|
||||
cmd.arg("-c").arg(wrapper).arg("sh").arg(build_script);
|
||||
Ok(cmd)
|
||||
cmd
|
||||
}
|
||||
|
||||
fn run_function_mode_build_script(
|
||||
spec: &PackageSpec,
|
||||
build_dir: &Path,
|
||||
install_destdir: &Path,
|
||||
build_script: &Path,
|
||||
env_vars: &crate::builder::EnvVars,
|
||||
) -> Result<()> {
|
||||
let state_file = NamedTempFile::new_in(build_dir).with_context(|| {
|
||||
format!(
|
||||
"Failed to create function mode state file in {}",
|
||||
build_dir.display()
|
||||
)
|
||||
})?;
|
||||
let state_path = state_file.path().to_path_buf();
|
||||
|
||||
let mut build_cmd = build_function_mode_build_command(build_script, &state_path);
|
||||
build_cmd.current_dir(build_dir);
|
||||
let mut build_env = env_vars.clone();
|
||||
crate::builder::set_env_var(
|
||||
&mut build_env,
|
||||
"DESTDIR",
|
||||
install_destdir.to_string_lossy().into_owned(),
|
||||
);
|
||||
crate::builder::prepare_tool_command(&mut build_cmd, &build_env);
|
||||
let build_status = crate::interrupts::command_status(&mut build_cmd).map_err(|e| {
|
||||
anyhow::anyhow!(
|
||||
"Failed to run build script {}: {}",
|
||||
build_script.display(),
|
||||
e
|
||||
)
|
||||
})?;
|
||||
if !build_status.success() {
|
||||
anyhow::bail!("Custom build script failed with status: {}", build_status);
|
||||
}
|
||||
|
||||
let build_ran = fs::read_to_string(&state_path)
|
||||
.ok()
|
||||
.map(|value| value.trim() == "1")
|
||||
.unwrap_or(false);
|
||||
|
||||
let mut install_cmd =
|
||||
build_function_mode_install_command(spec, install_destdir, build_script, build_ran);
|
||||
install_cmd.current_dir(build_dir);
|
||||
crate::builder::prepare_tool_command(&mut install_cmd, env_vars);
|
||||
let install_status = crate::interrupts::command_status(&mut install_cmd).map_err(|e| {
|
||||
anyhow::anyhow!(
|
||||
"Failed to run build script {}: {}",
|
||||
build_script.display(),
|
||||
e
|
||||
)
|
||||
})?;
|
||||
if !install_status.success() {
|
||||
anyhow::bail!("Custom build script failed with status: {}", install_status);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn shell_fn_suffix(pkg_name: &str) -> String {
|
||||
@@ -430,6 +521,70 @@ depot_install_dev_pkg() {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build_function_mode_only_uses_fakeroot_for_install() -> Result<()> {
|
||||
let tmp_src = tempdir()?;
|
||||
let tmp_dest = tempdir()?;
|
||||
|
||||
let build_sh = tmp_src.path().join("build.sh");
|
||||
std::fs::write(
|
||||
&build_sh,
|
||||
r#"#!/bin/sh
|
||||
depot_build() {
|
||||
if [ "${FAKEROOT_ACTIVE:-0}" = 1 ]; then
|
||||
echo yes > build-fakeroot.txt
|
||||
else
|
||||
echo no > build-fakeroot.txt
|
||||
fi
|
||||
}
|
||||
depot_install() {
|
||||
mkdir -p "$DESTDIR/usr/share"
|
||||
echo installed > "$DESTDIR/usr/share/install-fakeroot.txt"
|
||||
}
|
||||
"#,
|
||||
)?;
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let mut perms = std::fs::metadata(&build_sh)?.permissions();
|
||||
perms.set_mode(0o755);
|
||||
std::fs::set_permissions(&build_sh, perms)?;
|
||||
}
|
||||
|
||||
let spec = mk_spec("custom-function-fakeroot-split", "1.0");
|
||||
build(&spec, tmp_src.path(), tmp_dest.path(), None, true, None)?;
|
||||
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(tmp_src.path().join("build-fakeroot.txt"))?,
|
||||
"no\n"
|
||||
);
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(tmp_dest.path().join("usr/share/install-fakeroot.txt"))?,
|
||||
"installed\n"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build_function_mode_commands_split_fakeroot_boundary() {
|
||||
let build_script = Path::new("/tmp/build.sh");
|
||||
let state_file = Path::new("/tmp/build-state");
|
||||
let install_destdir = Path::new("/tmp/destdir");
|
||||
|
||||
let build_cmd = build_function_mode_build_command(build_script, state_file);
|
||||
assert_eq!(build_cmd.get_program(), std::ffi::OsStr::new("sh"));
|
||||
|
||||
let spec = mk_spec("custom-function-fakeroot-split", "1.0");
|
||||
let install_cmd =
|
||||
build_function_mode_install_command(&spec, install_destdir, build_script, true);
|
||||
let expected = if crate::fakeroot::is_root() {
|
||||
std::ffi::OsStr::new("sh")
|
||||
} else {
|
||||
std::ffi::OsStr::new("fakeroot")
|
||||
};
|
||||
assert_eq!(install_cmd.get_program(), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build_function_mode_errors_when_output_handler_missing() -> Result<()> {
|
||||
let tmp_src = tempdir()?;
|
||||
|
||||
@@ -65,7 +65,7 @@ pub fn build(
|
||||
for arg in meson_setup_args(flags, cross_file.as_deref(), &env_vars) {
|
||||
meson_cmd.arg(arg);
|
||||
}
|
||||
for arg in crate::builder::static_build_args_for(crate::package::BuildType::Meson)? {
|
||||
for arg in crate::builder::static_build_args_for(crate::package::BuildType::Meson, flags)? {
|
||||
meson_cmd.arg(arg);
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ pub(crate) fn ensure_host_build(
|
||||
for arg in meson_setup_args(flags, None, &env_vars) {
|
||||
meson_cmd.arg(arg);
|
||||
}
|
||||
for arg in crate::builder::static_build_args_for(crate::package::BuildType::Meson)? {
|
||||
for arg in crate::builder::static_build_args_for(crate::package::BuildType::Meson, flags)? {
|
||||
meson_cmd.arg(arg);
|
||||
}
|
||||
|
||||
|
||||
+53
-7
@@ -12,7 +12,7 @@ mod rust;
|
||||
pub mod state;
|
||||
|
||||
use crate::cross::CrossConfig;
|
||||
use crate::package::{BuildType, PackageSpec};
|
||||
use crate::package::{BuildFlags, BuildType, PackageSpec};
|
||||
use anyhow::{Context, Result};
|
||||
use std::ffi::OsString;
|
||||
use std::fs;
|
||||
@@ -188,12 +188,20 @@ pub(crate) fn requested_static_build() -> Result<Option<bool>> {
|
||||
crate::build_options::requested_static_build()
|
||||
}
|
||||
|
||||
pub(crate) fn static_build_args_for(build_type: BuildType) -> Result<Vec<String>> {
|
||||
let Some(enabled) = requested_static_build()? else {
|
||||
return Ok(Vec::new());
|
||||
fn static_build_args_for_request(
|
||||
build_type: BuildType,
|
||||
requested_static: Option<bool>,
|
||||
no_delete_static: bool,
|
||||
) -> Vec<String> {
|
||||
let Some(enabled) = requested_static else {
|
||||
return Vec::new();
|
||||
};
|
||||
|
||||
let args = match build_type {
|
||||
if !enabled && no_delete_static {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
match build_type {
|
||||
BuildType::Autotools => vec![if enabled {
|
||||
"--enable-static".to_string()
|
||||
} else {
|
||||
@@ -212,9 +220,18 @@ pub(crate) fn static_build_args_for(build_type: BuildType) -> Result<Vec<String>
|
||||
if enabled { "static" } else { "dynamic" }
|
||||
)],
|
||||
_ => Vec::new(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Ok(args)
|
||||
pub(crate) fn static_build_args_for(
|
||||
build_type: BuildType,
|
||||
flags: &BuildFlags,
|
||||
) -> Result<Vec<String>> {
|
||||
Ok(static_build_args_for_request(
|
||||
build_type,
|
||||
requested_static_build()?,
|
||||
flags.no_delete_static,
|
||||
))
|
||||
}
|
||||
|
||||
pub(crate) fn build_tool_package_option(build_type: BuildType) -> Option<&'static str> {
|
||||
@@ -225,6 +242,14 @@ pub(crate) fn requested_build_tool_package(build_type: BuildType) -> Option<Stri
|
||||
crate::build_options::requested_build_tool_package(build_type)
|
||||
}
|
||||
|
||||
pub(crate) fn development_package_option() -> &'static str {
|
||||
crate::build_options::development_package_option()
|
||||
}
|
||||
|
||||
pub(crate) fn requested_development_package() -> Option<String> {
|
||||
crate::build_options::requested_development_package()
|
||||
}
|
||||
|
||||
fn configured_install_dir(value: &str, default: &str) -> String {
|
||||
let trimmed = value.trim();
|
||||
if trimmed.is_empty() {
|
||||
@@ -943,6 +968,27 @@ mod tests {
|
||||
assert_eq!(build_tool_package_option(BuildType::Bin), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_static_build_args_skip_disable_static_when_no_delete_static_enabled() {
|
||||
let args = static_build_args_for_request(BuildType::Autotools, Some(false), true);
|
||||
assert!(args.is_empty());
|
||||
|
||||
let args = static_build_args_for_request(BuildType::CMake, Some(false), true);
|
||||
assert!(args.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_static_build_args_keep_other_requested_modes() {
|
||||
assert_eq!(
|
||||
static_build_args_for_request(BuildType::Autotools, Some(false), false),
|
||||
vec!["--disable-static".to_string()]
|
||||
);
|
||||
assert_eq!(
|
||||
static_build_args_for_request(BuildType::Meson, Some(true), true),
|
||||
vec!["-Ddefault_library=static".to_string()]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_standard_build_env_exports_native_linker_and_cpp() {
|
||||
let mut spec = mk_spec(Vec::new(), Vec::new());
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ pub fn build(
|
||||
for arg in &flags.configure {
|
||||
configure_cmd.arg(spec.expand_vars(arg));
|
||||
}
|
||||
for arg in crate::builder::static_build_args_for(crate::package::BuildType::Perl)? {
|
||||
for arg in crate::builder::static_build_args_for(crate::package::BuildType::Perl, flags)? {
|
||||
configure_cmd.arg(arg);
|
||||
}
|
||||
crate::builder::prepare_tool_command(&mut configure_cmd, &env_vars);
|
||||
|
||||
Reference in New Issue
Block a user