From 293e6c88e85602d155ddbcf154a59675efe95a6c Mon Sep 17 00:00:00 2001 From: Katasonov Vladyslav Date: Tue, 4 Jun 2019 23:08:01 +0300 Subject: [PATCH 1/2] 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) From c0c11394c402e38c5d7cd908d1a7ebddfc322103 Mon Sep 17 00:00:00 2001 From: Katasonov Vladyslav Date: Tue, 4 Jun 2019 23:57:26 +0300 Subject: [PATCH 2/2] Run rustfmt. --- components/script_plugins/webidl_must_inherit.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/components/script_plugins/webidl_must_inherit.rs b/components/script_plugins/webidl_must_inherit.rs index f853211d0f2..7d51b7f10f7 100644 --- a/components/script_plugins/webidl_must_inherit.rs +++ b/components/script_plugins/webidl_must_inherit.rs @@ -73,12 +73,14 @@ fn get_manifest_dir() -> io::Result { 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")) - }, + 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", + )), } }