summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/macro_processor/macro_processor.rs11
-rw-r--r--src/skaldpress/main.rs36
2 files changed, 39 insertions, 8 deletions
diff --git a/src/macro_processor/macro_processor.rs b/src/macro_processor/macro_processor.rs
index 93a86af..2e8675f 100644
--- a/src/macro_processor/macro_processor.rs
+++ b/src/macro_processor/macro_processor.rs
@@ -145,7 +145,7 @@ fn smp_builtin_include(
}
/// Include a new file verbatim, don't do ANY additional processing
-fn smp_builtin_include_verbatim (
+fn smp_builtin_include_verbatim(
smp: &mut MacroProcessor,
macro_name: &str,
args: &mut [String],
@@ -264,12 +264,15 @@ enum ParserState {
pub struct MacroProcessor {
/// All currently defined macros in this MacroProcessor
pub macros: HashMap<String, MacroType>,
+ /// All macro invocations that has happened
+ pub macro_invocations: Vec<(String, Vec<String>)>,
}
impl MacroProcessor {
pub fn new() -> Self {
let mut smp = Self {
macros: HashMap::new(),
+ macro_invocations: Vec::new(),
};
smp.define_builtins();
smp
@@ -373,6 +376,12 @@ impl MacroProcessor {
return Ok(out);
};
+ // Log macro invokation
+ // The fact that we are here, does not ensure that the macro is actually expanded into
+ // something useful, just that it exists, and was invoked
+ self.macro_invocations
+ .push((macro_name.to_string(), args.to_vec()));
+
match macro_body {
MacroType::String(body) => {
let mut expanded = body.clone();
diff --git a/src/skaldpress/main.rs b/src/skaldpress/main.rs
index 5e44b8d..a4d40ee 100644
--- a/src/skaldpress/main.rs
+++ b/src/skaldpress/main.rs
@@ -31,6 +31,7 @@ struct CompiledFile {
/// or the file itself if it didn't have a extension
extension: String,
source_path: String,
+ needs_recompilation: bool,
}
/// SMP Macro for processing input with a template
@@ -186,6 +187,15 @@ fn wrap_template(
)
}
+fn needs_recompilation(macro_processor: &MacroProcessor) -> bool {
+ for (macro_name, _) in &macro_processor.macro_invocations {
+ if macro_name == "all_tagged_by" {
+ return true;
+ }
+ }
+ false
+}
+
/// Will attempt to compile a specific file, potentially storing some state about the file
fn compile_file(file_path: &Path, opts: &Opts) -> Result<CompiledFile, SkaldpressError> {
let extension = file_path.extension().unwrap_or(std::ffi::OsStr::new(""));
@@ -230,6 +240,7 @@ fn compile_file(file_path: &Path, opts: &Opts) -> Result<CompiledFile, Skaldpres
metadata: map,
extension: String::from(extension.to_str().unwrap_or("")),
source_path: String::from(file_path.to_str().unwrap_or("")),
+ needs_recompilation: false,
});
}
}
@@ -246,6 +257,7 @@ fn compile_file(file_path: &Path, opts: &Opts) -> Result<CompiledFile, Skaldpres
metadata: map,
extension: String::from(extension.to_str().unwrap_or("")),
source_path: String::from(file_path.to_str().unwrap_or("")),
+ needs_recompilation: needs_recompilation(&macro_processor),
});
};
@@ -263,6 +275,7 @@ fn compile_file(file_path: &Path, opts: &Opts) -> Result<CompiledFile, Skaldpres
metadata: map,
extension: String::from(template_extension),
source_path: String::from(file_path.to_str().unwrap_or("")),
+ needs_recompilation: needs_recompilation(&macro_processor),
})
}
@@ -393,10 +406,20 @@ fn compile_files_in_directory(directory: &Path, opts: &Opts) -> Result<(), Skald
}
};
- let should_compile = (opts.filter.len() == 0)
- || opts
- .filter
- .contains(&path.as_path().to_str().unwrap_or("").to_string());
+ let mut needs_recompilation = false;
+ if let Some(cfile_i) =
+ cached_file_id_by_path(&path.as_path().to_str().unwrap_or("").to_string())
+ {
+ unsafe {
+ needs_recompilation = COMPILED_FILES[cfile_i].needs_recompilation;
+ }
+ }
+
+ let should_compile = (opts.first_run || needs_recompilation)
+ && ((opts.filter.len() == 0)
+ || opts
+ .filter
+ .contains(&path.as_path().to_str().unwrap_or("").to_string()));
if metadata.is_file() && should_compile {
println!("< Compiling {:#?}", path.as_path());
if let Err(e) = compile_file_and_write(path.as_path(), opts) {
@@ -492,9 +515,8 @@ fn main() {
let _ = std::fs::remove_dir_all(Path::new(&opts.build_dir));
println!("Copying static content");
let _ = copy_files_in_directory(Path::new(&opts.static_dir), &opts);
- // Running twice, we should make macro_processor emit list of macros which was executed, such
- // that we can re-compile only the files we need to
- // We should also make some kind of file-list, and only re-compile files which has changed.
+ // Running compilation twice, needed for some macros which depends on compiled content
+ // We should make some kind of file-list, and only re-compile files which has changed.
println!("Compiling content");
let _ = compile_files_in_directory(Path::new(&opts.content_dir), &opts);
println!("Rerun compilation");