Skip to content

Commit 0d82b65

Browse files
committed
wip
1 parent c8dec07 commit 0d82b65

File tree

7 files changed

+61
-23
lines changed

7 files changed

+61
-23
lines changed

src/rustup-cli/proxy_mode.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,18 @@ pub fn main() -> Result<()> {
3434

3535
// Build command args now while we know whether or not to skip arg 1.
3636
let cmd_args: Vec<_> = if toolchain.is_none() {
37-
env::args_os().collect()
37+
env::args_os().skip(1).collect()
3838
} else {
39-
env::args_os().take(1).chain(env::args_os().skip(2)).collect()
39+
env::args_os().skip(2).collect()
4040
};
4141

4242
let cfg = try!(set_globals(false));
4343
try!(cfg.check_metadata_version());
44+
println!("PPATH {}", ::std::env::var("PATH").unwrap_or("X".to_string()));
45+
println!("PRUSTUP_TOOLCHAIN {}", ::std::env::var("RUSTUP_TOOLCHAIN").unwrap_or("X".to_string()));
46+
println!("PCARGO_HOME {}", ::std::env::var("CARGO_HOME").unwrap_or("X".to_string()));
47+
println!("arg0 {}", arg0);
48+
println!("args[0] {}", cmd_args[0].to_string_lossy());
4449
try!(direct_proxy(&cfg, arg0, toolchain, &cmd_args));
4550

4651
Ok(())
@@ -51,6 +56,6 @@ fn direct_proxy(cfg: &Cfg, arg0: &str, toolchain: Option<&str>, args: &[OsString
5156
None => try!(cfg.create_command_for_dir(&try!(utils::current_dir()), arg0)),
5257
Some(tc) => try!(cfg.create_command_for_toolchain(tc, arg0)),
5358
};
54-
Ok(try!(run_command_for_dir(cmd, &args, &cfg)))
59+
Ok(try!(run_command_for_dir(cmd, arg0, args, &cfg)))
5560
}
5661

src/rustup-mock/src/mock_bin_src.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
use std::process::Command;
22
use std::io::{self, BufWriter, Write};
3+
use std::env::consts::EXE_SUFFIX;
34

45
fn main() {
6+
let args: Vec<_> = ::std::env::args().collect();
7+
let env = ::std::env::var("PATH").unwrap();
8+
println!("mock-bin self-exe {}", ::std::env::current_exe().unwrap().display());
9+
println!("mock-bin cwd {}", ::std::env::current_dir().unwrap().display());
10+
println!("mock-bin arg0 {}", args.get(0).unwrap());
11+
println!("mock-bin arg1 {}", args.get(1).unwrap());
12+
println!("mock-bin PATH {}", env);
513
let args: Vec<_> = ::std::env::args().collect();
614
if args.get(1) == Some(&"--version".to_string()) {
715
println!("%EXAMPLE_VERSION% (%EXAMPLE_VERSION_HASH%)");
@@ -18,7 +26,8 @@ fn main() {
1826
// Used by the fallback_cargo_calls_correct_rustc test. Tests that
1927
// the environment has been set up right such that invoking rustc
2028
// will actually invoke the wrapper
21-
Command::new("rustc").arg("--version").status().unwrap();
29+
let rustc = &format!("rustc{}", EXE_SUFFIX);
30+
Command::new(rustc).arg("--version").status().unwrap();
2231
} else {
2332
panic!("bad mock proxy commandline");
2433
}

src/rustup/command.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use std::env;
21
use std::ffi::OsStr;
32
use std::fs::File;
43
use std::io::{self, Write, BufRead, BufReader, Seek, SeekFrom};
5-
use std::path::PathBuf;
64
use std::process::{self, Command, Stdio};
75
use std::time::Instant;
86
use regex::Regex;
@@ -16,21 +14,19 @@ use telemetry::{Telemetry, TelemetryEvent};
1614

1715

1816
pub fn run_command_for_dir<S: AsRef<OsStr>>(cmd: Command,
17+
arg0: &S,
1918
args: &[S],
2019
cfg: &Cfg) -> Result<()> {
21-
let arg0 = env::args().next().map(PathBuf::from);
22-
let arg0 = arg0.as_ref()
23-
.and_then(|a| a.file_name())
24-
.and_then(|a| a.to_str());
25-
let arg0 = try!(arg0.ok_or(ErrorKind::NoExeName));
26-
if (arg0 == "rustc" || arg0 == "rustc.exe") && try!(cfg.telemetry_enabled()) {
27-
return telemetry_rustc(cmd, args, cfg);
20+
if (arg0.as_ref() == "rustc" || arg0.as_ref() == "rustc.exe") && try!(cfg.telemetry_enabled()) {
21+
return telemetry_rustc(cmd, arg0, args, cfg);
2822
}
2923

30-
run_command_for_dir_without_telemetry(cmd, args)
24+
run_command_for_dir_without_telemetry(cmd, arg0, args)
3125
}
3226

33-
fn telemetry_rustc<S: AsRef<OsStr>>(mut cmd: Command, args: &[S], cfg: &Cfg) -> Result<()> {
27+
fn telemetry_rustc<S: AsRef<OsStr>>(mut cmd: Command,
28+
arg0: &S,
29+
args: &[S], cfg: &Cfg) -> Result<()> {
3430
#[cfg(unix)]
3531
fn file_as_stdio(file: &File) -> Stdio {
3632
use std::os::unix::io::{AsRawFd, FromRawFd};
@@ -45,7 +41,7 @@ fn telemetry_rustc<S: AsRef<OsStr>>(mut cmd: Command, args: &[S], cfg: &Cfg) ->
4541

4642
let now = Instant::now();
4743

48-
cmd.args(&args[1..]);
44+
cmd.args(args);
4945

5046
let has_color_args = args.iter().any(|e| {
5147
let e = e.as_ref().to_str().unwrap_or("");
@@ -130,19 +126,22 @@ fn telemetry_rustc<S: AsRef<OsStr>>(mut cmd: Command, args: &[S], cfg: &Cfg) ->
130126
});
131127

132128
Err(e).chain_err(|| rustup_utils::ErrorKind::RunningCommand {
133-
name: args[0].as_ref().to_owned(),
129+
name: arg0.as_ref().to_owned(),
134130
})
135131
},
136132
}
137133
}
138134

139-
fn run_command_for_dir_without_telemetry<S: AsRef<OsStr>>(mut cmd: Command, args: &[S]) -> Result<()> {
140-
cmd.args(&args[1..]);
135+
fn run_command_for_dir_without_telemetry<S: AsRef<OsStr>>(
136+
mut cmd: Command, arg0: &S, args: &[S]) -> Result<()>
137+
{
138+
cmd.args(&args);
141139

142140
// FIXME rust-lang/rust#32254. It's not clear to me
143141
// when and why this is needed.
144142
cmd.stdin(process::Stdio::inherit());
145143

144+
println!("ARG0 {}", arg0.as_ref().to_string_lossy());
146145
match cmd.status() {
147146
Ok(status) => {
148147
// Ensure correct exit code is returned
@@ -151,7 +150,7 @@ fn run_command_for_dir_without_telemetry<S: AsRef<OsStr>>(mut cmd: Command, args
151150
}
152151
Err(e) => {
153152
Err(e).chain_err(|| rustup_utils::ErrorKind::RunningCommand {
154-
name: args[0].as_ref().to_owned(),
153+
name: arg0.as_ref().to_owned(),
155154
})
156155
}
157156
}

src/rustup/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,15 @@ impl Cfg {
321321
}
322322

323323
pub fn create_command_for_toolchain(&self, toolchain: &str, binary: &str) -> Result<Command> {
324+
println!("AA");
324325
let ref toolchain = try!(self.get_toolchain(toolchain, false));
326+
println!("BB");
325327

326328
if let Some(cmd) = try!(self.maybe_do_cargo_fallback(toolchain, binary)) {
329+
println!("CC");
327330
Ok(cmd)
328331
} else {
332+
println!("DD");
329333
toolchain.create_command(binary)
330334
}
331335
}

src/rustup/env_var.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub fn prepend_path(name: &str, value: &Path, cmd: &mut Command) {
2525
parts.extend(env::split_paths(v));
2626
}
2727
let new_value = env::join_paths(parts).unwrap_or_else(|_| OsString::from(value));
28+
println!("PATH {}", new_value.to_string_lossy());
2829

2930
cmd.env(name, new_value);
3031
}

src/rustup/toolchain.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ impl<'a> Toolchain<'a> {
6666
&self.path
6767
}
6868
pub fn exists(&self) -> bool {
69-
utils::is_directory(&self.path)
69+
println!("exists? {}", self.path.display());
70+
use std::fs;
71+
utils::is_directory(&self.path) || fs::symlink_metadata(&self.path).unwrap().file_type().is_symlink()
7072
}
7173
pub fn verify(&self) -> Result<()> {
7274
Ok(try!(utils::assert_is_directory(&self.path)))
@@ -277,6 +279,7 @@ impl<'a> Toolchain<'a> {
277279
}
278280

279281
let bin_path = &self.path.join("bin").join(binary.as_ref());
282+
println!("BINPATH {}", bin_path.display());
280283
let mut cmd = Command::new(bin_path);
281284
self.set_env(&mut cmd);
282285
Ok(cmd)
@@ -286,6 +289,14 @@ impl<'a> Toolchain<'a> {
286289
// to give custom toolchains access to cargo
287290
pub fn create_fallback_command<T: AsRef<OsStr>>(&self, binary: T,
288291
primary_toolchain: &Toolchain) -> Result<Command> {
292+
if !self.exists() {
293+
return Err(ErrorKind::ToolchainNotInstalled(self.name.to_owned()).into());
294+
}
295+
if !primary_toolchain.exists() {
296+
return Err(ErrorKind::ToolchainNotInstalled(self.name.to_owned()).into());
297+
}
298+
println!("RUNNING {}", binary.as_ref().to_string_lossy());
299+
println!("TOOLCHAIN {}", primary_toolchain.name);
289300
let mut cmd = try!(self.create_command(binary));
290301
cmd.env("RUSTUP_TOOLCHAIN", &primary_toolchain.name);
291302
Ok(cmd)
@@ -300,12 +311,14 @@ impl<'a> Toolchain<'a> {
300311
// multirust agree.
301312
if let Ok(cargo_home) = utils::cargo_home() {
302313
cmd.env("CARGO_HOME", &cargo_home);
314+
println!("CCC {}", cargo_home.display());
303315
}
304316

305317
env_var::inc("RUST_RECURSION_COUNT", cmd);
306318

307319
cmd.env("RUSTUP_TOOLCHAIN", &self.name);
308320
cmd.env("RUSTUP_HOME", &self.cfg.multirust_dir);
321+
println!("RUH {}", self.cfg.multirust_dir.display());
309322
}
310323

311324
pub fn set_ldpath(&self, cmd: &mut Command) {

tests/cli-rustup.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,10 @@ fn fallback_cargo_calls_correct_rustc() {
283283
let ref cargo_bin_path = config.cargodir.join("bin");
284284
fs::create_dir_all(cargo_bin_path).unwrap();
285285
let ref rustc_path = cargo_bin_path.join(format!("rustc{}", EXE_SUFFIX));
286-
fs::hard_link(rustup_path, rustc_path).unwrap();
286+
//fs::hard_link(rustup_path, rustc_path).unwrap();
287+
let ref rustcc_path = cargo_bin_path.join(format!("rustcc{}", EXE_SUFFIX));
288+
fs::hard_link(rustup_path, rustcc_path).unwrap();
289+
fs::rename(rustcc_path, rustc_path).unwrap();
287290

288291
// Install a custom toolchain and a nightly toolchain for the cargo fallback
289292
let path = config.customdir.join("custom-1");
@@ -295,12 +298,16 @@ fn fallback_cargo_calls_correct_rustc() {
295298
expect_stdout_ok(config, &["rustc", "--version"],
296299
"hash-c-1");
297300

301+
//assert!(rustc_path.exists());
302+
println!("SRCHAU {}", rustup_path.display());
303+
298304
// Here --call-rustc tells the mock cargo bin to exec `rustc --version`.
299305
// We should be ultimately calling the custom rustc, according to the
300306
// RUSTUP_TOOLCHAIN variable set by the original "cargo" proxy, and
301307
// interpreted by the nested "rustc" proxy.
302308
expect_stdout_ok(config, &["cargo", "--call-rustc"],
303-
"hash-c-1");
309+
"hash-n-2" /* "hash-c-1" */);
310+
::std::process::exit(-1);
304311
});
305312
}
306313

0 commit comments

Comments
 (0)