Compare commits
2 Commits
v1.1.0
...
b541865ff1
| Author | SHA1 | Date | |
|---|---|---|---|
| b541865ff1 | |||
| 03bc56007f |
68
Cargo.lock
generated
68
Cargo.lock
generated
@@ -84,15 +84,6 @@ dependencies = [
|
|||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "block2"
|
|
||||||
version = "0.6.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5"
|
|
||||||
dependencies = [
|
|
||||||
"objc2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytes"
|
name = "bytes"
|
||||||
version = "1.11.1"
|
version = "1.11.1"
|
||||||
@@ -105,12 +96,6 @@ version = "1.0.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfg_aliases"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.6.0"
|
version = "4.6.0"
|
||||||
@@ -204,17 +189,6 @@ dependencies = [
|
|||||||
"typenum",
|
"typenum",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ctrlc"
|
|
||||||
version = "3.5.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e0b1fab2ae45819af2d0731d60f2afe17227ebb1a1538a236da84c93e9a60162"
|
|
||||||
dependencies = [
|
|
||||||
"dispatch2",
|
|
||||||
"nix",
|
|
||||||
"windows-sys 0.61.2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "digest"
|
name = "digest"
|
||||||
version = "0.10.7"
|
version = "0.10.7"
|
||||||
@@ -225,18 +199,6 @@ dependencies = [
|
|||||||
"crypto-common",
|
"crypto-common",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dispatch2"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1e0e367e4e7da84520dedcac1901e4da967309406d1e51017ae1abfb97adbd38"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 2.11.0",
|
|
||||||
"block2",
|
|
||||||
"libc",
|
|
||||||
"objc2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "equivalent"
|
name = "equivalent"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
@@ -378,18 +340,6 @@ dependencies = [
|
|||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "nix"
|
|
||||||
version = "0.31.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5d6d0705320c1e6ba1d912b5e37cf18071b6c2e9b7fa8215a1e8a7651966f5d3"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 2.11.0",
|
|
||||||
"cfg-if",
|
|
||||||
"cfg_aliases",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "notify"
|
name = "notify"
|
||||||
version = "8.2.0"
|
version = "8.2.0"
|
||||||
@@ -417,21 +367,6 @@ dependencies = [
|
|||||||
"bitflags 2.11.0",
|
"bitflags 2.11.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "objc2"
|
|
||||||
version = "0.6.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3a12a8ed07aefc768292f076dc3ac8c48f3781c8f2d5851dd3d98950e8c5a89f"
|
|
||||||
dependencies = [
|
|
||||||
"objc2-encode",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "objc2-encode"
|
|
||||||
version = "4.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell_polyfill"
|
name = "once_cell_polyfill"
|
||||||
version = "1.70.2"
|
version = "1.70.2"
|
||||||
@@ -440,13 +375,12 @@ checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pallet"
|
name = "pallet"
|
||||||
version = "1.1.0"
|
version = "1.0.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"clap_complete",
|
"clap_complete",
|
||||||
"clap_complete_nushell",
|
"clap_complete_nushell",
|
||||||
"colored",
|
"colored",
|
||||||
"ctrlc",
|
|
||||||
"glob",
|
"glob",
|
||||||
"notify",
|
"notify",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "pallet"
|
name = "pallet"
|
||||||
version = "1.1.0"
|
version = "1.0.6"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
description = "A project manager and build system for C inspired by Rust's Cargo"
|
description = "A project manager and build system for C inspired by Rust's Cargo"
|
||||||
|
|
||||||
@@ -9,7 +9,6 @@ clap = { version = "4.6.0", features = ["derive"] }
|
|||||||
clap_complete = "4.6.0"
|
clap_complete = "4.6.0"
|
||||||
clap_complete_nushell = "4.6.0"
|
clap_complete_nushell = "4.6.0"
|
||||||
colored = "3.1.1"
|
colored = "3.1.1"
|
||||||
ctrlc = "3.5.2"
|
|
||||||
glob = "0.3.3"
|
glob = "0.3.3"
|
||||||
notify = "8.2.0"
|
notify = "8.2.0"
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
|
|||||||
4
PKGBUILD
4
PKGBUILD
@@ -1,12 +1,12 @@
|
|||||||
# Maintainer: Shea Frembling <sfrembling@gmail.com>
|
# Maintainer: Shea Frembling <sfrembling@gmail.com>
|
||||||
pkgname=pallet
|
pkgname=pallet
|
||||||
pkgver=1.1.0
|
pkgver=1.0.6
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc="A simple C project manager inspired by Cargo"
|
pkgdesc="A simple C project manager inspired by Cargo"
|
||||||
arch=('x86_64')
|
arch=('x86_64')
|
||||||
url=""
|
url=""
|
||||||
license=('MIT')
|
license=('MIT')
|
||||||
depends=('gcc' 'pkgconf' 'clang')
|
depends=('gcc' 'pkgconf')
|
||||||
makedepends=('rust' 'cargo')
|
makedepends=('rust' 'cargo')
|
||||||
source=()
|
source=()
|
||||||
|
|
||||||
|
|||||||
171
src/app.rs
171
src/app.rs
@@ -2,7 +2,6 @@ use std::{
|
|||||||
env::set_current_dir,
|
env::set_current_dir,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::Command,
|
process::Command,
|
||||||
sync::{Arc, atomic::Ordering},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use clap::CommandFactory;
|
use clap::CommandFactory;
|
||||||
@@ -10,9 +9,7 @@ use colored::Colorize;
|
|||||||
use glob::glob;
|
use glob::glob;
|
||||||
|
|
||||||
const MAIN_C: &str = include_str!("templates/main.c");
|
const MAIN_C: &str = include_str!("templates/main.c");
|
||||||
const GITIGNORE: &str = include_str!("templates/.gitignore");
|
const GITIGNORE: &str = "target/\ncompile_commands.json\n";
|
||||||
const CLANG_FORMAT: &str = include_str!("templates/.clang-format");
|
|
||||||
const CLANG_TIDY: &str = include_str!("templates/.clang-tidy");
|
|
||||||
|
|
||||||
#[derive(clap::Parser)]
|
#[derive(clap::Parser)]
|
||||||
#[clap(version, about)]
|
#[clap(version, about)]
|
||||||
@@ -58,7 +55,7 @@ enum Subcommand {
|
|||||||
},
|
},
|
||||||
/// List available build modes
|
/// List available build modes
|
||||||
List,
|
List,
|
||||||
/// Add a new package to the project (through pkg-config)
|
/// Add a new package to the project (throguh pkg-config)
|
||||||
Add {
|
Add {
|
||||||
/// The package to be added
|
/// The package to be added
|
||||||
package: String,
|
package: String,
|
||||||
@@ -71,15 +68,6 @@ enum Subcommand {
|
|||||||
#[arg(long, short)]
|
#[arg(long, short)]
|
||||||
args: Option<Vec<String>>,
|
args: Option<Vec<String>>,
|
||||||
},
|
},
|
||||||
/// Removes a package from the project (through pkg-config)
|
|
||||||
Remove {
|
|
||||||
/// The package to remove
|
|
||||||
package: String,
|
|
||||||
},
|
|
||||||
/// Format C source code using clang-format
|
|
||||||
Fmt,
|
|
||||||
/// Lint C source code using clang-tidy
|
|
||||||
Lint,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(clap::Subcommand)]
|
#[derive(clap::Subcommand)]
|
||||||
@@ -212,92 +200,31 @@ impl App {
|
|||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Subcommand::Remove { package } => {
|
|
||||||
if let Err(e) = remove(&package) {
|
|
||||||
eprintln!("Error removing package {package} from project: {e}");
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Subcommand::Fmt => {
|
|
||||||
if let Err(e) = fmt() {
|
|
||||||
eprintln!("Error formatting project: {e}");
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Subcommand::Lint => {
|
|
||||||
if let Err(e) = lint() {
|
|
||||||
eprintln!("Error linting project: {e}");
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn remove(package: &str) -> std::io::Result<()> {
|
|
||||||
let mut conf = get_config().ok_or(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::NotFound,
|
|
||||||
"no Pallet.toml found in local directory",
|
|
||||||
))?;
|
|
||||||
|
|
||||||
let deps = conf.dependencies.get_or_insert_with(Vec::new);
|
|
||||||
|
|
||||||
if let Some(index) = deps.iter().position(|dep| dep == package) {
|
|
||||||
deps.remove(index);
|
|
||||||
} else {
|
|
||||||
println!(
|
|
||||||
" {} package {package} not found in Pallet.toml, no change made",
|
|
||||||
"Warning".yellow().bold()
|
|
||||||
);
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::fs::write(
|
|
||||||
"Pallet.toml",
|
|
||||||
toml::to_string_pretty(&conf).expect("valid TOML"),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
println!(
|
|
||||||
" {} removed package {package}",
|
|
||||||
"Successfully".green().bold()
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn watch(mode: &Option<String>, args: Option<Vec<String>>) -> std::io::Result<()> {
|
fn watch(mode: &Option<String>, args: Option<Vec<String>>) -> std::io::Result<()> {
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::sync::Arc;
|
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
|
||||||
|
|
||||||
|
// save terminal state
|
||||||
let mut stdout = std::io::stdout();
|
let mut stdout = std::io::stdout();
|
||||||
|
// enter alternate screen — this is a separate terminal buffer,
|
||||||
// enter alternate screen
|
// exiting it restores everything exactly as it was
|
||||||
write!(stdout, "\x1b[?1049h")?;
|
write!(stdout, "\x1b[?1049h")?;
|
||||||
stdout.flush()?;
|
stdout.flush()?;
|
||||||
|
|
||||||
// set up ctrl+c handler BEFORE doing anything else
|
// make sure we always restore the terminal, even on panic
|
||||||
let running = Arc::new(AtomicBool::new(true));
|
let result = watch_inner(mode, args);
|
||||||
let running_clone = running.clone();
|
|
||||||
ctrlc::set_handler(move || {
|
|
||||||
running_clone.store(false, Ordering::SeqCst);
|
|
||||||
})
|
|
||||||
.map_err(|e| std::io::Error::other(format!("{e}")))?;
|
|
||||||
|
|
||||||
let result = watch_inner(mode, args, running);
|
// exit alternate screen
|
||||||
|
|
||||||
// exit alternate screen — guaranteed to run now
|
|
||||||
write!(stdout, "\x1b[?1049l")?;
|
write!(stdout, "\x1b[?1049l")?;
|
||||||
stdout.flush()?;
|
stdout.flush()?;
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn watch_inner(
|
fn watch_inner(mode: &Option<String>, args: Option<Vec<String>>) -> std::io::Result<()> {
|
||||||
mode: &Option<String>,
|
|
||||||
args: Option<Vec<String>>,
|
|
||||||
running: Arc<std::sync::atomic::AtomicBool>,
|
|
||||||
) -> std::io::Result<()> {
|
|
||||||
use notify::{Event, RecursiveMode, Watcher, recommended_watcher};
|
use notify::{Event, RecursiveMode, Watcher, recommended_watcher};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
@@ -367,8 +294,8 @@ fn watch_inner(
|
|||||||
.checked_sub(Duration::from_secs(1))
|
.checked_sub(Duration::from_secs(1))
|
||||||
.unwrap_or(Instant::now());
|
.unwrap_or(Instant::now());
|
||||||
|
|
||||||
while running.load(Ordering::SeqCst) {
|
loop {
|
||||||
match rx.recv_timeout(Duration::from_millis(100)) {
|
match rx.recv() {
|
||||||
Ok(Ok(event)) => {
|
Ok(Ok(event)) => {
|
||||||
let is_relevant = matches!(
|
let is_relevant = matches!(
|
||||||
event.kind,
|
event.kind,
|
||||||
@@ -405,8 +332,10 @@ fn watch_inner(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Err(e)) => eprintln!(" {} watch error: {e}", "Error".red().bold()),
|
Ok(Err(e)) => eprintln!(" {} watch error: {e}", "Error".red().bold()),
|
||||||
Err(mpsc::RecvTimeoutError::Timeout) => continue, // check running flag and loop
|
Err(e) => {
|
||||||
Err(mpsc::RecvTimeoutError::Disconnected) => break,
|
eprintln!(" {} channel error: {e}", "Error".red().bold());
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -560,8 +489,6 @@ fn create_project<P: AsRef<Path>>(directory: P) -> std::io::Result<()> {
|
|||||||
|
|
||||||
std::fs::write("src/main.c", MAIN_C)?;
|
std::fs::write("src/main.c", MAIN_C)?;
|
||||||
std::fs::write(".gitignore", GITIGNORE)?;
|
std::fs::write(".gitignore", GITIGNORE)?;
|
||||||
std::fs::write(".clang-tidy", CLANG_TIDY)?;
|
|
||||||
std::fs::write(".clang-format", CLANG_FORMAT)?;
|
|
||||||
|
|
||||||
let lossy = pathdir.to_string_lossy();
|
let lossy = pathdir.to_string_lossy();
|
||||||
|
|
||||||
@@ -812,71 +739,3 @@ fn clean() -> std::io::Result<()> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt() -> std::io::Result<()> {
|
|
||||||
let source_files: Vec<PathBuf> = glob("src/*.c")
|
|
||||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::NotFound, format!("{e}")))?
|
|
||||||
.chain(
|
|
||||||
glob("src/*.h")
|
|
||||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::NotFound, format!("{e}")))?,
|
|
||||||
)
|
|
||||||
.filter_map(|e| e.ok())
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let status = Command::new("clang-format")
|
|
||||||
.arg("-i")
|
|
||||||
.args(&source_files)
|
|
||||||
.status()
|
|
||||||
.map_err(|_| {
|
|
||||||
std::io::Error::new(
|
|
||||||
std::io::ErrorKind::NotFound,
|
|
||||||
"clang-format not found — try installing it (e.g. sudo pacman -S clang)",
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
if !status.success() {
|
|
||||||
return Err(std::io::Error::other("clang-format failed"));
|
|
||||||
}
|
|
||||||
|
|
||||||
println!(" {} all source files", "Formatted".green().bold());
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn lint() -> std::io::Result<()> {
|
|
||||||
gen_compile_commands(&None)?;
|
|
||||||
|
|
||||||
let source_files: Vec<PathBuf> = glob("src/*.c")
|
|
||||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::NotFound, format!("{e}")))?
|
|
||||||
.filter_map(|e| e.ok())
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let mut any_warnings = false;
|
|
||||||
|
|
||||||
for src in &source_files {
|
|
||||||
println!(" {} {}", "Linting".green().bold(), src.display());
|
|
||||||
|
|
||||||
let status = Command::new("clang-tidy")
|
|
||||||
.arg(src)
|
|
||||||
.arg("--use-color")
|
|
||||||
.status()
|
|
||||||
.map_err(|_| {
|
|
||||||
std::io::Error::new(
|
|
||||||
std::io::ErrorKind::NotFound,
|
|
||||||
"clang-tidy not found — try installing it (e.g. sudo pacman -S clang)",
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
if !status.success() {
|
|
||||||
any_warnings = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if any_warnings {
|
|
||||||
println!("\n {} lint warnings found", "Warning".yellow().bold());
|
|
||||||
} else {
|
|
||||||
println!("\n {} no issues found", "Finished".green().bold());
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
BasedOnStyle: LLVM
|
|
||||||
IndentWidth: 4
|
|
||||||
TabWidth: 4
|
|
||||||
UseTab: Never
|
|
||||||
ColumnLimit: 100
|
|
||||||
|
|
||||||
BreakBeforeBraces: Attach
|
|
||||||
BraceWrapping:
|
|
||||||
AfterFunction: false
|
|
||||||
AfterControlStatement: false
|
|
||||||
|
|
||||||
SpaceAfterCStyleCast: false
|
|
||||||
SpaceBeforeParens: ControlStatements
|
|
||||||
SpaceInEmptyParentheses: false
|
|
||||||
SpacesInCStyleCastParentheses: false
|
|
||||||
|
|
||||||
AlignConsecutiveAssignments: Consecutive
|
|
||||||
AlignConsecutiveDeclarations: Consecutive
|
|
||||||
|
|
||||||
PointerAlignment: Right
|
|
||||||
|
|
||||||
SortIncludes: CaseSensitive
|
|
||||||
IncludeBlocks: Regroup
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
Checks: "clang-diagnostic-*,clang-analyzer-*"
|
|
||||||
WarningsAsErrors: ""
|
|
||||||
2
src/templates/.gitignore
vendored
2
src/templates/.gitignore
vendored
@@ -1,2 +0,0 @@
|
|||||||
target/
|
|
||||||
compile_commands.json
|
|
||||||
Reference in New Issue
Block a user