From 3891cd638af5b11244164cdf268003f4b73d930f Mon Sep 17 00:00:00 2001 From: Navid Date: Wed, 24 Oct 2018 15:56:23 +0330 Subject: [PATCH] Fix issues related to package the crate --- .gitignore | 1 - Makefile | 9 ++------- build.rs | 20 +++++++------------- src/bindings.rs | 6 ++++++ src/lib.rs | 6 +++--- tests/lib_test.rs | 1 + 6 files changed, 19 insertions(+), 24 deletions(-) create mode 100644 src/bindings.rs diff --git a/.gitignore b/.gitignore index 0a2a5ae..e36aac4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ **/*.rs.bk Cargo.lock /libinjection -src/bindings.rs diff --git a/Makefile b/Makefile index 4916153..cf3fe4d 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,4 @@ -clean: - rm -rf libinjection - rm -f src/bindings.rs - cargo clean - fix-python: - sed -i 's/python$$/python2/g' libinjection/src/*.py + sed -i 's/python$$/python2/g' $(OUT_DIR)/libinjection/src/*.py -.PHONY: clean fix-python +.PHONY: fix-python diff --git a/build.rs b/build.rs index 3baa972..f0143b4 100644 --- a/build.rs +++ b/build.rs @@ -5,18 +5,14 @@ extern crate regex; use git2::Repository; use regex::Regex; use std::env; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::process::Command; const LIBINJECTION_URL: &'static str = "https://github.com/client9/libinjection"; const BUILD_DIR_NAME: &'static str = "libinjection"; fn clone_libinjection(build_dir: &Path, version: &str) -> Option<()> { - let repo = if build_dir.exists() { - Repository::open(build_dir).ok()? - } else { - Repository::clone(LIBINJECTION_URL, build_dir).ok()? - }; + let repo = Repository::clone(LIBINJECTION_URL, build_dir).ok()?; let rev = repo.revparse_single(version).ok()?; repo.set_head_detached(rev.id()).ok() } @@ -24,6 +20,7 @@ fn clone_libinjection(build_dir: &Path, version: &str) -> Option<()> { fn run_make(rule: &str, cwd: &Path) -> Option { let output = Command::new("make") .arg(rule) + .env("OUT_DIR", env::var("OUT_DIR").unwrap()) .current_dir(cwd) .output() .ok()?; @@ -50,8 +47,8 @@ fn fix_python_version() -> Option<()> { } fn main() { - let mut build_parent_dir = env::current_dir().unwrap(); - build_parent_dir.push(BUILD_DIR_NAME); + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + let mut build_parent_dir = out_path.join(BUILD_DIR_NAME); if clone_libinjection(build_parent_dir.as_path(), "v3.10.0").is_none() { panic!("unable to clone libinjection"); @@ -79,10 +76,7 @@ fn main() { .generate() .expect("Unable to generate bindings"); - let mut out_path = env::current_dir().unwrap(); - out_path.push("src"); - out_path.push("bindings.rs"); bindings - .write_to_file(out_path) - .expect("Couldn't write bindings!"); + .write_to_file(out_path.join("bindings.rs")) + .expect("unable to write bindings"); } diff --git a/src/bindings.rs b/src/bindings.rs new file mode 100644 index 0000000..cd503e4 --- /dev/null +++ b/src/bindings.rs @@ -0,0 +1,6 @@ +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(dead_code)] + +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); diff --git a/src/lib.rs b/src/lib.rs index 2001020..e6022d5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,14 +8,14 @@ //! //! ``` //! extern crate libinjection; -//! +//! //! use libinjection::{sqli, xss}; -//! +//! //! fn main() { //! let (is_sqli, fingerprint) = sqli("' OR '1'='1' --").unwrap(); //! assert!(is_sqli); //! assert_eq!("s&sos", fingerprint); -//! +//! //! let is_xss = xss("").unwrap(); //! assert!(is_xss); //! } diff --git a/tests/lib_test.rs b/tests/lib_test.rs index d067caf..7f593b1 100644 --- a/tests/lib_test.rs +++ b/tests/lib_test.rs @@ -13,6 +13,7 @@ fn test_sqli() { assert!(fingerprint.is_empty()); } +#[test] fn test_xss() { let is_xss = xss("").unwrap(); assert!(is_xss);