Skip to content

Commit

Permalink
Rollup merge of #97466 - jyn514:consolidate-install, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
[bootstrap] Move `sanitize_sh` from `dist` to `install`

This is the only place it's used, so there's no need for it to be public in another module.
In general, `dist` shouldn't ever touch shell scripts.
  • Loading branch information
Dylan-DPC authored May 28, 2022
2 parents 529fcb5 + 81e2c11 commit 5badc29
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
23 changes: 0 additions & 23 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,29 +894,6 @@ impl Step for PlainSourceTarball {
}
}

// We have to run a few shell scripts, which choke quite a bit on both `\`
// characters and on `C:\` paths, so normalize both of them away.
pub fn sanitize_sh(path: &Path) -> String {
let path = path.to_str().unwrap().replace("\\", "/");
return change_drive(unc_to_lfs(&path)).unwrap_or(path);

fn unc_to_lfs(s: &str) -> &str {
s.strip_prefix("//?/").unwrap_or(s)
}

fn change_drive(s: &str) -> Option<String> {
let mut ch = s.chars();
let drive = ch.next().unwrap_or('C');
if ch.next() != Some(':') {
return None;
}
if ch.next() != Some('/') {
return None;
}
Some(format!("/{}/{}", drive, &s[drive.len_utf8() + 2..]))
}
}

#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Cargo {
pub compiler: Compiler,
Expand Down
27 changes: 25 additions & 2 deletions src/bootstrap/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
use std::env;
use std::fs;
use std::path::{Component, PathBuf};
use std::path::{Component, Path, PathBuf};
use std::process::Command;

use crate::util::t;

use crate::dist::{self, sanitize_sh};
use crate::dist;
use crate::tarball::GeneratedTarball;
use crate::Compiler;

Expand All @@ -22,6 +22,29 @@ const SHELL: &str = "bash";
#[cfg(not(target_os = "illumos"))]
const SHELL: &str = "sh";

// We have to run a few shell scripts, which choke quite a bit on both `\`
// characters and on `C:\` paths, so normalize both of them away.
fn sanitize_sh(path: &Path) -> String {
let path = path.to_str().unwrap().replace("\\", "/");
return change_drive(unc_to_lfs(&path)).unwrap_or(path);

fn unc_to_lfs(s: &str) -> &str {
s.strip_prefix("//?/").unwrap_or(s)
}

fn change_drive(s: &str) -> Option<String> {
let mut ch = s.chars();
let drive = ch.next().unwrap_or('C');
if ch.next() != Some(':') {
return None;
}
if ch.next() != Some('/') {
return None;
}
Some(format!("/{}/{}", drive, &s[drive.len_utf8() + 2..]))
}
}

fn install_sh(
builder: &Builder<'_>,
package: &str,
Expand Down

0 comments on commit 5badc29

Please sign in to comment.