Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5f14568
std: get rid of `sys_common::process`
joboet Mar 27, 2025
0f81fca
Change rustc_driver dependency on stable_mir crate
celinval Apr 30, 2025
415a73e
docs: alias `limit` to `Iterator::take`, cite `[u8]::utf8_chunks` in …
ShE3py May 2, 2025
cbdd713
Implement Iterator::last for vec::IntoIter
thaliaarchi Apr 13, 2025
6621826
Implement RFC 3503: frontmatters
fee1-dead Apr 12, 2025
b796179
Created `tests/rustdoc/reexports` subfolder to limit number of files …
GuillaumeGomez May 5, 2025
099f730
Created `tests/rustdoc/source-code-pages` subfolder to limit number o…
GuillaumeGomez May 5, 2025
b374996
Created `tests/rustdoc/anchors` subfolder to limit number of files at…
GuillaumeGomez May 5, 2025
ff971d0
Created `tests/rustdoc/auto` subfolder to limit number of files at th…
GuillaumeGomez May 5, 2025
9db7de5
Created `tests/rustdoc/jump-to-def` subfolder to limit number of file…
GuillaumeGomez May 5, 2025
a00b399
Move intra-doc tests into the expected subfolder
GuillaumeGomez May 5, 2025
eee6c97
Created `tests/rustdoc/private` subfolder to limit number of files at…
GuillaumeGomez May 5, 2025
d1f4a0b
Created `tests/rustdoc/macro` subfolder to limit number of files at t…
GuillaumeGomez May 5, 2025
be71d8b
Created `tests/rustdoc/doc-cfg` subfolder to limit number of files at…
GuillaumeGomez May 5, 2025
b84f4cc
Created `tests/rustdoc/impl` subfolder to limit number of files at th…
GuillaumeGomez May 5, 2025
fa2b922
Created `tests/rustdoc/assoc` subfolder to limit number of files at t…
GuillaumeGomez May 5, 2025
4b6bc73
Created `tests/rustdoc/enum` subfolder to limit number of files at th…
GuillaumeGomez May 5, 2025
e245c3b
Move primitive rustdoc tests into the `primitive` sub folder
GuillaumeGomez May 5, 2025
e14e19a
Created `tests/rustdoc/extern` subfolder to limit number of files at …
GuillaumeGomez May 5, 2025
27e39c3
Created `tests/rustdoc/async` subfolder to limit number of files at t…
GuillaumeGomez May 5, 2025
fa6d0d1
Use more accurate ELF flags on MIPS
smrobtzz May 4, 2025
57941af
Apply suggestions from code review
smrobtzz May 5, 2025
6a7996e
Take into-account `-Zremap-path-scope` when embedding filenames
Urgau Apr 19, 2025
c0dfa44
Be a bit more relaxed about not yet constrained infer vars in closure…
compiler-errors May 5, 2025
9c11c02
[Arm64EC] Only decorate functions with `#`
dpaoliello Apr 25, 2025
292aea5
Update mdbook to 0.4.49
ehuss May 5, 2025
a3d5562
bootstrap: Add check/test/run steps for src/tools/coverage-dump
Zalathar Apr 22, 2025
89319f2
coverage-dump: Extract some common code to an `llvm_utils` submodule
Zalathar Apr 23, 2025
bc3f0e3
coverage-dump: Extract a common parser method for maybe-compressed bytes
Zalathar Apr 23, 2025
f1b8cd4
coverage-dump: Include filenames hash in covfun line data
Zalathar Apr 22, 2025
041b2b2
coverage-dump: Make filenames available to covfun record dumping
Zalathar Apr 24, 2025
c53a767
coverage-dump: Dump filenames instead of global file IDs (and bless)
Zalathar Apr 24, 2025
51b74c9
Rollup merge of #139550 - Urgau:rmeta-remap-path-scope, r=nnethercote
Zalathar May 6, 2025
608e98a
Rollup merge of #139773 - thaliaarchi:vec-into-iter-last, r=workingju…
Zalathar May 6, 2025
b90beb5
Rollup merge of #140035 - fee1-dead-contrib:push-oszwkkvmpkks, r=jiey…
Zalathar May 6, 2025
24262b7
Rollup merge of #140176 - dpaoliello:arm64ecdec, r=wesleywiser
Zalathar May 6, 2025
c667fd9
Rollup merge of #140251 - Zalathar:coverage-dump-path, r=clubby789
Zalathar May 6, 2025
fa02cb0
Rollup merge of #140393 - joboet:sys_common_process, r=thomcc
Zalathar May 6, 2025
e650155
Rollup merge of #140532 - celinval:chores-smir-ra, r=oli-obk
Zalathar May 6, 2025
7300b97
Rollup merge of #140598 - ShE3py:iter-misc-docs, r=workingjubilee
Zalathar May 6, 2025
a7c6b50
Rollup merge of #140634 - smrobtzz:mips-elf-fixes, r=workingjubilee
Zalathar May 6, 2025
c1272ba
Rollup merge of #140673 - GuillaumeGomez:clean-rustdoc-tests, r=notri…
Zalathar May 6, 2025
8eec52e
Rollup merge of #140678 - compiler-errors:dont-ice-on-infer-in-upvar,…
Zalathar May 6, 2025
1e27a12
Rollup merge of #140687 - ehuss:update-mdbook, r=jieyouxu
Zalathar May 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
std: get rid of sys_common::process
Move the public `CommandEnvs` into the `process` module (and make it a wrapper type for an internal iterator type) and everything else into `sys::process` as per #117276.
  • Loading branch information
