From 8b794e29936443f1f4120cf0b6e084f34cc57534 Mon Sep 17 00:00:00 2001 From: Valentin NOEL Date: Tue, 10 Dec 2019 16:09:44 +0100 Subject: [PATCH 1/8] Add .travis.yml file --- .travis.yml | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5b649b8 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,56 @@ +language: rust + +rust: + - 1.35.0 + - 1.36.0 + - 1.37.0 + - 1.38.0 + - 1.39.0 + - stable + - beta + - nightly + +matrix: + allow_failures: + - rust: nightly + include: + # Rustfmt + - rust: stable + install: + - rustup component add rustfmt-preview + before_script: + - cargo fmt --version + script: + - cargo fmt -- --check + + # Clippy + - rust: stable + install: + - rustup component add clippy-preview + script: + # Fail if clippy output contains "error:" or "warning:" + - cargo clippy 2>&1 | tee ./clippy.out && ! grep -qe "error:\|warning:" ./clippy.out + + # Test coverage (with Tarpaulin) + - rust: stable + # To avoid "Error: EPERM: operation not permitted" error (see https://github.com/valery-barysok/session-file-store/issues/58) + sudo: true + install: + - RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install cargo-tarpaulin --force + script: + - cargo tarpaulin --ciserver travis-ci --coveralls $TRAVIS_JOB_ID + +script: + - gcc -c -Wall -Werror -fpic worker.cpp && gcc -shared -o libworker.so worker.o + - cargo test +cache: + cargo: true +before_cache: + # Travis can't cache files that are not readable by "others" + - chmod -R a+r $HOME/.cargo + +addons: + apt: + packages: + - libssl-dev # Required for tarpaulin + - gcc From 0f275af442f117c71e68d4a46d9d5daa30df7ddc Mon Sep 17 00:00:00 2001 From: Valentin NOEL Date: Tue, 10 Dec 2019 16:26:40 +0100 Subject: [PATCH 2/8] Display workspace content after building example worker --- .travis.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5b649b8..08d040e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: rust rust: - - 1.35.0 - 1.36.0 - 1.37.0 - 1.38.0 @@ -10,6 +9,9 @@ rust: - beta - nightly +env: + - WORKER_LIBRARY_FILE=/home/travis/build/media-cloud-ai/c_amqp_worker/libworker.so + matrix: allow_failures: - rust: nightly @@ -41,8 +43,8 @@ matrix: - cargo tarpaulin --ciserver travis-ci --coveralls $TRAVIS_JOB_ID script: - - gcc -c -Wall -Werror -fpic worker.cpp && gcc -shared -o libworker.so worker.o - - cargo test + - gcc -c -Wall -Werror -fpic worker.cpp && gcc -shared -o libworker.so worker.o && pwd && ls -l && echo $TRAVIS_BUILD_DIR + - ls -l && cargo test cache: cargo: true before_cache: From a1de53ddc9570d3886a4bd8d5f1b0db79f205eec Mon Sep 17 00:00:00 2001 From: Valentin NOEL Date: Tue, 10 Dec 2019 17:05:01 +0100 Subject: [PATCH 3/8] Travis: set worker library file environment variable and clean build script --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 08d040e..7938980 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ rust: - nightly env: - - WORKER_LIBRARY_FILE=/home/travis/build/media-cloud-ai/c_amqp_worker/libworker.so + - WORKER_LIBRARY_FILE=$TRAVIS_BUILD_DIR/libworker.so matrix: allow_failures: @@ -43,8 +43,8 @@ matrix: - cargo tarpaulin --ciserver travis-ci --coveralls $TRAVIS_JOB_ID script: - - gcc -c -Wall -Werror -fpic worker.cpp && gcc -shared -o libworker.so worker.o && pwd && ls -l && echo $TRAVIS_BUILD_DIR - - ls -l && cargo test + - gcc -c -Wall -Werror -fpic worker.cpp && gcc -shared -o libworker.so worker.o + - cargo test cache: cargo: true before_cache: From 9bfa6e0bf45261f016067cdfe30e421e1740bac6 Mon Sep 17 00:00:00 2001 From: Valentin NOEL Date: Tue, 10 Dec 2019 17:05:17 +0100 Subject: [PATCH 4/8] Fix clippy warnings --- src/main.rs | 10 ++++++---- src/worker.rs | 16 ++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 490f0e4..583dd00 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,10 +32,12 @@ impl MessageEvent for CWorkerEvent { fn get_version(&self) -> Version { let version = get_worker_function_string_value(GET_VERSION_FUNCTION); - Version::parse(&version).expect(&format!( - "unable to parse version {} (please use SemVer format)", - version - )) + Version::parse(&version).unwrap_or_else(|_| { + panic!( + "unable to parse version {} (please use SemVer format)", + version + ) + }) } fn get_git_version(&self) -> Version { diff --git a/src/worker.rs b/src/worker.rs index 10458d3..8761c81 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -55,13 +55,13 @@ type ProcessFunc = unsafe fn( type CheckLastError = extern "C" fn() -> c_int; -pub static GET_NAME_FUNCTION: &'static str = "get_name"; -pub static GET_SHORT_DESCRIPTION_FUNCTION: &'static str = "get_short_description"; -pub static GET_DESCRIPTION_FUNCTION: &'static str = "get_description"; -pub static GET_VERSION_FUNCTION: &'static str = "get_version"; -pub static GET_PARAMETERS_SIZE_FUNCTION: &'static str = "get_parameters_size"; -pub static GET_PARAMETERS_FUNCTION: &'static str = "get_parameters"; -pub static PROCESS_FUNCTION: &'static str = "process"; +pub static GET_NAME_FUNCTION: &str = "get_name"; +pub static GET_SHORT_DESCRIPTION_FUNCTION: &str = "get_short_description"; +pub static GET_DESCRIPTION_FUNCTION: &str = "get_description"; +pub static GET_VERSION_FUNCTION: &str = "get_version"; +pub static GET_PARAMETERS_SIZE_FUNCTION: &str = "get_parameters_size"; +pub static GET_PARAMETERS_FUNCTION: &str = "get_parameters"; +pub static PROCESS_FUNCTION: &str = "process"; extern "C" fn check_error() -> c_int { let last_error = LAST_ERROR.with(|last_error| last_error.replace(None)); @@ -144,7 +144,7 @@ unsafe fn get_parameter_from_worker_parameter(worker_parameter: &WorkerParameter } fn get_library_file_path() -> String { - std::env::var("WORKER_LIBRARY_FILE").unwrap_or("libworker.so".to_string()) + std::env::var("WORKER_LIBRARY_FILE").unwrap_or_else(|_| "libworker.so".to_string()) } unsafe fn get_library_function<'a, T>( From 7ce87f84cdca4c21d017f840fd31325670561414 Mon Sep 17 00:00:00 2001 From: Valentin NOEL Date: Tue, 10 Dec 2019 17:21:08 +0100 Subject: [PATCH 5/8] Fix Travis warnings --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7938980..bd3b308 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ language: rust +os: linux + rust: - 1.36.0 - 1.37.0 @@ -12,7 +14,7 @@ rust: env: - WORKER_LIBRARY_FILE=$TRAVIS_BUILD_DIR/libworker.so -matrix: +jobs: allow_failures: - rust: nightly include: @@ -35,8 +37,6 @@ matrix: # Test coverage (with Tarpaulin) - rust: stable - # To avoid "Error: EPERM: operation not permitted" error (see https://github.com/valery-barysok/session-file-store/issues/58) - sudo: true install: - RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install cargo-tarpaulin --force script: From ab88b02b5843a5195c682e2fba5cd47bee4b679b Mon Sep 17 00:00:00 2001 From: Valentin NOEL Date: Tue, 10 Dec 2019 17:51:18 +0100 Subject: [PATCH 6/8] Build the example worker to fix cargo tarpaulin job --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index bd3b308..1dbc5e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,6 +40,7 @@ jobs: install: - RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install cargo-tarpaulin --force script: + - gcc -c -Wall -Werror -fpic worker.cpp && gcc -shared -o libworker.so worker.o - cargo tarpaulin --ciserver travis-ci --coveralls $TRAVIS_JOB_ID script: From 9a5168ec2af7c718d756c77354fa6ea3c41cda3c Mon Sep 17 00:00:00 2001 From: Valentin NOEL Date: Tue, 10 Dec 2019 17:54:29 +0100 Subject: [PATCH 7/8] Add Travis status badge into the README file --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ac6bb4c..7be8fea 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # C/C++ binding for Rust AMQP Worker Based on [rs_amqp_worker](https://github.com/media-cloud-ai/rs_amqp_worker). +[![Build Status](https://travis-ci.org/media-cloud-ai/c_amqp_worker.svg?branch=master)](https://travis-ci.org/media-cloud-ai/c_amqp_worker) + ## Build To build the rust application ```bash From 5e6eade6ed711e84875cbd78e7cdf4551a5478fc Mon Sep 17 00:00:00 2001 From: Valentin NOEL Date: Wed, 11 Dec 2019 09:23:01 +0100 Subject: [PATCH 8/8] Add Coverall badge into README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7be8fea..8d90c39 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ Based on [rs_amqp_worker](https://github.com/media-cloud-ai/rs_amqp_worker). [![Build Status](https://travis-ci.org/media-cloud-ai/c_amqp_worker.svg?branch=master)](https://travis-ci.org/media-cloud-ai/c_amqp_worker) +[![Coverage Status](https://coveralls.io/repos/github/media-cloud-ai/c_amqp_worker/badge.svg?branch=master)](https://coveralls.io/github/media-cloud-ai/c_amqp_worker?branch=master) ## Build To build the rust application