mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Copy all generated files to dist dir for packaging.
This commit is contained in:
parent
10b7001dd1
commit
ff76ec8d2f
1 changed files with 27 additions and 17 deletions
|
@ -3,12 +3,26 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
mod common {
|
mod common {
|
||||||
use std::env;
|
use std::{env, fs, io};
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref OUTDIR_PATH: PathBuf = PathBuf::from(env::var("OUT_DIR").unwrap()).join("gecko");
|
pub static ref OUTDIR_PATH: PathBuf = PathBuf::from(env::var("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")]
|
#[cfg(feature = "bindgen")]
|
||||||
|
@ -62,11 +76,6 @@ mod bindings {
|
||||||
pub static ref LAST_MODIFIED: Mutex<SystemTime> =
|
pub static ref LAST_MODIFIED: Mutex<SystemTime> =
|
||||||
Mutex::new(get_modified_time(&env::current_exe().unwrap())
|
Mutex::new(get_modified_time(&env::current_exe().unwrap())
|
||||||
.expect("Failed to get modified time of executable"));
|
.expect("Failed to get modified time of executable"));
|
||||||
static ref BINDING_DISTDIR_PATH: PathBuf = {
|
|
||||||
let path = DISTDIR_PATH.join("rust_bindings/style");
|
|
||||||
fs::create_dir_all(&path).expect("Fail to create bindings dir in dist");
|
|
||||||
path
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_modified_time(file: &Path) -> Option<SystemTime> {
|
fn get_modified_time(file: &Path) -> Option<SystemTime> {
|
||||||
|
@ -239,8 +248,6 @@ mod bindings {
|
||||||
}
|
}
|
||||||
let bytes = result.into_bytes();
|
let bytes = result.into_bytes();
|
||||||
File::create(&out_file).unwrap().write_all(&bytes).expect("Unable to write output");
|
File::create(&out_file).unwrap().write_all(&bytes).expect("Unable to write output");
|
||||||
File::create(&BINDING_DISTDIR_PATH.join(file)).unwrap()
|
|
||||||
.write_all(&bytes).expect("Unable to write output to binding dist");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_arc_types() -> Vec<String> {
|
fn get_arc_types() -> Vec<String> {
|
||||||
|
@ -850,25 +857,28 @@ mod bindings {
|
||||||
generate_bindings(),
|
generate_bindings(),
|
||||||
generate_atoms(),
|
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"))]
|
#[cfg(not(feature = "bindgen"))]
|
||||||
mod bindings {
|
mod bindings {
|
||||||
use std::fs;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use super::common::*;
|
use super::common::*;
|
||||||
|
|
||||||
pub fn generate() {
|
pub fn generate() {
|
||||||
let dir = Path::new(file!()).parent().unwrap().join("gecko/generated");
|
let dir = Path::new(file!()).parent().unwrap().join("gecko/generated");
|
||||||
println!("cargo:rerun-if-changed={}", dir.display());
|
println!("cargo:rerun-if-changed={}", dir.display());
|
||||||
let entries = dir.read_dir().expect("Fail to list the generated directory");
|
copy_dir(&dir, &*OUTDIR_PATH, |path| {
|
||||||
for entry in entries {
|
println!("cargo:rerun-if-changed={}", path.display());
|
||||||
let entry = entry.expect("Fail to get dir entry");
|
}).expect("Fail to copy generated files to out dir");
|
||||||
println!("cargo:rerun-if-changed={}", entry.path().display());
|
|
||||||
fs::copy(entry.path(), OUTDIR_PATH.join(entry.file_name()))
|
|
||||||
.expect("Fail to copy the file");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue