]> git.proxmox.com Git - cargo.git/commitdiff
Be compatible with the stdlib for now ('static shell)
authorAlex Crichton <alex@alexcrichton.com>
Fri, 29 Aug 2014 19:00:15 +0000 (12:00 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 29 Aug 2014 19:00:15 +0000 (12:00 -0700)
src/cargo/core/shell.rs
src/cargo/lib.rs
src/cargo/ops/cargo_compile.rs
src/cargo/util/config.rs
tests/test_cargo_cross_compile.rs
tests/test_shell.rs

index 9c741e1ab1ff477191871531ae38f85a207f907e..4778929a1981deb6a18b6cc49eb962fc5c5c6c10 100644 (file)
@@ -10,34 +10,34 @@ pub struct ShellConfig {
     pub tty: bool
 }
 
-enum AdequateTerminal<'a> {
-    NoColor(Box<Writer+'a>),
-    Color(Box<Terminal<Box<Writer+'a>>+'a>)
+enum AdequateTerminal {
+    NoColor(Box<Writer+'static>),
+    Color(Box<Terminal<Box<Writer+'static>>+'static>)
 }
 
-pub struct Shell<'a> {
-    terminal: AdequateTerminal<'a>,
+pub struct Shell {
+    terminal: AdequateTerminal,
     config: ShellConfig
 }
 
-pub struct MultiShell<'a> {
-    out: Shell<'a>,
-    err: Shell<'a>,
+pub struct MultiShell {
+    out: Shell,
+    err: Shell,
     verbose: bool
 }
 
 pub type Callback<'a> = |&mut MultiShell|:'a -> IoResult<()>;
 
-impl<'a> MultiShell<'a> {
-    pub fn new(out: Shell<'a>, err: Shell<'a>, verbose: bool) -> MultiShell<'a> {
+impl MultiShell {
+    pub fn new(out: Shell, err: Shell, verbose: bool) -> MultiShell {
         MultiShell { out: out, err: err, verbose: verbose }
     }
 
-    pub fn out(&mut self) -> &mut Shell<'a> {
+    pub fn out(&mut self) -> &mut Shell {
         &mut self.out
     }
 
-    pub fn err(&mut self) -> &mut Shell<'a> {
+    pub fn err(&mut self) -> &mut Shell {
         &mut self.err
     }
 
@@ -72,17 +72,17 @@ impl<'a> MultiShell<'a> {
     }
 }
 
-pub type ShellCallback<'a> = |&mut Shell<'a>|:'a -> IoResult<()>;
+pub type ShellCallback<'a> = |&mut Shell|:'a -> IoResult<()>;
 
-impl<'a> Shell<'a> {
-    pub fn create(out: Box<Writer+'a>, config: ShellConfig) -> Shell<'a> {
+impl Shell {
+    pub fn create(out: Box<Writer+'static>, config: ShellConfig) -> Shell {
         if config.tty && config.color {
-            let term: Option<term::TerminfoTerminal<Box<Writer+'a>>> = Terminal::new(out);
+            let term: Option<term::TerminfoTerminal<Box<Writer+'static>>> = Terminal::new(out);
             term.map(|t| Shell {
-                terminal: Color(box t as Box<Terminal<Box<Writer+'a>>>),
+                terminal: Color(box t as Box<Terminal<Box<Writer+'static>>>),
                 config: config
             }).unwrap_or_else(|| {
-                Shell { terminal: NoColor(box stderr() as Box<Writer+'a>), config: config }
+                Shell { terminal: NoColor(box stderr() as Box<Writer+'static>), config: config }
             })
         } else {
             Shell { terminal: NoColor(out), config: config }
@@ -121,8 +121,8 @@ impl<'a> Shell<'a> {
     }
 }
 
-impl<'a> Terminal<Box<Writer+'a>> for Shell<'a> {
-    fn new(out: Box<Writer+'a>) -> Option<Shell<'a>> {
+impl Terminal<Box<Writer+'static>> for Shell {
+    fn new(out: Box<Writer+'static>) -> Option<Shell> {
         Some(Shell {
             terminal: NoColor(out),
             config: ShellConfig {
@@ -168,18 +168,18 @@ impl<'a> Terminal<Box<Writer+'a>> for Shell<'a> {
         }
     }
 
-    fn unwrap(self) -> Box<Writer+'a> {
+    fn unwrap(self) -> Box<Writer+'static> {
         fail!("Can't unwrap a Shell");
     }
 
-    fn get_ref<'b>(&'b self) -> &'b Box<Writer+'a> {
+    fn get_ref<'b>(&'b self) -> &'b Box<Writer+'static> {
         match self.terminal {
             Color(ref c) => c.get_ref(),
             NoColor(ref w) => w
         }
     }
 
-    fn get_mut<'b>(&'b mut self) -> &'b mut Box<Writer+'a> {
+    fn get_mut<'b>(&'b mut self) -> &'b mut Box<Writer+'static> {
         match self.terminal {
             Color(ref mut c) => c.get_mut(),
             NoColor(ref mut w) => w
@@ -187,7 +187,7 @@ impl<'a> Terminal<Box<Writer+'a>> for Shell<'a> {
     }
 }
 
-impl<'a> Writer for Shell<'a> {
+impl Writer for Shell {
     fn write(&mut self, buf: &[u8]) -> IoResult<()> {
         match self.terminal {
             Color(ref mut c) => c.write(buf),
index f01277bb4bfc3d2210ea13c67957e8bc11b6be62..8144eb39666a24dd5b364f5138b055558d8822e8 100644 (file)
@@ -150,7 +150,7 @@ pub fn process_executed<'a,
     }
 }
 
-pub fn shell(verbose: bool) -> MultiShell<'static> {
+pub fn shell(verbose: bool) -> MultiShell {
     let tty = stderr_raw().isatty();
     let stderr = box stderr() as Box<Writer>;
 
index 23b0cf12f889e2d3a219ea0809ea6461a3ea533f..8b686af2d75badee6ce07f0d8e72dc6081c32f3b 100644 (file)
@@ -36,7 +36,7 @@ use util::{CargoResult, Wrap, config, internal, human, ChainError, profile};
 pub struct CompileOptions<'a> {
     pub update: bool,
     pub env: &'a str,
-    pub shell: &'a mut MultiShell<'a>,
+    pub shell: &'a mut MultiShell,
     pub jobs: Option<uint>,
     pub target: Option<&'a str>,
     pub dev_deps: bool,
index 01e54438370293209c8731fe88626d48e194984a..6e03115ac6bc01496f0c2cd48614742aed28d680 100644 (file)
@@ -9,7 +9,7 @@ use util::toml as cargo_toml;
 
 pub struct Config<'a> {
     home_path: Path,
-    shell: &'a mut MultiShell<'a>,
+    shell: &'a mut MultiShell,
     jobs: uint,
     target: Option<String>,
     linker: Option<String>,
index 7e65190d186779f1fb21ab486929563606a52d4e..35b702a823955efdcce8f27726f4e32f705631cb 100644 (file)
@@ -163,7 +163,7 @@ test!(plugin_deps {
             }
 
             fn expand_bar(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
-                          -> Box<MacResult> {
+                          -> Box<MacResult + 'static> {
                 MacExpr::new(quote_expr!(cx, 1i))
             }
         "#);
@@ -245,7 +245,7 @@ test!(plugin_to_the_max {
             }
 
             fn expand_bar(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
-                          -> Box<MacResult> {
+                          -> Box<MacResult + 'static> {
                 MacExpr::new(quote_expr!(cx, baz::baz()))
             }
         "#);
index d1211ab2bacbe54109c6ea1b6ffda92cce0fe2dd..f0da10669f1d3cbf68a65e6004dec6dd68688383 100644 (file)
@@ -1,50 +1,55 @@
-use support::{ResultTest,Tap,shell_writes};
+use std::io::{MemWriter, IoResult, ChanReader, ChanWriter};
+
+use term::{Terminal, TerminfoTerminal, color};
 use hamcrest::{assert_that};
-use std::io::{MemWriter, BufWriter, IoResult};
+
+use support::{ResultTest, Tap, shell_writes};
 use cargo::core::shell::{Shell,ShellConfig};
-use term::{Terminal,TerminfoTerminal,color};
 
 fn setup() {
 }
 
-fn writer(buf: &mut [u8]) -> Box<Writer> {
-    box BufWriter::new(buf) as Box<Writer>
+fn io_channel() -> (Box<Writer + 'static>, Box<Reader + 'static>) {
+    let (tx, rx) = channel();
+    (box ChanWriter::new(tx), box ChanReader::new(rx))
 }
 
 test!(non_tty {
     let config = ShellConfig { color: true, verbose: true, tty: false };
-    let mut buf: Vec<u8> = Vec::from_elem(9, 0 as u8);
+    let (tx, mut rx) = io_channel();
 
-    Shell::create(writer(buf.as_mut_slice()), config).tap(|shell| {
+    Shell::create(tx, config).tap(|shell| {
         shell.say("Hey Alex", color::RED).assert();
-        assert_that(buf.as_slice(), shell_writes("Hey Alex\n"));
     });
+    assert_that(rx.read_to_end().unwrap().as_slice(),
+                shell_writes("Hey Alex\n"));
 })
 
 test!(color_explicitly_disabled {
     let config = ShellConfig { color: false, verbose: true, tty: true };
-    let mut buf: Vec<u8> = Vec::from_elem(9, 0 as u8);
+    let (tx, mut rx) = io_channel();
 
-    Shell::create(writer(buf.as_mut_slice()), config).tap(|shell| {
+    Shell::create(tx, config).tap(|shell| {
         shell.say("Hey Alex", color::RED).assert();
-        assert_that(buf.as_slice(), shell_writes("Hey Alex\n"));
     });
+    assert_that(rx.read_to_end().unwrap().as_slice(),
+                shell_writes("Hey Alex\n"));
 })
 
 test!(colored_shell {
     let term: Option<TerminfoTerminal<MemWriter>> =
         Terminal::new(MemWriter::new());
     if term.is_none() { return }
+    let (tx, mut rx) = io_channel();
 
     let config = ShellConfig { color: true, verbose: true, tty: true };
-    let mut buf: Vec<u8> = Vec::from_elem(100, 0 as u8);
 
-    Shell::create(writer(buf.as_mut_slice()), config).tap(|shell| {
+    Shell::create(tx, config).tap(|shell| {
         shell.say("Hey Alex", color::RED).assert();
-        let buf = buf.as_slice().slice_to(buf.iter().position(|a| *a == 0).unwrap());
-        assert_that(buf, shell_writes(colored_output("Hey Alex\n",
-                                                     color::RED).assert()));
     });
+    assert_that(rx.read_to_end().unwrap().as_slice(),
+                shell_writes(colored_output("Hey Alex\n",
+                                            color::RED).assert()));
 })
 
 fn colored_output<S: Str>(string: S, color: color::Color) -> IoResult<String> {