Skip to content

Commit 6ec4291

Browse files
authored
Merge pull request #525 from ratmice/fix_cache_check
Fix cache check
2 parents b5017c1 + 93028a5 commit 6ec4291

File tree

3 files changed

+38
-43
lines changed

3 files changed

+38
-43
lines changed

.buildbot.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ root=`pwd`
2525
cd $root/lrlex/examples/calc_manual_lex
2626
echo "2 + 3 * 4" | cargo run | grep "Result: 14"
2727
# Touching these files shouldn't invalidate the cache (via --cfg grmtools_extra_checks)
28-
touch src/main.rs src/calc.y && echo "2 + 3 * 4" | CACHE_EXPECTED=y cargo run | grep "Result: 14"
28+
touch src/main.rs && CACHE_EXPECTED=y cargo build
2929
cd $root/lrpar/examples/calc_actions
3030
echo -n "2 + 3 * 4" | cargo run --package nimbleparse -- src/calc.l src/calc.y -
3131
echo "2 + 3 * 4" | cargo run | grep "Result: 14"
32-
touch src/main.rs src/calc.y && echo "2 + 3 * 4" | CACHE_EXPECTED=y cargo run | grep "Result: 14"
32+
touch src/main.rs && CACHE_EXPECTED=y cargo build
3333
cd $root/lrpar/examples/calc_ast
3434
echo -n "2 + 3 * 4" | cargo run --package nimbleparse -- src/calc.l src/calc.y -
3535
echo "2 + 3 * 4" | cargo run | grep "Result: 14"
36-
touch src/main.rs src/calc.y && echo "2 + 3 * 4" | CACHE_EXPECTED=y cargo run | grep "Result: 14"
36+
touch src/main.rs && CACHE_EXPECTED=y cargo build
3737
cd $root/lrpar/examples/calc_parsetree
3838
echo -n "2 + 3 * 4" | cargo run --package nimbleparse -- src/calc.l src/calc.y -
3939
echo "2 + 3 * 4" | cargo run | grep "Result: 14"
40-
touch src/main.rs src/calc.y && echo "2 + 3 * 4" | CACHE_EXPECTED=y cargo run | grep "Result: 14"
40+
touch src/main.rs && CACHE_EXPECTED=y cargo build
4141
cd $root/lrpar/examples/clone_param
4242
echo -n "1+++" | cargo run --package nimbleparse -- src/param.l src/param.y -
4343
cd $root/lrpar/examples/start_states

lrlex/src/lib/ctbuilder.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,6 @@ where
355355
.lexer_path
356356
.as_ref()
357357
.expect("lexer_path must be specified before processing.");
358-
if std::env::var("OUT_DIR").is_ok() {
359-
println!("cargo:rerun-if-changed={}", lexerp.display());
360-
}
361358
let outp = self
362359
.output_path
363360
.as_ref()

lrpar/src/lib/ctbuilder.rs

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,6 @@ where
474474
.grammar_path
475475
.as_ref()
476476
.expect("grammar_path must be specified before processing.");
477-
if std::env::var("OUT_DIR").is_ok() {
478-
println!("cargo:rerun-if-changed={}", grmp.display());
479-
}
480477
let outp = self
481478
.output_path
482479
.as_ref()
@@ -602,13 +599,8 @@ where
602599
if FileTime::from_last_modification_time(out_rs_md)
603600
> FileTime::from_last_modification_time(inmd)
604601
{
605-
if let Ok(mut outc) = read_to_string(outp) {
606-
// Strip whitespace from the output file and the cache since the copy of
607-
// the cache in the output file may be affected by pretty printing.
608-
let mut cache = cache.to_string();
609-
outc.retain(|c| !c.is_whitespace());
610-
cache.retain(|c| !c.is_whitespace());
611-
if outc.contains(&cache) {
602+
if let Ok(outc) = read_to_string(outp) {
603+
if outc.contains(&cache.to_string()) {
612604
return Ok(CTParser {
613605
regenerated: false,
614606
rule_ids,
@@ -617,6 +609,8 @@ where
617609
} else {
618610
#[cfg(grmtools_extra_checks)]
619611
if std::env::var("CACHE_EXPECTED").is_ok() {
612+
eprintln!("outc: {}", outc);
613+
eprintln!("using cache: {}", cache,);
620614
// Primarily for use in the testsuite.
621615
panic!("The cache regenerated however, it was expected to match");
622616
}
@@ -647,7 +641,20 @@ where
647641
}
648642
}
649643

650-
self.output_file(&grm, &stable, &derived_mod_name, outp, &cache)?;
644+
self.output_file(
645+
&grm,
646+
&stable,
647+
&derived_mod_name,
648+
outp,
649+
&quote! {
650+
// This declaration can be affected by the pretty printer.
651+
// But we would hope the actual cache string is not.
652+
//
653+
// This is emitted for the purposes of performing the cache check.
654+
// on the output source, but is not used by generated parser.
655+
const _: &str = #cache;
656+
},
657+
)?;
651658
let conflicts = if stable.conflicts().is_some() {
652659
Some((grm, sgraph, stable))
653660
} else {
@@ -865,31 +872,22 @@ where
865872
))
866873
})
867874
.collect::<Vec<_>>();
868-
let rule_map_len = rule_map.len();
869-
quote! {
870-
#[allow(unused)]
871-
mod _cache_information_ {
872-
use ::lrpar::{RecoveryKind, Visibility, RustEdition};
873-
use ::cfgrammar::yacc::YaccKind;
874-
875-
const BUILD_TIME: &str = #build_time;
876-
// May differ from `MOD_NAME` by being derived from the grammar path.
877-
const DERIVED_MOD_NAME: &str = #derived_mod_name;
878-
const GRAMMAR_PATH: &str = #grammar_path;
879-
// As explicitly set by the builder.
880-
const MOD_NAME: Option<&str> = #mod_name;
881-
const RECOVERER: RecoveryKind = #recoverer;
882-
const YACC_KIND: YaccKind = #yacckind;
883-
const ERROR_ON_CONFLICTS: bool = #error_on_conflicts;
884-
const SHOW_WARNINGS: bool = #show_warnings;
885-
const WARNINGS_ARE_ERRORS: bool = #warnings_are_errors;
886-
const RUST_EDITION: RustEdition = #rust_edition;
887-
const RULE_IDS_MAP: [(usize, &str); #rule_map_len] = [#(#rule_map,)*];
888-
fn visibility() -> Visibility {
889-
#visibility
890-
}
891-
}
892-
}
875+
let cache_info = quote! {
876+
BUILD_TIME = #build_time
877+
DERIVED_MOD_NAME = #derived_mod_name
878+
GRAMMAR_PATH = #grammar_path
879+
MOD_NAME = #mod_name
880+
RECOVERER = #recoverer
881+
YACC_KIND = #yacckind
882+
ERROR_ON_CONFLICTS = #error_on_conflicts
883+
SHOW_WARNINGS = #show_warnings
884+
WARNINGS_ARE_ERRORS = #warnings_are_errors
885+
RUST_EDITION = #rust_edition
886+
RULE_IDS_MAP = [#(#rule_map,)*]
887+
VISIBILITY = #visibility
888+
};
889+
let cache_info_str = cache_info.to_string();
890+
quote!(#cache_info_str)
893891
}
894892

895893
/// Generate the main parse() function for the output file.

0 commit comments

Comments
 (0)