From 293e6c88e85602d155ddbcf154a59675efe95a6c Mon Sep 17 00:00:00 2001 From: Katasonov Vladyslav Date: Tue, 4 Jun 2019 23:08:01 +0300 Subject: [PATCH] Made webidl search path relative to manifest. Manifest dir should be more stable than current dir. --- .../script_plugins/webidl_must_inherit.rs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/components/script_plugins/webidl_must_inherit.rs b/components/script_plugins/webidl_must_inherit.rs index ce6ed841217..f853211d0f2 100644 --- a/components/script_plugins/webidl_must_inherit.rs +++ b/components/script_plugins/webidl_must_inherit.rs @@ -66,9 +66,25 @@ fn get_ty_name(ty: &str) -> &str { } } +fn get_manifest_dir() -> io::Result { + match env::var("CARGO_MANIFEST_DIR") { + Ok(var) => { + let mut dir = path::PathBuf::new(); + dir.push(var); + Ok(dir) + }, + Err(env::VarError::NotPresent) => { + Err(io::Error::new(io::ErrorKind::NotFound, "CARGO_MANIFEST_DIR environment variable was not found")) + }, + Err(env::VarError::NotUnicode(_)) => { + Err(io::Error::new(io::ErrorKind::InvalidData, "CARGO_MANIFEST_DIR environment variable's contents are non valid UTF-8")) + }, + } +} + fn get_webidl_path(struct_name: &str) -> io::Result { - let mut dir = env::current_dir()?; - dir.push("components/script/dom/webidls/"); + let mut dir = get_manifest_dir()?; + dir.push("dom/webidls/"); dir.push(format!("{}.webidl", struct_name)); Ok(dir)