-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix verbatim paths used with include!
When using `concat!` to join paths, the Unix path separator (`/`) is often used. This breaks on Windows if the base path is a verbatim path (i.e. starts with `\\?\`).
- Loading branch information
1 parent
83dcdb3
commit edc97a0
Showing
4 changed files
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
static TEST: &str = "Hello World!"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//@ only-windows other platforms do not have Windows verbatim paths | ||
use run_make_support::rustc; | ||
fn main() { | ||
// Canonicalizing the path ensures that it's verbatim (i.e. starts with `\\?\`) | ||
let mut path = std::fs::canonicalize(file!()).unwrap(); | ||
path.pop(); | ||
rustc().input("verbatim.rs").env("VERBATIM_DIR", path).run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//! Include a file by concating the verbatim path using `/` instead of `\` | ||
include!(concat!(env!("VERBATIM_DIR"), "/include/include.txt")); | ||
fn main() { | ||
assert_eq!(TEST, "Hello World!"); | ||
|
||
let s = include_str!(concat!(env!("VERBATIM_DIR"), "/include/include.txt")); | ||
assert_eq!(s, "static TEST: &str = \"Hello World!\";\n"); | ||
|
||
let b = include_bytes!(concat!(env!("VERBATIM_DIR"), "/include/include.txt")); | ||
assert_eq!(b, b"static TEST: &str = \"Hello World!\";\n"); | ||
} |