mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 19:09:37 +00:00
feat: add native Qt support and dcr lint command; refactor architecture and integration tests
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::core::config::Config;
|
||||
use crate::core::build_config::Config;
|
||||
use crate::core::deps::register;
|
||||
use crate::utils::fs::find_project_root;
|
||||
use crate::utils::log::error;
|
||||
|
||||
135
src/cli/build.rs
135
src/cli/build.rs
@@ -17,16 +17,16 @@
|
||||
|
||||
use crate::cli::clean::clean;
|
||||
use crate::cli::flags::parse_build_run_flags;
|
||||
use crate::core::build_config::Config;
|
||||
use crate::core::builder::common;
|
||||
use crate::core::builder::{BuildContext, build as build_project, collect_sources};
|
||||
use crate::core::config::Config;
|
||||
use crate::core::deps::{register, resolve_deps};
|
||||
use crate::core::workspace::parse_workspace;
|
||||
use crate::utils::build::{
|
||||
default_target_triple, get_bool_with_profile, get_config_opt, get_config_str,
|
||||
get_language_with_profile, is_bare_metal_target, normalize_target_os, parse_version_info,
|
||||
prepend_clang_target_flag, profile_table, resolve_compiler, resolve_pkg_config_flags,
|
||||
resolve_tool,
|
||||
get_language_with_profile, is_bare_metal_target, normalize_kind, normalize_platform,
|
||||
normalize_target, normalize_target_os, parse_version_info, prepend_clang_target_flag,
|
||||
profile_table, resolve_compiler, resolve_pkg_config_flags, resolve_tool, substitute_vars,
|
||||
};
|
||||
use crate::utils::fs::{check_dir, find_project_root, with_dir};
|
||||
use crate::utils::log::error;
|
||||
@@ -633,6 +633,7 @@ fn build_project_at(
|
||||
let project_compiler =
|
||||
get_string_with_profile_and_target(&config, "compiler", profile, build_target);
|
||||
let build_language = get_language_with_profile(&config, profile)?;
|
||||
let build_qt = get_bool_with_profile(&config, "qt", profile, false);
|
||||
let build_standard =
|
||||
get_string_with_profile_and_target(&config, "standard", profile, build_target);
|
||||
let build_cxx_standard =
|
||||
@@ -930,21 +931,19 @@ fn build_project_at(
|
||||
}
|
||||
|
||||
let version_info = parse_version_info(&project_version);
|
||||
let substitute = |s: &str| -> String {
|
||||
s.replace("{profile}", profile)
|
||||
.replace("{name}", &project_name)
|
||||
.replace("{version}", &version_info.full)
|
||||
.replace("{version_major}", &version_info.major)
|
||||
.replace("{version_minor}", &version_info.minor)
|
||||
.replace("{version_patch}", &version_info.patch)
|
||||
.replace("{version_suffix}", &version_info.suffix)
|
||||
.replace("{version_suffix_dash}", &version_info.suffix_dash)
|
||||
};
|
||||
let resolved_cflags: Vec<String> = resolved_cflags.iter().map(|f| substitute(f)).collect();
|
||||
let modified_ldflags: Vec<String> =
|
||||
resolved_ldflags.iter().map(|f| substitute(f)).collect();
|
||||
let merged_include_dirs: Vec<String> =
|
||||
merged_include_dirs.iter().map(|f| substitute(f)).collect();
|
||||
let resolved_cflags: Vec<String> = resolved_cflags
|
||||
.iter()
|
||||
.map(|f| substitute_vars(f, &version_info, profile, &project_name))
|
||||
.collect();
|
||||
let modified_ldflags: Vec<String> = resolved_ldflags
|
||||
.iter()
|
||||
.map(|f| substitute_vars(f, &version_info, profile, &project_name))
|
||||
.collect();
|
||||
let merged_include_dirs: Vec<String> = merged_include_dirs
|
||||
.iter()
|
||||
.map(|f| substitute_vars(f, &version_info, profile, &project_name))
|
||||
.collect();
|
||||
let tool_execs = resolve_toolchain_execs(&tc_uic, &tc_moc, &tc_rcc, &pkg_configs);
|
||||
let ctx = BuildContext {
|
||||
profile,
|
||||
project_name: &project_name,
|
||||
@@ -962,6 +961,9 @@ fn build_project_at(
|
||||
platform: normalize_platform(&build_platform),
|
||||
linker: resolved_linker.as_deref(),
|
||||
archiver: resolved_archiver.as_deref(),
|
||||
moc: Some(&tool_execs.moc),
|
||||
uic: Some(&tool_execs.uic),
|
||||
rcc: Some(&tool_execs.rcc),
|
||||
package_type: if build_type.is_empty() {
|
||||
None
|
||||
} else {
|
||||
@@ -989,15 +991,8 @@ fn build_project_at(
|
||||
Some(output_extension.as_str())
|
||||
},
|
||||
verbose,
|
||||
qt: build_qt,
|
||||
};
|
||||
if std::env::var("DCR_DEBUG").is_ok() {
|
||||
eprintln!("[dcr] debug: compiler={}", ctx.compiler);
|
||||
eprintln!("[dcr] debug: cflags={:?}", ctx.cflags);
|
||||
eprintln!("[dcr] debug: ldflags={:?}", ctx.ldflags);
|
||||
eprintln!("[dcr] debug: lib_dirs={:?}", ctx.lib_dirs);
|
||||
eprintln!("[dcr] debug: libs={:?}", ctx.libs);
|
||||
}
|
||||
let tool_execs = resolve_toolchain_execs(&tc_uic, &tc_moc, &tc_rcc, &pkg_configs);
|
||||
let step_flags =
|
||||
build_step_flags(&resolved_cflags, &resolved.include_dirs, &resolved_compiler);
|
||||
let step_vars = StepVars {
|
||||
@@ -1105,29 +1100,6 @@ fn package_library(ctx: &BuildContext, headers: &[PathBuf]) -> Result<(), String
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn normalize_target(target: &str, profile: &str) -> Option<String> {
|
||||
let trimmed = normalize_target_os(target.trim());
|
||||
if trimmed.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(format!("target/{trimmed}/{profile}"))
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize_kind(kind: &str) -> &str {
|
||||
let trimmed = kind.trim();
|
||||
if trimmed.is_empty() { "bin" } else { trimmed }
|
||||
}
|
||||
|
||||
fn normalize_platform(platform: &str) -> Option<&str> {
|
||||
let trimmed = platform.trim();
|
||||
if trimmed.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(trimmed)
|
||||
}
|
||||
}
|
||||
|
||||
struct ToolchainExecs {
|
||||
uic: String,
|
||||
moc: String,
|
||||
@@ -1242,12 +1214,11 @@ fn detect_qt6_tool_variant(tool: &str) -> Option<String> {
|
||||
}
|
||||
|
||||
fn is_on_path(cmd: &str) -> bool {
|
||||
std::process::Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg(format!("command -v {cmd}"))
|
||||
.output()
|
||||
.map(|o| o.status.success())
|
||||
.unwrap_or(false)
|
||||
if Path::new(cmd).is_file() {
|
||||
return true;
|
||||
}
|
||||
std::env::var_os("PATH")
|
||||
.is_some_and(|paths| std::env::split_paths(&paths).any(|dir| dir.join(cmd).is_file()))
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -1370,21 +1341,15 @@ fn substitute_step_cmd(
|
||||
stem: &str,
|
||||
vars: &StepVars,
|
||||
) -> String {
|
||||
template
|
||||
.replace("{in}", &input.to_string_lossy())
|
||||
let info = make_version_info(vars);
|
||||
let s = substitute_vars(template, &info, vars.profile, "");
|
||||
s.replace("{in}", &input.to_string_lossy())
|
||||
.replace("{out}", &output.to_string_lossy())
|
||||
.replace("{uic}", &tools.uic)
|
||||
.replace("{moc}", &tools.moc)
|
||||
.replace("{rcc}", &tools.rcc)
|
||||
.replace("{cflags}", step_flags)
|
||||
.replace("{stem}", stem)
|
||||
.replace("{profile}", vars.profile)
|
||||
.replace("{version}", vars.version)
|
||||
.replace("{version_major}", vars.version_major)
|
||||
.replace("{version_minor}", vars.version_minor)
|
||||
.replace("{version_patch}", vars.version_patch)
|
||||
.replace("{version_suffix}", vars.version_suffix)
|
||||
.replace("{version_suffix_dash}", vars.version_suffix_dash)
|
||||
}
|
||||
|
||||
fn build_step_flags(cflags: &[String], include_dirs: &[String], compiler: &str) -> String {
|
||||
@@ -1407,14 +1372,9 @@ fn build_step_flags(cflags: &[String], include_dirs: &[String], compiler: &str)
|
||||
out.push(format!("/I{dir}"));
|
||||
}
|
||||
}
|
||||
let mut dedup = Vec::new();
|
||||
for item in out {
|
||||
if !dedup.contains(&item) {
|
||||
dedup.push(item);
|
||||
}
|
||||
}
|
||||
dedup
|
||||
.into_iter()
|
||||
out.sort();
|
||||
out.dedup();
|
||||
out.into_iter()
|
||||
.map(quote_step_arg)
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
@@ -1475,16 +1435,21 @@ fn build_steps_need_run(steps: &[BuildStep], vars: &StepVars) -> Result<bool, St
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
fn make_version_info(vars: &StepVars) -> crate::utils::build::VersionInfo {
|
||||
crate::utils::build::VersionInfo {
|
||||
full: vars.version.to_string(),
|
||||
major: vars.version_major.to_string(),
|
||||
minor: vars.version_minor.to_string(),
|
||||
patch: vars.version_patch.to_string(),
|
||||
suffix: vars.version_suffix.to_string(),
|
||||
suffix_dash: vars.version_suffix_dash.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn expand_step_value(template: &str, stem: &str, vars: &StepVars) -> String {
|
||||
template
|
||||
.replace("{stem}", stem)
|
||||
.replace("{profile}", vars.profile)
|
||||
.replace("{version}", vars.version)
|
||||
.replace("{version_major}", vars.version_major)
|
||||
.replace("{version_minor}", vars.version_minor)
|
||||
.replace("{version_patch}", vars.version_patch)
|
||||
.replace("{version_suffix}", vars.version_suffix)
|
||||
.replace("{version_suffix_dash}", vars.version_suffix_dash)
|
||||
let info = make_version_info(vars);
|
||||
let s = substitute_vars(template, &info, vars.profile, "");
|
||||
s.replace("{stem}", stem)
|
||||
}
|
||||
|
||||
struct StepVars<'a> {
|
||||
@@ -1716,9 +1681,5 @@ fn update_hasher_with_file(hasher: &mut Sha256, path: &Path) -> Result<(), Strin
|
||||
}
|
||||
|
||||
fn to_hex(bytes: &[u8]) -> String {
|
||||
let mut out = String::with_capacity(bytes.len() * 2);
|
||||
for b in bytes {
|
||||
out.push_str(&format!("{:02x}", b));
|
||||
}
|
||||
out
|
||||
crate::utils::fs::to_hex(bytes)
|
||||
}
|
||||
|
||||
@@ -15,10 +15,9 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::config::flags;
|
||||
use crate::core::config::Config;
|
||||
use crate::core::build_config::Config;
|
||||
use crate::core::workspace::parse_workspace;
|
||||
use crate::utils::build::{default_target_triple, parse_version_info};
|
||||
use crate::utils::build::{default_profile_flags, default_target_triple, parse_version_info};
|
||||
use crate::utils::fs::{check_dir, find_project_root, with_dir};
|
||||
use crate::utils::log::{error, warn};
|
||||
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc};
|
||||
@@ -106,7 +105,7 @@ fn parse_clean_flags(args: &[String]) -> Result<CleanFlags, String> {
|
||||
}
|
||||
if arg.starts_with("--") {
|
||||
let candidate = arg.trim_start_matches("--").to_string();
|
||||
if flags(&candidate).is_some() {
|
||||
if !default_profile_flags(&candidate).is_empty() {
|
||||
if profile.is_some() {
|
||||
return Err("Duplicate profile flag".to_string());
|
||||
}
|
||||
@@ -227,7 +226,7 @@ fn clean_custom_paths(config: &Config, profile: &str) -> Result<(), String> {
|
||||
.filter_map(|item| item.as_str())
|
||||
.map(|s| {
|
||||
let value = s.replace("{profile}", profile);
|
||||
substitute_version_vars(&value, config)
|
||||
substitute_clean_vars(&value, config)
|
||||
})
|
||||
.collect::<Vec<String>>(),
|
||||
None => Vec::new(),
|
||||
@@ -248,17 +247,11 @@ fn clean_custom_paths(config: &Config, profile: &str) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn substitute_version_vars(value: &str, config: &Config) -> String {
|
||||
fn substitute_clean_vars(value: &str, config: &Config) -> String {
|
||||
let version = config
|
||||
.get("package.version")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("");
|
||||
let info = parse_version_info(version);
|
||||
value
|
||||
.replace("{version}", &info.full)
|
||||
.replace("{version_major}", &info.major)
|
||||
.replace("{version_minor}", &info.minor)
|
||||
.replace("{version_patch}", &info.patch)
|
||||
.replace("{version_suffix}", &info.suffix)
|
||||
.replace("{version_suffix_dash}", &info.suffix_dash)
|
||||
crate::utils::build::substitute_version_vars(value, &info)
|
||||
}
|
||||
|
||||
@@ -15,15 +15,15 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::core::build_config::Config;
|
||||
use crate::core::builder::BuildContext;
|
||||
use crate::core::builder::collect_sources;
|
||||
use crate::core::builder::common;
|
||||
use crate::core::config::Config;
|
||||
use crate::core::workspace::parse_workspace;
|
||||
use crate::utils::build::{
|
||||
get_bool_with_profile, get_config_opt, get_config_str, get_language_with_profile_or_default,
|
||||
get_list_with_profile, get_string_with_profile, normalize_target_os, resolve_compiler,
|
||||
resolve_pkg_config_flags_lossy,
|
||||
get_list_with_profile, get_string_with_profile, normalize_kind, normalize_platform,
|
||||
normalize_target, resolve_compiler, resolve_pkg_config_flags_lossy,
|
||||
};
|
||||
use crate::utils::fs::find_project_root;
|
||||
use crate::utils::log::error;
|
||||
@@ -366,6 +366,9 @@ fn collect_project_info_inner(root: &Path, profile: &str) -> Result<ProjectInfo,
|
||||
platform: normalize_platform(&platform),
|
||||
linker: resolved_linker.as_deref(),
|
||||
archiver: resolved_archiver.as_deref(),
|
||||
moc: None,
|
||||
uic: None,
|
||||
rcc: None,
|
||||
package_type: None,
|
||||
freestanding: false,
|
||||
panic_abort: false,
|
||||
@@ -381,6 +384,7 @@ fn collect_project_info_inner(root: &Path, profile: &str) -> Result<ProjectInfo,
|
||||
output_filename: None,
|
||||
output_extension: None,
|
||||
verbose: false,
|
||||
qt: false,
|
||||
};
|
||||
|
||||
let sources = collect_sources(&ctx).map_err(|e| format!("Failed to collect sources: {e}"))?;
|
||||
@@ -606,7 +610,7 @@ fn build_compile_command(info: &ProjectInfo, source: &str, profile: &str) -> Vec
|
||||
cmd.push("-c".to_string());
|
||||
|
||||
// ASM x flag — must be before source file
|
||||
if let Some(flag) = asm_lang_flag(source) {
|
||||
if let Some(flag) = common::asm_lang_flag(source) {
|
||||
cmd.push("-x".to_string());
|
||||
cmd.push(flag.to_string());
|
||||
}
|
||||
@@ -684,15 +688,6 @@ fn build_compile_command(info: &ProjectInfo, source: &str, profile: &str) -> Vec
|
||||
cmd
|
||||
}
|
||||
|
||||
fn asm_lang_flag(source: &str) -> Option<&'static str> {
|
||||
let ext = Path::new(source).extension().and_then(|v| v.to_str())?;
|
||||
match ext {
|
||||
"S" => Some("assembler-with-cpp"),
|
||||
"s" | "asm" => Some("assembler"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn strip_src_prefix(p: &Path) -> PathBuf {
|
||||
// Try to strip leading ./src or src
|
||||
let s = p.to_string_lossy();
|
||||
@@ -1241,25 +1236,6 @@ fn parse_gen_args(args: &[String]) -> Result<(PathBuf, String), i32> {
|
||||
Ok((root, profile))
|
||||
}
|
||||
|
||||
fn normalize_target(s: &str, profile: &str) -> Option<String> {
|
||||
let trimmed = normalize_target_os(s.trim());
|
||||
if trimmed.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(format!("target/{trimmed}/{profile}"))
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize_kind(s: &str) -> &str {
|
||||
let t = s.trim();
|
||||
if t.is_empty() { "bin" } else { t }
|
||||
}
|
||||
|
||||
fn normalize_platform(s: &str) -> Option<&str> {
|
||||
let t = s.trim();
|
||||
if t.is_empty() { None } else { Some(t) }
|
||||
}
|
||||
|
||||
fn json_str(s: &str) -> String {
|
||||
let mut result = String::with_capacity(s.len() + 2);
|
||||
result.push('"');
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::config::FILE_MAIN_C;
|
||||
use crate::core::config::{Config, validate_package_name};
|
||||
use crate::core::build_config::{Config, validate_package_name};
|
||||
use crate::core::vcs::VcsKind;
|
||||
use crate::utils::fs::check_dir;
|
||||
use crate::utils::log::{error, warn};
|
||||
|
||||
189
src/cli/lint.rs
Normal file
189
src/cli/lint.rs
Normal file
@@ -0,0 +1,189 @@
|
||||
// DCR — Cargo-like C/C++ project manager.
|
||||
//
|
||||
// Copyright (C) 2026 Dexoron (Bezotechestvo Vladimir) <main@dexoron.su>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::core::build_config::Config;
|
||||
use crate::core::builder::common;
|
||||
use crate::utils::build::{get_bool_with_profile, get_list_with_profile};
|
||||
use crate::utils::fs::find_project_root;
|
||||
use crate::utils::log::error;
|
||||
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, BOLD_YELLOW, colored, printc};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
pub fn lint(args: &[String]) -> i32 {
|
||||
if args.first().is_some_and(|a| a == "--help") {
|
||||
printc("USAGE:", BOLD_GREEN);
|
||||
printc(" dcr lint [--fix]", BOLD_CYAN);
|
||||
println!();
|
||||
printc("DESCRIPTION:", BOLD_GREEN);
|
||||
println!(" Runs clang-tidy on all C/C++ source files.");
|
||||
println!(" Scans source roots (configurable via build.roots) and tests/ directory.");
|
||||
println!();
|
||||
printc("OPTIONS:", BOLD_GREEN);
|
||||
println!(" --fix Apply clang-tidy suggestions automatically");
|
||||
return 0;
|
||||
}
|
||||
|
||||
let do_fix = args.iter().any(|a| a == "--fix");
|
||||
|
||||
let start_dir = match std::env::current_dir() {
|
||||
Ok(dir) => dir,
|
||||
Err(_) => {
|
||||
error("Failed to determine current directory");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
let root = match find_project_root(&start_dir) {
|
||||
Ok(Some(r)) => r,
|
||||
Ok(None) => {
|
||||
error("dcr.toml not found");
|
||||
return 1;
|
||||
}
|
||||
Err(_) => {
|
||||
error("Failed to find project root");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
let config = match Config::open(&root.join("dcr.toml").to_string_lossy()) {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
error(&format!("Failed to load dcr.toml: {e}"));
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
let profile = "debug";
|
||||
let build_roots = get_list_with_profile(&config, "roots", profile);
|
||||
let src_disable = get_bool_with_profile(&config, "src_disable", profile, false);
|
||||
|
||||
let mut source_roots: Vec<String> = Vec::new();
|
||||
for raw in &build_roots {
|
||||
let p = Path::new(raw);
|
||||
if p.is_absolute() {
|
||||
source_roots.push(raw.clone());
|
||||
} else {
|
||||
source_roots.push(root.join(p).to_string_lossy().to_string());
|
||||
}
|
||||
}
|
||||
if !src_disable && source_roots.is_empty() {
|
||||
source_roots.push(root.join("src").to_string_lossy().to_string());
|
||||
}
|
||||
|
||||
let cxx_extensions = ["c", "cpp", "cxx", "cc"];
|
||||
let exclude_dirs: Vec<PathBuf> = Vec::new();
|
||||
let include_paths: Vec<String> = Vec::new();
|
||||
|
||||
let roots: Vec<PathBuf> = source_roots.iter().map(PathBuf::from).collect();
|
||||
let mut files =
|
||||
match common::collect_sources(&roots, &cxx_extensions, &exclude_dirs, &include_paths) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
error(&format!("Failed to collect source files: {e}"));
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
let tests_dir = root.join("tests");
|
||||
if tests_dir.is_dir() {
|
||||
let test_roots = vec![tests_dir];
|
||||
if let Ok(mut test_files) =
|
||||
common::collect_sources(&test_roots, &cxx_extensions, &exclude_dirs, &include_paths)
|
||||
{
|
||||
files.append(&mut test_files);
|
||||
}
|
||||
}
|
||||
|
||||
files.sort();
|
||||
|
||||
if files.is_empty() {
|
||||
println!(" {} No files to lint", colored("Lint", BOLD_GREEN));
|
||||
return 0;
|
||||
}
|
||||
|
||||
println!(
|
||||
" {} {} files {}",
|
||||
colored("Linting", BOLD_GREEN),
|
||||
files.len(),
|
||||
if do_fix { "(with --fix)" } else { "" }
|
||||
);
|
||||
|
||||
let mut total_issues = 0u32;
|
||||
let mut failed = 0u32;
|
||||
|
||||
for file in &files {
|
||||
let mut cmd = Command::new("clang-tidy");
|
||||
if do_fix {
|
||||
cmd.arg("--fix");
|
||||
}
|
||||
cmd.arg("--quiet");
|
||||
cmd.arg(file);
|
||||
|
||||
let output = match cmd.output() {
|
||||
Ok(o) => o,
|
||||
Err(e) => {
|
||||
error(&format!("Failed to execute clang-tidy: {}", e));
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let combined = format!("{}{}", stdout, stderr);
|
||||
|
||||
let issues: Vec<&str> = combined
|
||||
.lines()
|
||||
.filter(|l| l.contains("warning:") || l.contains("error:"))
|
||||
.collect();
|
||||
let issue_count = issues.len();
|
||||
|
||||
if issue_count > 0 {
|
||||
total_issues += issue_count as u32;
|
||||
failed += 1;
|
||||
print!(" {} ", colored("×", BOLD_YELLOW));
|
||||
println!("{} ({} issues)", file, issue_count);
|
||||
for issue in &issues {
|
||||
println!(" {}", issue);
|
||||
}
|
||||
} else {
|
||||
print!(" {} ", colored("✓", BOLD_GREEN));
|
||||
println!("{}", file);
|
||||
}
|
||||
}
|
||||
|
||||
let total = files.len();
|
||||
let passed = total - failed as usize;
|
||||
|
||||
if failed == 0 {
|
||||
println!(
|
||||
" {} {} files, no issues",
|
||||
colored("Lint", BOLD_GREEN),
|
||||
total
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
" {} {}/{} files passed, {} issues found",
|
||||
colored("Lint", BOLD_YELLOW),
|
||||
passed,
|
||||
total,
|
||||
total_issues
|
||||
);
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
@@ -24,6 +24,7 @@ pub mod fmt;
|
||||
pub mod r#gen;
|
||||
pub mod help;
|
||||
pub mod init;
|
||||
pub mod lint;
|
||||
pub mod new;
|
||||
pub mod run;
|
||||
pub mod setup;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::config::FILE_MAIN_C;
|
||||
use crate::core::config::{Config, validate_package_name};
|
||||
use crate::core::build_config::{Config, validate_package_name};
|
||||
use crate::core::vcs::VcsKind;
|
||||
use crate::utils::fs::check_dir;
|
||||
use crate::utils::log::{error, warn};
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
|
||||
use crate::cli::build::build;
|
||||
use crate::cli::flags::parse_build_run_flags;
|
||||
use crate::core::config::Config;
|
||||
use crate::core::build_config::Config;
|
||||
use crate::core::runner::run_binary;
|
||||
use crate::utils::build::{default_target_triple, normalize_target_os, parse_version_info};
|
||||
use crate::utils::build::{
|
||||
default_target_triple, normalize_target_os, parse_version_info, substitute_vars,
|
||||
};
|
||||
use crate::utils::fs::find_project_root;
|
||||
use crate::utils::fs::with_dir;
|
||||
use crate::utils::log::error;
|
||||
@@ -195,11 +197,11 @@ fn run_project(
|
||||
match workspace_root {
|
||||
Some(wr) => target
|
||||
.as_ref()
|
||||
.and_then(|t| crate::cli::build::normalize_target(t, &flags.profile))
|
||||
.and_then(|t| crate::utils::build::normalize_target(t, &flags.profile))
|
||||
.map(|rel| wr.join(&rel).to_string_lossy().to_string()),
|
||||
None => target
|
||||
.as_ref()
|
||||
.and_then(|t| crate::cli::build::normalize_target(t, &flags.profile)),
|
||||
.and_then(|t| crate::utils::build::normalize_target(t, &flags.profile)),
|
||||
}
|
||||
};
|
||||
|
||||
@@ -285,11 +287,5 @@ fn run_shell(cmd: &str) -> i32 {
|
||||
|
||||
fn substitute_run_vars(cmd: &str, profile: &str, version: &str) -> String {
|
||||
let info = parse_version_info(version);
|
||||
cmd.replace("{profile}", profile)
|
||||
.replace("{version}", &info.full)
|
||||
.replace("{version_major}", &info.major)
|
||||
.replace("{version_minor}", &info.minor)
|
||||
.replace("{version_patch}", &info.patch)
|
||||
.replace("{version_suffix}", &info.suffix)
|
||||
.replace("{version_suffix_dash}", &info.suffix_dash)
|
||||
substitute_vars(cmd, &info, profile, "")
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
use crate::cli::build;
|
||||
use crate::config::{FILE_DCR_TEST_H, FILE_TEST_C, flags};
|
||||
use crate::core::config::Config;
|
||||
use crate::core::build_config::Config;
|
||||
use crate::utils::build::{
|
||||
get_config_opt, get_config_str, get_language_with_profile, get_list_with_profile,
|
||||
get_string_with_profile, resolve_compiler, resolve_pkg_config_flags,
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::core::config::Config;
|
||||
use crate::core::build_config::Config;
|
||||
use crate::utils::log::error;
|
||||
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, printc};
|
||||
use std::collections::HashSet;
|
||||
|
||||
Reference in New Issue
Block a user