joboet committed Apr 28, 2025
commit 5f145689b1c0a313ee737de296a57d1479c18cb5
48 changes: 44 additions & 4 deletions library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ use crate::num::NonZero;
use crate::path::Path;
use crate::sys::pipe::{AnonPipe, read2};
use crate::sys::process as imp;
#[stable(feature = "command_access", since = "1.57.0")]
pub use crate::sys_common::process::CommandEnvs;
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
use crate::{fmt, fs, str};

Expand Down Expand Up @@ -1073,7 +1071,7 @@ impl Command {
/// ```
#[stable(feature = "process", since = "1.0.0")]
pub fn output(&mut self) -> io::Result<Output> {
let (status, stdout, stderr) = self.inner.output()?;
let (status, stdout, stderr) = imp::output(&mut self.inner)?;
Ok(Output { status: ExitStatus(status), stdout, stderr })
}

Expand Down Expand Up @@ -1174,7 +1172,7 @@ impl Command {
/// ```
#[stable(feature = "command_access", since = "1.57.0")]
pub fn get_envs(&self) -> CommandEnvs<'_> {
self.inner.get_envs()
CommandEnvs { iter: self.inner.get_envs() }
}

/// Returns the working directory for the child process.
Expand Down Expand Up @@ -1264,6 +1262,48 @@ impl<'a> ExactSizeIterator for CommandArgs<'a> {
}
}

/// An iterator over the command environment variables.
///
/// This struct is created by
/// [`Command::get_envs`][crate::process::Command::get_envs]. See its
/// documentation for more.
#[must_use = "iterators are lazy and do nothing unless consumed"]
#[stable(feature = "command_access", since = "1.57.0")]
pub struct CommandEnvs<'a> {
iter: imp::CommandEnvs<'a>,
}

#[stable(feature = "command_access", since = "1.57.0")]
impl<'a> Iterator for CommandEnvs<'a> {
type Item = (&'a OsStr, Option<&'a OsStr>);

fn next(&mut self) -> Option<Self::Item> {
self.iter.next()
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}

#[stable(feature = "command_access", since = "1.57.0")]
impl<'a> ExactSizeIterator for CommandEnvs<'a> {
fn len(&self) -> usize {
self.iter.len()
}

fn is_empty(&self) -> bool {
self.iter.is_empty()
}
}

#[stable(feature = "command_access", since = "1.57.0")]
impl<'a> fmt::Debug for CommandEnvs<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.iter.fmt(f)
}
}

/// The output of a finished process.
///
/// This is returned in a Result by either the [`output`] method of a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#![allow(dead_code)]
#![unstable(feature = "process_internals", issue = "none")]

use crate::collections::BTreeMap;
use crate::ffi::{OsStr, OsString};
use crate::sys::pipe::read2;
use crate::sys::process::{EnvKey, ExitStatus, Process, StdioPipes};
use crate::{env, fmt, io};
use crate::sys::process::EnvKey;
use crate::{env, fmt};

// Stores a set of changes to an environment
/// Stores a set of changes to an environment
#[derive(Clone, Default)]
pub struct CommandEnv {
clear: bool,
Expand Down Expand Up @@ -92,30 +88,23 @@ impl CommandEnv {
}
}

