|
| 1 | +use std::path::{Path, PathBuf}; |
| 2 | + |
1 | 3 | use proc_macro::TokenStream; |
2 | 4 | use syn::parse::{Error, Parse, ParseStream, Result}; |
3 | 5 | use syn::punctuated::Punctuated; |
@@ -28,11 +30,11 @@ fn run(input: TokenStream, dir: Direction) -> TokenStream { |
28 | 30 |
|
29 | 31 | // Include a dummy `include_str!` for any files we read so rustc knows that |
30 | 32 | // we depend on the contents of those files. |
31 | | - let cwd = std::env::current_dir().unwrap(); |
| 33 | + let cwd = std::env::var("CARGO_MANIFEST_DIR").unwrap(); |
32 | 34 | for file in input.files.iter() { |
33 | 35 | contents.push_str(&format!( |
34 | 36 | "const _: &str = include_str!(r#\"{}\"#);\n", |
35 | | - cwd.join(file).display() |
| 37 | + Path::new(&cwd).join(file).display() |
36 | 38 | )); |
37 | 39 | } |
38 | 40 |
|
@@ -82,7 +84,9 @@ impl Parse for Opts { |
82 | 84 | files.push(s.value()); |
83 | 85 | } |
84 | 86 | let mut interfaces = Vec::new(); |
| 87 | + let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); |
85 | 88 | for path in files.iter() { |
| 89 | + let path = manifest_dir.join(path); |
86 | 90 | let iface = Interface::parse_file(path).map_err(|e| Error::new(call_site, e))?; |
87 | 91 | interfaces.push(iface); |
88 | 92 | } |
@@ -123,7 +127,9 @@ impl Parse for ConfigField { |
123 | 127 | let paths = Punctuated::<syn::LitStr, Token![,]>::parse_terminated(&paths)?; |
124 | 128 | let values = paths.iter().map(|s| s.value()).collect::<Vec<_>>(); |
125 | 129 | let mut interfaces = Vec::new(); |
| 130 | + let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); |
126 | 131 | for value in &values { |
| 132 | + let value = manifest_dir.join(value); |
127 | 133 | let interface = |
128 | 134 | Interface::parse_file(value).map_err(|e| Error::new(bracket.span, e))?; |
129 | 135 | interfaces.push(interface); |
|
0 commit comments