Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libterm: synchronize with public "term" crate v0.4.0 #31205

Closed
wants to merge 5 commits into from

Conversation

erickt
Copy link
Contributor

@erickt erickt commented Jan 26, 2016

The largest impact is that the public "term" crate now has it's own term::Error type. Most of the changes are propagating this type through the other crates.

I also had a minor extraction of a subset of the "winapi" and "kernel32" crates.

cc @cmr, who made the original change to term.

@rust-highfive
Copy link
Collaborator

r? @aturon

(rust_highfive has picked a reviewer for you, use r? to override)

@erickt
Copy link
Contributor Author

erickt commented Jan 26, 2016

I mainly want this so I can update syntex to use the latest term crate :) Keep a close eye on the Windows code. I wasn't able to test it out on my Mac.

@Stebalien
Copy link
Contributor

FYI, in terminfo/searcher.rs:

  1. get_dbpath_for_term probably doesn't need #[allow(deprecated)].
  2. The test case (test_get_dbpath_for_term) is outdated, broken, disabled, and should probably be removed.

@Stebalien
Copy link
Contributor

Otherwise, LGTM.

@erickt
Copy link
Contributor Author

erickt commented Jan 26, 2016

@Stebalien: Good point. I made both of your suggested changes in the latest patch.

@bors
Copy link
Contributor

bors commented Jan 27, 2016

