Skip to content

Commit ab1092d

Browse files
committed
skip build flag for quicker iteration
1 parent 9a62d94 commit ab1092d

File tree

3 files changed

+41
-35
lines changed

3 files changed

+41
-35
lines changed

src/analyze.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,26 +84,20 @@ async fn analyze_with_clang(config: Arc<Config>, args: &[String]) -> Result<(),
8484
Ok(())
8585
}
8686

87-
async fn analyze_with_cmake(config: Arc<Config>) -> Result<(), String> {
87+
async fn analyze_with_cmake(config: Arc<Config>, skip_build: bool) -> Result<(), String> {
8888
// Configure the cmake project
89-
cmake::cmake_configure(
90-
&config.cmake.as_ref().unwrap().build_dir,
91-
&config
92-
.cmake
93-
.as_ref()
94-
.unwrap()
95-
.config_args,
96-
)?;
89+
if !skip_build {
90+
cmake::cmake_configure(
91+
&config.cmake.as_ref().unwrap().build_dir,
92+
&config.cmake.as_ref().unwrap().config_args,
93+
)?;
94+
}
9795

9896
// Build the cmake project
99-
if config.cmake.as_ref().unwrap().build {
97+
if !skip_build && config.cmake.as_ref().unwrap().build {
10098
cmake::cmake_build(
10199
&config.cmake.as_ref().unwrap().build_dir,
102-
&config
103-
.cmake
104-
.as_ref()
105-
.unwrap()
106-
.build_args,
100+
&config.cmake.as_ref().unwrap().build_args,
107101
)?;
108102
}
109103

@@ -116,7 +110,7 @@ async fn analyze_with_cmake(config: Arc<Config>) -> Result<(), String> {
116110
Ok(())
117111
}
118112

119-
pub async fn create_docs(config: Arc<Config>) -> Result<(), String> {
113+
pub async fn create_docs(config: Arc<Config>, skip_build: bool) -> Result<(), String> {
120114
// Execute prebuild commands
121115
if let Some(cmds) = config.run.as_ref().map(|c| &c.prebuild) {
122116
for cmd in cmds {
@@ -126,7 +120,7 @@ pub async fn create_docs(config: Arc<Config>) -> Result<(), String> {
126120

127121
// Build based on mode
128122
if config.cmake.is_some() {
129-
analyze_with_cmake(config).await
123+
analyze_with_cmake(config, skip_build).await
130124
}
131125
// Build with extra compile args only
132126
else {

src/cmake.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ impl CompileCommand {
3838
.chain(vec![format!("-working-directory={}", self.directory.to_str().unwrap())])
3939
// Add extra compile args
4040
.chain(config.analysis.compile_args.clone())
41+
// Retain comments from external libraries that might be included in the docs
42+
.chain(vec!["-fretain-comments-from-system-headers".into()])
4143
.collect();
4244

4345
// Passing -c crashes LibClang

src/main.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@
22
#![feature(iter_advance_by)]
33
#![feature(iter_intersperse)]
44

5-
use crate::{analyze::create_docs, url::UrlPath, normalize::Normalize};
5+
use crate::{analyze::create_docs, normalize::Normalize, url::UrlPath};
66
use clap::Parser;
77
use config::Config;
8-
use std::{fs, path::{PathBuf, Path}, process::exit, io, time::Instant};
8+
use std::{
9+
error::Error,
10+
fs, io,
11+
path::{Path, PathBuf},
12+
process::exit,
13+
time::Instant,
14+
};
915

1016
mod analyze;
17+
mod annotation;
1118
mod builder;
1219
mod cmake;
1320
mod config;
1421
mod html;
15-
mod url;
16-
mod normalize;
17-
mod annotation;
1822
mod lookahead;
23+
mod normalize;
24+
mod url;
1925

2026
#[derive(Parser, Debug)]
2127
#[command(name("Flash"), version, about)]
@@ -31,6 +37,10 @@ struct Args {
3137
/// Whether to overwrite output directory if it already exists
3238
#[arg(long, default_value_t = false)]
3339
overwrite: bool,
40+
41+
/// Whether to skip invoking CMake entirely, relies on existing build dir.
42+
#[arg(long, default_value_t = false, hide = true)]
43+
skip_build: bool,
3444
}
3545

3646
fn remove_dir_contents<P: AsRef<Path>>(path: P) -> io::Result<()> {
@@ -49,7 +59,7 @@ fn remove_dir_contents<P: AsRef<Path>>(path: P) -> io::Result<()> {
4959
}
5060

5161
#[tokio::main]
52-
async fn main() -> Result<(), String> {
62+
async fn main() -> Result<(), Box<dyn Error>> {
5363
let args = Args::parse();
5464

5565
// Check if output dir exists
@@ -59,19 +69,15 @@ async fn main() -> Result<(), String> {
5969
// Then overwrite must be specified
6070
&& !args.overwrite
6171
{
62-
println!(
72+
eprintln!(
6373
"Output directory {} already exists and no --overwrite option was specified, aborting",
64-
args.output.to_str().unwrap()
74+
args.output.to_string_lossy()
6575
);
6676
exit(1);
6777
}
6878

69-
// Clear output dir if it exists
70-
if args.output.exists() {
71-
remove_dir_contents(&args.output).unwrap();
72-
}
73-
else {
74-
fs::create_dir_all(&args.output).unwrap();
79+
if !args.output.exists() {
80+
fs::create_dir_all(&args.output)?;
7581
}
7682

7783
let relative_output = if args.output.is_relative() {
@@ -86,12 +92,12 @@ async fn main() -> Result<(), String> {
8692
let full_output = if args.output.is_absolute() {
8793
args.output
8894
} else {
89-
std::env::current_dir().unwrap().join(args.output).normalize()
95+
std::env::current_dir()?.join(args.output).normalize()
9096
};
9197
let full_input = if args.input.is_absolute() {
9298
args.input
9399
} else {
94-
std::env::current_dir().unwrap().join(args.input).normalize()
100+
std::env::current_dir()?.join(args.input).normalize()
95101
};
96102
std::env::set_current_dir(&full_input).expect(
97103
"Unable to set input dir as working directory \
@@ -107,8 +113,12 @@ async fn main() -> Result<(), String> {
107113
conf.project.name, conf.project.version
108114
);
109115
let now = Instant::now();
110-
create_docs(conf.clone()).await?;
111-
println!("Docs built for {} in {}s", conf.project.name, now.elapsed().as_secs());
116+
create_docs(conf.clone(), args.skip_build).await?;
117+
println!(
118+
"Docs built for {} in {}s",
119+
conf.project.name,
120+
now.elapsed().as_secs()
121+
);
112122

113123
Ok(())
114124
}

0 commit comments

Comments
 (0)