From 6ecc7772d452fe89d1cd5aceddfc95408eed2ac9 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Fri, 11 May 2018 11:00:06 -0700 Subject: [PATCH] Don't include tests and AFL seeds in distributed package Fixes #139 --- Cargo.toml | 1 + build.rs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 391a1ff..96aff08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ build = "build.rs" categories = ["development-tools::debugging", "development-tools::ffi"] description = "A crate for demangling C++ symbols" documentation = "https://docs.rs/cpp_demangle" +exclude = ["tests/**", "in/**"] keywords = ["demangle", "symbolicate", "c-plus-plus", "itanium"] license = "Apache-2.0/MIT" name = "cpp_demangle" diff --git a/build.rs b/build.rs index 3658ef0..3be8172 100644 --- a/build.rs +++ b/build.rs @@ -60,7 +60,11 @@ use std::io::Read; let mut in_dir = get_crate_dir()?; in_dir.push("in"); - assert!(in_dir.is_dir()); + if !in_dir.is_dir() { + // We are in `cargo publish` and the `in/` directory isn't included in + // the distributed package. + return Ok(()); + } let entries = fs::read_dir(in_dir)?; @@ -104,6 +108,14 @@ fn test_afl_seed_{}() {{ fn generate_compatibility_tests_from_libiberty() -> io::Result<()> { println!("cargo:rerun-if-changed=tests/libiberty-demangle-expected"); + let mut tests_dir = get_crate_dir()?; + tests_dir.push("tests"); + if !tests_dir.is_dir() { + // We are in `cargo publish` and the `in/` directory isn't included in + // the distributed package. + return Ok(()); + } + let test_path = get_test_path("libiberty.rs")?; let _ = fs::remove_file(&test_path); let mut test_file = fs::File::create(test_path)?;