@@ -474,9 +474,6 @@ where
474
474
. grammar_path
475
475
. as_ref ( )
476
476
. 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
- }
480
477
let outp = self
481
478
. output_path
482
479
. as_ref ( )
@@ -602,13 +599,8 @@ where
602
599
if FileTime :: from_last_modification_time ( out_rs_md)
603
600
> FileTime :: from_last_modification_time ( inmd)
604
601
{
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 ( ) ) {
612
604
return Ok ( CTParser {
613
605
regenerated : false ,
614
606
rule_ids,
@@ -617,6 +609,8 @@ where
617
609
} else {
618
610
#[ cfg( grmtools_extra_checks) ]
619
611
if std:: env:: var ( "CACHE_EXPECTED" ) . is_ok ( ) {
612
+ eprintln ! ( "outc: {}" , outc) ;
613
+ eprintln ! ( "using cache: {}" , cache, ) ;
620
614
// Primarily for use in the testsuite.
621
615
panic ! ( "The cache regenerated however, it was expected to match" ) ;
622
616
}
@@ -647,7 +641,20 @@ where
647
641
}
648
642
}
649
643
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
+ ) ?;
651
658
let conflicts = if stable. conflicts ( ) . is_some ( ) {
652
659
Some ( ( grm, sgraph, stable) )
653
660
} else {
@@ -865,31 +872,22 @@ where
865
872
) )
866
873
} )
867
874
. 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)
893
891
}
894
892
895
893
/// Generate the main parse() function for the output file.
0 commit comments