Emit crate_root with forward slashes on Windows#200
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
| package_root_path_str = package_root_path_str.split_off(2); | ||
| } | ||
|
|
||
| // Bazel wants forward slashes, but some operating systems don't use '/' as the path |
There was a problem hiding this comment.
Maybe a better fix for this would be to change line 750 to not turn the path into a string, call
let package_root_path = target.src_path
.strip_prefix(&package_root_path())
.components()
.map(|c| { c.as_os_str().to_string().expect(format!("Fatal: {:?} has non-UTF-8 characters in it.", c.as_os_str()) })
.collect::<Vec<String>>()
.join("/")
This
- Obviates the TODO
- Obviates 769-771, as components skips . and path separators
- Calling to_string_lossy on Paths (which are internally sequences of things built on OsString) because you want to write them in a config file so they can be reliably read by another tool is not generally correct. While unconventional, it's legal in Linux to have non-UTF-8 filenames. If we encounter one, it's better to fail fast in this tool rather than letting than rustc failing with file not found on a path name in the config file that might be visually indistinguishable from the actual path on disk. Not that Bazel can even do well with all legal paths containing only UTF-8 either... Spaces anyone?
There was a problem hiding this comment.
I generally like the approach. Are you able to to return an error from the function instead of panicking?
There was a problem hiding this comment.
We'd have to change the Result type of this function, as the Error is no longer io::Error, but it's the standard "crate-level Error with a bunch of Variants for all the errors this crate can encounter with a bunch of impl From trait pattern."
I'll have to do something more clever than collect now that I have Vec<Result<String, Error>> rather than Vec coming out of the map statement.
|
@googlebot I signed it! |
dfreese
left a comment
There was a problem hiding this comment.
Thanks. A small comment in the implementation. Could you also add a unit test to cover the case you were running into?
Then I'm good with this.
|
This is in v0.3.9. |
Adds an additional error for non-unicode paths, which was previously a TODO in terms of handling. google#178 provided a similar solution.
Windows was emitting bazel paths with back slashes for
crate_entryattrs because we callpath.to_string_lossy. Fix that.