☔ The latest upstream changes (presumably #31120) made this pull request unmergeable. Please resolve the merge conflicts.

@aturon
Copy link
Member

aturon commented Jan 27, 2016

Hm, I'm marked as reviewer but know nothing about this crate. @alexcrichton, do you know of a good person to r? here?

@alexcrichton
Copy link
Member

Yes I can take a look

@alexcrichton alexcrichton assigned alexcrichton and unassigned aturon Jan 27, 2016
fn from(err: term::Error) -> Self {
Error::Term(err)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems pretty unfortunate, shouldn't a term::Error be convertible into a io::Error?

This same duplication seems to happen in libtest which is what makes me wary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought about that. I initially started by just adding:

impl From<term::Error> for io::Error {
    fn from(err: term::Error) -> io::Error {
        match err {
            term::Io(err) => err,
            err => io::Error::new(io::ErrorKind::Other, err),
        }
    }
}

But I decided against that because it seems a shame that we're giving up the flexibility to do sensible things with the term errors, and making it slightly harder to add in custom emitter and libtest errors in the future. There's a side of me that just wants us to not get into the habit of stuffing things into error types like io::Error. It probably doesn't really matter much in this case since these uses are internal to the compiler, but I'm trying to be a good role model :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of integration with libsyntax/libtest, however, it seems pretty onerous to always require a shim like this (or to merge any two libraries together)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it does get a bit obnoxious to setup the first time, and if we never take advantage of it, it does get a bit silly. I'm fine either way, assuming if we add this impl to term it's fine with @Stebalien.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I'd prefer the following so we don't loose any information:

impl From<term::Error> for io::Error {
    fn from(err: term::Error) -> io::Error {
        let kind = match &err {
            &term::Error::Io(ref e) => e.kind(),
            _ => ErrorKind::Other,
        };
        io::Error::new(kind, err)
    }
}

This way, we keep the fact that this IO error was caused by a term error.

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me!

@bors
Copy link
Contributor

bors commented Jan 29, 2016

☔ The latest upstream changes (presumably #30411) made this pull request unmergeable. Please resolve the merge conflicts.

@alexcrichton
Copy link
Member

If we get a conversion of term::Error -> io::Error then this all looks good to me, thanks @erickt!

@Stebalien
Copy link
Contributor

@alexcrichton done in term 0.4.1.

@alexcrichton
Copy link
Member

Note that @pnkfelix found a bug in what appears to be term when cargo itself upgraded, prompting a downgrade back to 0.2.

Along those lines we may want to be hesitant about aggressively updating to new code? @Stebalien could you speak to some of the bigger changes made between term 0.2 and 0.4?

@Stebalien
Copy link
Contributor

@alexcrichton term used to return Ok(true) if something succeeded, Ok(false) if the operation was unsupported, and Err(io::Error) if there was an IO error. Now, it returns Ok(()) if the operation succeeds and Err(term::Error) if the operation fails. If the operation is unsupported, it returns Err(term::Error::NotSupported). I'm adding a supports_color() function that will allow crates to determine if the terminal supports color/reset up front. See Stebalien/term#56.

@Stebalien
Copy link
Contributor

After Stebalien/term#56 is merged, the fix here would be to check if color is supported in syntax::errors::emitter::Destination::from_stderr.

@Stebalien
Copy link
Contributor

I apologize for not catching this when initially reviewing this patch, I completely forgot about this change. Thanks @pnkfelix for noticing this.

@alexcrichton
Copy link
Member

Ok, thanks for the summary @Stebalien! @erickt it looks like there's going to need to be some changes in that case? e.g. if we call methods like reset() we'll need a guard to see whether the terminal supports it at all

@pnkfelix
Copy link
Member

pnkfelix commented Feb 1, 2016

I'm sort of surprised that I was seeing the behavior that I was observing given that the API change described was something where unsupported operations now lead to Err -- in particular, why was I still seeing a zero exit code in that case? (Update: I accidentally wrote "non-zero" in the first version of this comment.)

This is what I mean (from rust-lang/cargo#2338 (comment) ):

% /Users/fklock/.multirust/toolchains/nightly-2016-01-27/bin/cargo --version
% echo $?
0

this is the scenario where cargo --version was running under a terminal environment that is not as full-featured (presumably emacs M-x shell said it did not support color?). But why was cargo exiting with exit code zero in this scenario?

@Stebalien
Copy link
Contributor

@pnkfelix it's probably just ignoring the errors as unimportant (printing to the screen is not critical) For example, the following would say nothing:

fn say_something(&self)  -> Result {
    try!(self.term.reset());
    write!(term, "something");
}

fn do_something_important() {
    let _ = sayer.say_something();
}

@erickt
Copy link
Contributor Author

erickt commented Feb 5, 2016

@Stebalien / @alexcrichton: I've updated my patch to sync with term v0.4.4, and got rid of the custom Error implementations. Rust built for me, but this patch is still untested on windows.

@Stebalien
Copy link
Contributor

See #31205 (comment).

You need to check if the terminal supports color.

Steven Allen

@alexcrichton
Copy link
Member

Looks good to me modulo what @Stebalien mentioned

The only point of divergence from the public crate is that this
patch uses `std::sys::windows` instead of the `winapi` and
`kernel32` crate to access the Windows Console APIs.
@erickt
Copy link
Contributor Author

erickt commented Feb 17, 2016

@Stebalien: This PR should now be synced with term, modulo the clippy work you did in the repo. Does that address your comment about checking the terminal if it supports color?

@Stebalien
Copy link
Contributor

Not quite. You need to actually check for color support in syntax::errors::emitter::Destination::from_stderr. See Stebalien/cargo@cfcfa08 for how I did this in cargo.

@erickt
Copy link
Contributor Author

erickt commented Feb 18, 2016

@Stebalien: I added a patch that I think implements the check you were looking for. How does it look?

Raw(Box::new(io::stderr()))
}
}
None => Raw(Box::new(io::stderr())),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@alexcrichton
Copy link
Member

@bors: r+ 388cf4e

@bors
Copy link
Contributor

bors commented Feb 18, 2016

⌛ Testing commit 388cf4e with merge c8c296a...

@bors
Copy link
Contributor

bors commented Feb 18, 2016

💔 Test failed - auto-win-gnu-32-nopt-t

use std::io::prelude::*;
use std::io;
use std::ptr;
use std::sys::windows::c as kernel32;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this stuff casued the build failure

../src/libterm\win.rs:18:5: 18:37 error: unresolved import `std::sys::windows::c`. Could not find `windows` in `std::sys` [E0432]

@bors
Copy link
Contributor

bors commented Mar 23, 2016

☔ The latest upstream changes (presumably #32390) made this pull request unmergeable. Please resolve the merge conflicts.

@alexcrichton
Copy link
Member

Closing due to inactivity, but seems good to merge with a rebase and test fixes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants