From 3ddbfeafde93d1aab16a710498d86eef4e787406 Mon Sep 17 00:00:00 2001 From: Michael Krelin Date: Wed, 30 Mar 2005 15:50:28 +0000 Subject: 1. preprocessor doesn't touch unchanged files anymore 2. doublechedk on whether file is up to date when making 3. changed the way preprocessor targets depend on the timestamp file 4. a bugfix in strip_suffix/strip_prefix --- diff --git a/include/sitecing/sitecing_enflesher.h b/include/sitecing/sitecing_enflesher.h index 512a358..8bc43a0 100644 --- a/include/sitecing/sitecing_enflesher.h +++ b/include/sitecing/sitecing_enflesher.h @@ -42,6 +42,11 @@ class sitecing_enflesher : public sitecing_enflesherFlexLexer { * The output stream. */ ofstream outs; + /** + * the outs stream destination file. + * @see outs + */ + string outs_filename; /** * @param p The parser object containing preparsed data. @@ -61,6 +66,14 @@ class sitecing_enflesher : public sitecing_enflesherFlexLexer { * Put a #line anchor into output. */ void anchor(); + + /** + * Close previously opened output stream, rename to the 'correct' + * destination filename, if needed, and open new file. + * @see outs + * @see outs_filename + */ + void outs_open(const string& nfile); }; #endif /* __SITECING_SITECING_ENFLESHER_H */ diff --git a/lib/component_factory.cc b/lib/component_factory.cc index f8666dc..b8f5a16 100644 --- a/lib/component_factory.cc +++ b/lib/component_factory.cc @@ -19,7 +19,7 @@ namespace sitecing { - static const char *pp_targets[] = { ".cc", ".h", ".imports", ".classname", ".baseclassname", ".ancestors" }; + static const char *pp_targets[] = { ".cc", ".h", ".imports", ".classname", ".baseclassname", ".ancestors", ".pp_stamp" }; static const char *cc_targets[] = { ".o", ".d" }; component_factory::component_factory(configuration& c) @@ -116,15 +116,20 @@ namespace sitecing { string dp = normalize_path(dst,strip_trailing_slash); // XXX: or just compare it off, instead of throwing things around. try { - strip_prefix(dp,root_intermediate); - return file_factory::is_uptodate(dst,deps); - }catch(utility_no_prefix& unp) { - } + string noro = strip_prefix(dp,root_intermediate); + for(int ppt=0;(ppt+1)sizeof(t1)) + rb = sizeof(t1); + if(i_s.read(t1,rb).gcount()!=rb) + throw preprocessor_error(CODEPOINT,"error reading just created file"); + if(i_d.read(t2,rb).gcount()!=rb) + throw preprocessor_error(CODEPOINT,"error reading the old preprocessed source"); + if(memcmp(t1,t2,rb)) { + overwrite = true; + break; + } + remaining -= rb; + } + } + } + if(overwrite) { + cerr << "renaming '" << fn_s << "'" << endl; + if(rename(fn_s.c_str(),fn_d.c_str())) + throw preprocessor_error(CODEPOINT,"failed to rename() generated output"); + } + } + outs_filename = nfile; + outs.open((nfile+".new").c_str(),ios::trunc); + if(!outs.good()) + throw preprocessor_error(CODEPOINT,"failed to write preprocessor output"); +} /* * vim:set ft=lex: */ diff --git a/lib/sitecing_util.cc b/lib/sitecing_util.cc index 5466b28..f892a60 100644 --- a/lib/sitecing_util.cc +++ b/lib/sitecing_util.cc @@ -56,13 +56,13 @@ namespace sitecing { } string strip_prefix(const string& str,const string& prefix) { - if(str.compare(0,prefix.length(),prefix)) + if( (str.length()