Bug 1455623 part 2 - Not copy generated binding files into dist. r=emilio

MozReview-Commit-ID: GBnkmwjDS8Y

--HG--
extra : rebase_source : 247500457a1f1779ed8a3fd7d43d546e48980e9a
This commit is contained in:
Xidorn Quan 2018-04-21 00:38:08 +10:00
Родитель 804bbb9b67
Коммит f3bd200b24
1 изменённых файлов: 22 добавлений и 30 удалений

Просмотреть файл

@ -3,31 +3,13 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
mod common {
use std::{env, fs, io};
use std::path::{Path, PathBuf};
use std::env;
use std::path::PathBuf;
lazy_static! {
pub static ref OUTDIR_PATH: PathBuf =
PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("gecko");
}
/// Copy contents of one directory into another.
/// It currently only does a shallow copy.
pub fn copy_dir<P, Q, F>(from: P, to: Q, callback: F) -> io::Result<()>
where
P: AsRef<Path>,
Q: AsRef<Path>,
F: Fn(&Path),
{
let to = to.as_ref();
for entry in from.as_ref().read_dir()? {
let entry = entry?;
let path = entry.path();
callback(&path);
fs::copy(&path, to.join(entry.file_name()))?;
}
Ok(())
}
}
#[cfg(feature = "bindgen")]
@ -613,23 +595,33 @@ mod bindings {
generate_bindings(),
generate_atoms(),
}
// Copy all generated files to dist for the binding package
let path = DISTDIR_PATH.join("rust_bindings/style");
if path.exists() {
fs::remove_dir_all(&path).expect("Fail to remove binding dir in dist");
}
fs::create_dir_all(&path).expect("Fail to create bindings dir in dist");
copy_dir(&*OUTDIR_PATH, &path, |_| {}).expect("Fail to copy generated files to dist dir");
}
}
#[cfg(not(feature = "bindgen"))]
mod bindings {
use std::env;
use std::path::PathBuf;
use std::{env, fs, io};
use std::path::{Path, PathBuf};
use super::common::*;
/// Copy contents of one directory into another.
/// It currently only does a shallow copy.
fn copy_dir<P, Q, F>(from: P, to: Q, callback: F) -> io::Result<()>
where
P: AsRef<Path>,
Q: AsRef<Path>,
F: Fn(&Path),
{
let to = to.as_ref();
for entry in from.as_ref().read_dir()? {
let entry = entry?;
let path = entry.path();
callback(&path);
fs::copy(&path, to.join(entry.file_name()))?;
}
Ok(())
}
pub fn generate() {
let dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()).join("gecko/generated");
println!("cargo:rerun-if-changed={}", dir.display());