Skip to content

Commit 77e633e

Browse files
authored
tracking clang-tidy warnings (#17)
* tracking clang-tidy warnings * attempting to update artifacts on PR * testing CI artifact creation * added selective artifacts to ci compile step * extending conditional for artifacts * added build modifier for CI step
1 parent 2f764c0 commit 77e633e

File tree

9 files changed

+217
-78
lines changed

9 files changed

+217
-78
lines changed

.github/workflows/ci.yml

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ jobs:
4444
name: Compile ${{ matrix.tuple.build }}
4545
needs: [rustfmt, clippy]
4646
runs-on: ${{ matrix.tuple.os }}
47+
env:
48+
TARGET_DIR: ./target
49+
RUST_BACKTRACE: 1 # Emit backtraces on panics.
4750
strategy:
4851
fail-fast: false
4952
matrix:
@@ -59,28 +62,30 @@ jobs:
5962
# alternatively matrix could be shared and specified via .json
6063
# see https://github.community/t/how-to-share-matrix-between-jobs/128595/8
6164
# ---
62-
- { build: 'linux-x86_64-pinned', os: 'ubuntu-22.04', target: 'x86_64-unknown-linux-gnu', cross: false, rust: 1.68.2 }
63-
- { build: 'windows-x86_64-pinned', os: 'windows-2019', target: 'x86_64-pc-windows-msvc', cross: false, rust: 1.68.2 }
64-
- { build: 'macos-x86_64-pinned', os: 'macos-latest', target: 'x86_64-apple-darwin', cross: false, rust: 1.68.2 }
65-
- { build: 'linux-x86_64', os: 'ubuntu-latest', target: 'x86_64-unknown-linux-gnu', cross: false, rust: stable }
66-
- { build: 'linux-i686', os: 'ubuntu-latest', target: 'i686-unknown-linux-gnu', cross: true, rust: stable }
67-
- { build: 'linux-arm', os: 'ubuntu-latest', target: 'aarch64-unknown-linux-gnu', cross: true, rust: stable } # aarch64
68-
# - { build: 'ubuntu-armv7', os: 'ubuntu-latest', target: 'armv7-unknown-linux-gnueabihf', cross: true, rust: stable } # armv7
69-
# - { build: 'ubuntu-armv6', os: 'ubuntu-latest', target: 'arm-unknown-linux-gnueabihf', cross: true, rust: stable } # armv6
70-
- { build: 'macos-x86_64', os: 'macos-latest', target: 'x86_64-apple-darwin', cross: false, rust: stable }
71-
# - { build: 'macos-arm', os: 'macos-latest', target: 'aarch64-apple-darwin', cross: true, rust: stable } # arm (tier 2, not in cross)
72-
- { build: 'windows-x86_64-msvc', os: 'windows-latest', target: 'x86_64-pc-windows-msvc', cross: false, rust: stable }
73-
- { build: 'windows-i686-msvc', os: 'windows-latest', target: 'i686-pc-windows-msvc', cross: false, rust: stable }
74-
- { build: 'windows-x86_64-mingw', os: 'windows-latest', target: 'x86_64-pc-windows-gnu', cross: false, rust: stable }
75-
# - { build: 'windows-i686-mingw', os: 'windows-latest', target: 'i686-pc-windows-gnu', cross: false, rust: stable }
65+
- { build: 'linux-x86_64-pinned', os: 'ubuntu-22.04', target: 'x86_64-unknown-linux-gnu', cross: false, rust: 1.68.2, archive: true }
66+
- { build: 'windows-x86_64-pinned', os: 'windows-2019', target: 'x86_64-pc-windows-msvc', cross: false, rust: 1.68.2, archive: true }
67+
- { build: 'macos-x86_64-pinned', os: 'macos-latest', target: 'x86_64-apple-darwin', cross: false, rust: 1.68.2, archive: true }
68+
- { build: 'linux-x86_64', os: 'ubuntu-latest', target: 'x86_64-unknown-linux-gnu', cross: false, rust: stable, archive: false }
69+
- { build: 'linux-i686', os: 'ubuntu-latest', target: 'i686-unknown-linux-gnu', cross: true, rust: stable, archive: false }
70+
- { build: 'linux-arm', os: 'ubuntu-latest', target: 'aarch64-unknown-linux-gnu', cross: true, rust: stable, archive: false } # aarch64
71+
# - { build: 'ubuntu-armv7', os: 'ubuntu-latest', target: 'armv7-unknown-linux-gnueabihf', cross: true, rust: stable, archive: false } # armv7
72+
# - { build: 'ubuntu-armv6', os: 'ubuntu-latest', target: 'arm-unknown-linux-gnueabihf', cross: true, rust: stable, archive: false } # armv6
73+
- { build: 'macos-x86_64', os: 'macos-latest', target: 'x86_64-apple-darwin', cross: false, rust: stable, archive: false }
74+
# - { build: 'macos-arm', os: 'macos-latest', target: 'aarch64-apple-darwin', cross: true, rust: stable, archive: false } # arm (tier 2, not in cross)
75+
- { build: 'windows-x86_64-msvc', os: 'windows-latest', target: 'x86_64-pc-windows-msvc', cross: false, rust: stable, archive: false }
76+
- { build: 'windows-i686-msvc', os: 'windows-latest', target: 'i686-pc-windows-msvc', cross: false, rust: stable, archive: false }
77+
- { build: 'windows-x86_64-mingw', os: 'windows-latest', target: 'x86_64-pc-windows-gnu', cross: false, rust: stable, archive: false }
78+
# - { build: 'windows-i686-mingw', os: 'windows-latest', target: 'i686-pc-windows-gnu', cross: false, rust: stable, archive: false }
7679
steps:
7780
- name: Checkout repository
7881
uses: actions/checkout@v3
7982
# Rustup update can fail on windows since it tries to replace its binary. This is not really
8083
# needed anyhow. https://github.com/rust-lang/rustup/issues/3029
84+
8185
- name: Disable rustup self-update
8286
shell: bash
8387
run: rustup set auto-self-update disable
88+
8489
- name: Install toolchain
8590
uses: actions-rs/toolchain@v1
8691
with:
@@ -90,6 +95,7 @@ jobs:
9095
toolchain: ${{ matrix.tuple.rust }}
9196
override: true
9297
target: ${{ matrix.tuple.target }}
98+
9399
- name: Check
94100
uses: actions-rs/cargo@v1
95101
with:
@@ -98,6 +104,43 @@ jobs:
98104
args: --verbose --target=${{ matrix.tuple.target }}
99105
use-cross: ${{ matrix.tuple.cross }}
100106

107+
- name: Build artifact
108+
uses: actions-rs/cargo@v1
109+
if: matrix.tuple.archive != false && github.event_name == 'pull_request'
110+
with:
111+
command: build
112+
args: --release --target=${{ matrix.tuple.target }}
113+
use-cross: ${{ matrix.tuple.cross }}
114+
env:
115+
CI_PKG_VERSION_PRE_RELEASE: --alpha
116+
CI_PKG_VERSION_BUILD: ${{ github.run_number }}
117+
118+
- name: Archive
119+
if: matrix.tuple.archive != false && github.event_name == 'pull_request'
120+
shell: bash
121+
run: |
122+
staging="run-clang-tidy-build-${{github.run_number}}-${{ matrix.tuple.target }}"
123+
mkdir -p "$staging"
124+
125+
cp {readme.md,LICENSE} "$staging/"
126+
127+
if [ "${{ matrix.tuple.os }}" = "windows-latest" ]; then
128+
cp "target/${{ matrix.tuple.target }}/release/run-clang-tidy.exe" "$staging/"
129+
7z a "$staging.zip" "$staging"
130+
echo "ASSET=$staging.zip" >> $GITHUB_ENV
131+
else
132+
cp "target/${{ matrix.tuple.target }}/release/run-clang-tidy" "$staging/"
133+
tar czf "$staging.tar.gz" "$staging"
134+
echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
135+
fi
136+
137+
- name: Archive artifacts
138+
uses: actions/upload-artifact@v3
139+
if: matrix.tuple.archive != false && github.event_name == 'pull_request'
140+
with:
141+
name: dist-${{github.run_number}}-${{ matrix.tuple.target }}
142+
path: ${{ env.ASSET }}
143+
101144
tests:
102145
name: Test ${{ matrix.os }}
103146
needs: [compile]
@@ -144,6 +187,6 @@ jobs:
144187
toolchain: ${{ matrix.toolchain }}
145188
override: true
146189

147-
- name: Test
190+
- name: Run tests
148191
# using only one test thread to avoid race conditions on temporary files
149192
run: cargo test --verbose --no-fail-fast -- --test-threads 1

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ _notes.md
1515
artifacts
1616
docker
1717

18-
_bld
18+
_bld
19+
.cargo/config.toml

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "run-clang-tidy"
3-
version = "0.1.8"
3+
version = "0.2.0"
44
authors = ["Martin Lampacher <lmapii@gmail.com>"]
55
description = """
66
Cross platform CLI wrapper for executing clang-tidy based paths or globs specified

build.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
fn main() {
2+
let pre_release = if let Ok(pre_release) = std::env::var("CI_PKG_VERSION_PRE_RELEASE") {
3+
"-".to_owned() + &pre_release
4+
} else {
5+
"".to_owned()
6+
};
7+
8+
let build = if let Ok(build) = std::env::var("CI_PKG_VERSION_BUILD") {
9+
"+".to_owned() + &build
10+
} else {
11+
"".to_owned()
12+
};
13+
14+
// If we set CARGO_PKG_VERSION this way, then it will override the default value, which is
15+
// taken from the `version` in Cargo.toml or from an override in .cargo/config.toml
16+
let version_override = format!("{}{}{}", env!("CARGO_PKG_VERSION"), pre_release, build);
17+
if !version_override.is_empty() {
18+
println!("cargo:rustc-env=CARGO_PKG_VERSION={}", version_override);
19+
}
20+
21+
println!("cargo:rerun-if-env-changed=CI_PKG_VERSION_PRE_RELEASE");
22+
println!("cargo:rerun-if-env-changed=CI_PKG_VERSION_BUILD");
23+
println!("cargo:rerun-if-changed=.cargo/config.toml");
24+
}

readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Execute `run-clang-tidy --help` for more details, or `run-clang-tidy schema` for
4141
- [Speeding up the execution](#speeding-up-the-execution)
4242
- [Specifying an alternative tidy file and command](#specifying-an-alternative-tidy-file-and-command)
4343
- [Specifying an alternative build root](#specifying-an-alternative-build-root)
44+
- [Suppressing warnings](#suppressing-warnings)
4445
- [Use-cases](#use-cases)
4546
- [Pitfalls](#pitfalls)
4647
- [Multiple `.clang-tidy` files](#multiple-clang-tidy-files)
@@ -300,6 +301,12 @@ The [build root](#the-build-root-and-compile_commandsjson) containing the compil
300301

301302
Therefore the command-line option `--build-root` allows to specify the build directory when invoking this script, overriding, e.g., a default directory specified in the configuration `.json` file.
302303

304+
## Suppressing warnings
305+
306+
By default, warnings issued by `clang-tidy` are output on each run, unless the command-line option `--suppress-warnings` is used.
307+
308+
> **Remark:** `clang-tidy` warnings do not affect the return code of `run-clang-tidy`, regardless of whether or not they are part of the output. Use your `.clang-tidy` file to transform warnings into errors in case the execution should fail, e.g., by specifying `WarningsAsErrors`.
309+
303310
# Use-cases
304311

305312
Due to the nature of this tool, i.e., the underlying `clang` tools, the use-cases are very similar when executing `clang-format`, for which a [dedicated wrapper](https://github.com/lmapii/run-clang-format) exists. Please refer to the matching section in the documentation of [`run-clang-format`](https://github.com/lmapii/run-clang-format#use-cases).

src/cli/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod handlers;
44
mod logging;
55
pub mod utils;
66

7-
use clap::{arg, crate_authors, crate_description, crate_name, crate_version};
7+
use clap::{arg, crate_authors, crate_description, crate_name, crate_version, Arg};
88
#[allow(unused_imports)]
99
use color_eyre::{eyre::eyre, eyre::WrapErr, Help};
1010
use schemars::{schema_for, JsonSchema};
@@ -69,6 +69,8 @@ pub struct Data {
6969
/// Command-line parameter for the number of jobs to use for executing clang-tidy
7070
/// If `None` then all available jobs should be used, else the specified number of jobs.
7171
pub jobs: Option<u8>,
72+
/// Command-line option to suppress warnings issued by clang-tidy.
73+
pub ignore_warn: bool,
7274
}
7375

7476
pub struct Builder {
@@ -132,6 +134,12 @@ impl Builder {
132134
arg!(-q --quiet "Suppress all output except for errors; overrides -v")
133135
.action(clap::ArgAction::SetTrue),
134136
)
137+
.arg(
138+
Arg::new("suppress-warnings")
139+
.long("suppress-warnings")
140+
.action(clap::ArgAction::SetTrue)
141+
.help("Suppress warnings; overrides -v"),
142+
)
135143
.subcommand_negates_reqs(true)
136144
.subcommand(
137145
clap::Command::new("schema")
@@ -212,6 +220,7 @@ impl Builder {
212220
build_root,
213221
command,
214222
jobs,
223+
ignore_warn: self.matches.get_flag("suppress-warnings"),
215224
})
216225
}
217226

src/cmd/mod.rs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ struct Version {
77
patch: u8,
88
}
99

10+
#[derive(Debug)]
11+
pub enum RunResult {
12+
Ok,
13+
Err(String),
14+
Warn(String),
15+
}
16+
17+
impl From<&io::Error> for RunResult {
18+
fn from(value: &io::Error) -> Self {
19+
RunResult::Err(value.to_string())
20+
}
21+
}
22+
1023
impl FromStr for Version {
1124
type Err = String;
1225

@@ -91,29 +104,28 @@ impl Runner {
91104
Ok(())
92105
}
93106

94-
fn run(mut cmd: process::Command) -> Result<(), io::Error> {
95-
let output = cmd.output()?;
107+
fn run(mut cmd: process::Command, ignore_warn: bool) -> RunResult {
108+
let output = cmd.output();
109+
if let Err(err) = &output {
110+
return err.into();
111+
}
112+
let output = output.unwrap();
96113

97-
if let Err(err) = Runner::eval_status(output.status) {
98-
let stderr = String::from_utf8_lossy(&output.stderr);
99-
let stdout = String::from_utf8_lossy(&output.stdout);
114+
let stderr = String::from_utf8_lossy(&output.stderr);
115+
let stdout = String::from_utf8_lossy(&output.stdout);
100116

117+
if let Err(err) = Runner::eval_status(output.status) {
101118
if stderr.len() != 0 {
102-
// log::error!("{}", stderr);
103-
// log::info!("{}", stdout);
104-
105-
return Err(io::Error::new(
106-
io::ErrorKind::Other,
107-
format!("{err}\n---\n{stderr}---\n{stdout}"),
108-
// format!("{}\n---\n{}", err, stdout),
109-
));
119+
return RunResult::Err(format!("{err}\n---\n{stderr}---\n{stdout}"));
110120
}
111-
return Err(err);
121+
return (&err).into();
122+
} else if !ignore_warn && !stderr.is_empty() {
123+
return RunResult::Warn(format!("warnings encountered\n---\n{stderr}---\n{stdout}"));
112124
}
113-
Ok(())
125+
RunResult::Ok
114126
}
115127

116-
pub fn run_tidy<P, Q>(&self, file: P, build_root: Q, fix: bool) -> Result<(), io::Error>
128+
pub fn run_tidy<P, Q>(&self, file: P, build_root: Q, fix: bool, ignore_warn: bool) -> RunResult
117129
where
118130
P: AsRef<path::Path>,
119131
Q: AsRef<path::Path>,
@@ -135,7 +147,7 @@ impl Runner {
135147
// This suppresses printing statistics about ignored warnings:
136148
// cmd.arg("-quiet");
137149

138-
Runner::run(cmd)
150+
Runner::run(cmd, ignore_warn)
139151
}
140152

141153
pub fn supports_config_file(&self) -> Result<(), io::Error> {

0 commit comments

Comments
 (0)