/// An iterator over the command environment variables.
///
/// This struct is created by
/// [`Command::get_envs`][crate::process::Command::get_envs]. See its
/// documentation for more.
#[must_use = "iterators are lazy and do nothing unless consumed"]
#[stable(feature = "command_access", since = "1.57.0")]
#[derive(Debug)]
pub struct CommandEnvs<'a> {
iter: crate::collections::btree_map::Iter<'a, EnvKey, Option<OsString>>,
}

#[stable(feature = "command_access", since = "1.57.0")]
impl<'a> Iterator for CommandEnvs<'a> {
type Item = (&'a OsStr, Option<&'a OsStr>);

fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(key, value)| (key.as_ref(), value.as_deref()))
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}

#[stable(feature = "command_access", since = "1.57.0")]
impl<'a> ExactSizeIterator for CommandEnvs<'a> {
fn len(&self) -> usize {
self.iter.len()
Expand All @@ -124,30 +113,3 @@ impl<'a> ExactSizeIterator for CommandEnvs<'a> {
self.iter.is_empty()
}
}

pub fn wait_with_output(
mut process: Process,
mut pipes: StdioPipes,
) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
drop(pipes.stdin.take());

let (mut stdout, mut stderr) = (Vec::new(), Vec::new());
match (pipes.stdout.take(), pipes.stderr.take()) {
(None, None) => {}
(Some(out), None) => {
let res = out.read_to_end(&mut stdout);
res.unwrap();
}
(None, Some(err)) => {
let res = err.read_to_end(&mut stderr);
res.unwrap();
}
(Some(out), Some(err)) => {
let res = read2(out, &mut stdout, err, &mut stderr);
res.unwrap();
}
}

let status = process.wait()?;
Ok((status, stdout, stderr))
}
59 changes: 59 additions & 0 deletions library/std/src/sys/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,65 @@ cfg_if::cfg_if! {
}
}

// This module is shared by all platforms, but nearly all platforms except for
// the "normal" UNIX ones leave some of this code unused.
#[cfg_attr(not(target_os = "linux"), allow(dead_code))]
mod env;

pub use env::CommandEnvs;
pub use imp::{
Command, CommandArgs, EnvKey, ExitCode, ExitStatus, ExitStatusError, Process, Stdio, StdioPipes,
};

#[cfg(any(
all(
target_family = "unix",
not(any(
target_os = "espidf",
target_os = "horizon",
target_os = "vita",
target_os = "nuttx"
))
),
target_os = "windows",
))]
pub fn output(cmd: &mut Command) -> crate::io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
use crate::sys::pipe::read2;

let (mut process, mut pipes) = cmd.spawn(Stdio::MakePipe, false)?;

drop(pipes.stdin.take());
let (mut stdout, mut stderr) = (Vec::new(), Vec::new());
match (pipes.stdout.take(), pipes.stderr.take()) {
(None, None) => {}
(Some(out), None) => {
let res = out.read_to_end(&mut stdout);
res.unwrap();
}
(None, Some(err)) => {
let res = err.read_to_end(&mut stderr);
res.unwrap();
}
(Some(out), Some(err)) => {
let res = read2(out, &mut stdout, err, &mut stderr);
res.unwrap();
}
}

let status = process.wait()?;
Ok((status, stdout, stderr))
}

#[cfg(not(any(
all(
target_family = "unix",
not(any(
target_os = "espidf",
target_os = "horizon",
target_os = "vita",
target_os = "nuttx"
))
),
target_os = "windows",
)))]
pub use imp::output;
116 changes: 58 additions & 58 deletions library/std/src/sys/process/uefi.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use r_efi::protocols::{simple_text_input, simple_text_output};

use super::env::{CommandEnv, CommandEnvs};
use crate::collections::BTreeMap;
pub use crate::ffi::OsString as EnvKey;
use crate::ffi::{OsStr, OsString};
Expand All @@ -10,7 +11,6 @@ use crate::sys::pal::helpers;
use crate::sys::pal::os::error_string;
use crate::sys::pipe::AnonPipe;
use crate::sys::unsupported;
use crate::sys_common::process::{CommandEnv, CommandEnvs};
use crate::{fmt, io};

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -139,72 +139,72 @@ impl Command {
Stdio::MakePipe => unsupported(),
}
}
}

pub fn output(&mut self) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
let mut cmd = uefi_command_internal::Image::load_image(&self.prog)?;

