Skip to content

Commit

Permalink
launch.rs: Remove need for nightly Rust and make subshell error more …
Browse files Browse the repository at this point in the history
…verbose.

I was assuming [`exit_status_error`][1] would be stabilized quickly, but
there's been no movement on it for at least a year and there are now other
[(possibly) competing/conflicting proposals][2].

This should reduce [confusion when trying to build the launcher][3].

[1]: rust-lang/rust#84908
[2]: rust-lang/rfcs#3362
[3]: #137 (comment)
  • Loading branch information
caldwell committed Dec 11, 2024
1 parent 1948d20 commit 4b59686
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#![feature(exit_status_error)]

use std::error::Error;
use std::vec::Vec;
use std::collections::hash_map::HashMap;
Expand Down Expand Up @@ -175,15 +173,16 @@ fn get_shell_environment() -> Result<HashMap<OsString,OsString>, Box<dyn Error>>

fn osstr(s: &str) -> OsString { OsString::from(s) }
let (mut reader, writer) = pipe()?;
let mut child = Command::new(std::env::var_os("SHELL").unwrap_or(osstr("sh"))).args([osstr("--login"), osstr("-c"), std::env::current_exe()?.into_os_string()])
let mut command = Command::new(std::env::var_os("SHELL").unwrap_or(osstr("sh")));
let mut child = command.args([osstr("--login"), osstr("-c"), std::env::current_exe()?.into_os_string()])
.env(DUMP_ENV_NAME, format!("{}", writer.as_raw_fd()))
.stdin(std::process::Stdio::null())
.spawn()?;
drop(writer); // force parent to close writer
let mut env_raw = Vec::new();
let r2end = reader.read_to_end(&mut env_raw);
let status = child.wait()?; // Make sure we call wait
status.exit_ok()?;
if !status.success() { Err(format!("Command: {command:?}\nFailed: {status}"))? }
let _count = r2end?;

// This dedupes environment variables as a side effect (see comment in dedup_environment())
Expand Down

0 comments on commit 4b59686

Please sign in to comment.