// UEFI adds the bin name by default
if !self.args.is_empty() {
let args = uefi_command_internal::create_args(&self.prog, &self.args);
cmd.set_args(args);
}

// Setup Stdout
let stdout = self.stdout.unwrap_or(Stdio::MakePipe);
let stdout = Self::create_pipe(stdout)?;
if let Some(con) = stdout {
cmd.stdout_init(con)
} else {
cmd.stdout_inherit()
};

// Setup Stderr
let stderr = self.stderr.unwrap_or(Stdio::MakePipe);
let stderr = Self::create_pipe(stderr)?;
if let Some(con) = stderr {
cmd.stderr_init(con)
} else {
cmd.stderr_inherit()
};

// Setup Stdin
let stdin = self.stdin.unwrap_or(Stdio::Null);
let stdin = Self::create_stdin(stdin)?;
if let Some(con) = stdin {
cmd.stdin_init(con)
} else {
cmd.stdin_inherit()
};

let env = env_changes(&self.env);

// Set any new vars
if let Some(e) = &env {
for (k, (_, v)) in e {
match v {
Some(v) => unsafe { crate::env::set_var(k, v) },
None => unsafe { crate::env::remove_var(k) },
}
pub fn output(command: &mut Command) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
let mut cmd = uefi_command_internal::Image::load_image(&command.prog)?;

// UEFI adds the bin name by default
if !command.args.is_empty() {
let args = uefi_command_internal::create_args(&command.prog, &command.args);
cmd.set_args(args);
}

// Setup Stdout
let stdout = command.stdout.unwrap_or(Stdio::MakePipe);
let stdout = Command::create_pipe(stdout)?;
if let Some(con) = stdout {
cmd.stdout_init(con)
} else {
cmd.stdout_inherit()
};

// Setup Stderr
let stderr = command.stderr.unwrap_or(Stdio::MakePipe);
let stderr = Command::create_pipe(stderr)?;
if let Some(con) = stderr {
cmd.stderr_init(con)
} else {
cmd.stderr_inherit()
};

// Setup Stdin
let stdin = command.stdin.unwrap_or(Stdio::Null);
let stdin = Command::create_stdin(stdin)?;
if let Some(con) = stdin {
cmd.stdin_init(con)
} else {
cmd.stdin_inherit()
};

let env = env_changes(&command.env);

// Set any new vars
if let Some(e) = &env {
for (k, (_, v)) in e {
match v {
Some(v) => unsafe { crate::env::set_var(k, v) },
None => unsafe { crate::env::remove_var(k) },
}
}
}

let stat = cmd.start_image()?;
let stat = cmd.start_image()?;

// Rollback any env changes
if let Some(e) = env {
for (k, (v, _)) in e {
match v {
Some(v) => unsafe { crate::env::set_var(k, v) },
None => unsafe { crate::env::remove_var(k) },
}
// Rollback any env changes
if let Some(e) = env {
for (k, (v, _)) in e {
match v {
Some(v) => unsafe { crate::env::set_var(k, v) },
None => unsafe { crate::env::remove_var(k) },
}
}
}

let stdout = cmd.stdout()?;
let stderr = cmd.stderr()?;
let stdout = cmd.stdout()?;
let stderr = cmd.stderr()?;

Ok((ExitStatus(stat), stdout, stderr))
}
Ok((ExitStatus(stat), stdout, stderr))
}

impl From<AnonPipe> for Stdio {
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/process/unix/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::sys::fs::File;
#[cfg(not(target_os = "fuchsia"))]
use crate::sys::fs::OpenOptions;
use crate::sys::pipe::{self, AnonPipe};
use crate::sys_common::process::{CommandEnv, CommandEnvs};
use crate::sys::process::env::{CommandEnv, CommandEnvs};
use crate::sys_common::{FromInner, IntoInner};
use crate::{fmt, io, ptr};

Expand Down
5 changes: 0 additions & 5 deletions library/std/src/sys/process/unix/fuchsia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ impl Command {
Ok((Process { handle: Handle::new(process_handle) }, ours))
}

pub fn output(&mut self) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
let (proc, pipes) = self.spawn(Stdio::MakePipe, false)?;
crate::sys_common::process::wait_with_output(proc, pipes)
}

pub fn exec(&mut self, default: Stdio) -> io::Error {
if self.saw_nul() {
return io::const_error!(
Expand Down
Loading
Loading