vsts_version_fixer.cpp

Go to the documentation of this file.
00001 #ifndef VSTS_VERSION_FIXER_IMPLEMENTATION_FILE
00002 #define VSTS_VERSION_FIXER_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : vsts_version_fixer                                                *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2008-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include <basis/function.h>
00019 #include <basis/istring.h>
00020 #include <basis/portable.h>
00021 #include <basis/string_array.h>
00022 #include <data_struct/static_memory_gremlin.h>
00023 #include <opsystem/application_shell.h>
00024 #include <opsystem/byte_filer.h>
00025 #include <opsystem/directory.h>
00026 #include <opsystem/filename.h>
00027 #include <opsystem/version_ini.h>
00028 
00029 #undef LOG
00030 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger(), s)
00031 #undef BASE_LOG
00032 #define BASE_LOG(s) program_wide_logger().log(s)
00033 
00034 //#define DEBUG_VSTS_VERSION_FIXER
00035   // uncomment for noisy version.
00036 
00038 
00039 class vsts_version_fixer : public application_shell
00040 {
00041 public:
00042   vsts_version_fixer() : application_shell(static_class_name()) {}
00043   virtual ~vsts_version_fixer() {}
00044 
00045   virtual int execute();
00046 
00047   IMPLEMENT_CLASS_NAME("vsts_version_fixer");
00048 
00049   void remove_confusing_files();
00051 
00052 //move these
00053   typedef bool spider_method(const directory &current);
00055 
00060 //hmmm: support postfix and in order also.
00061 //hmmm: support reporting where the spidering stopped.
00062   bool spider_directory(directory start, spider_method to_invoke);
00064 
00066 //move those
00067 
00068   bool perform_version_stamping(const directory &start);
00070 
00071   void whack_in_subdirs(const directory &start,
00072       const string_array &file_whacks, const string_array &dir_whacks);
00074 
00078 };
00079 
00080 HOOPLE_MAIN(vsts_version_fixer, )
00081 
00082 
00083 
00084 //hmmm: move to a useful place; maybe even in directory class?
00085 bool vsts_version_fixer::spider_directory(directory start,
00086     spider_method to_invoke)
00087 {
00088   FUNCDEF("spider_directory");
00089 
00090 //LOG(istring("spider_directory: ") + start.path());
00091   // call our method on this directory first.  this ensures that we have
00092   // dealt with it before we spider off elsewhere.
00093   bool ret = to_invoke(start);
00094   if (!ret) return false;  // bail.
00095 
00096   // now let's look at the subdirectories.  we'll recurse on all of them in
00097   // the order listed.
00098   const string_array &dirs = start.directories();
00099   for (int dir_indy = 0; dir_indy < dirs.length(); dir_indy++) {
00100     const istring &current_dir = dirs[dir_indy];
00101 //LOG(istring("currdir into ") + current_dir);
00102     if (current_dir == ".svn") continue;  // skip this.
00103     if (current_dir == "CVS") continue;  // skip this also.
00104     directory new_dir(start.path() + "/" + current_dir,
00105         start.pattern().observe());
00106     bool ret = spider_directory(new_dir, to_invoke);
00107     if (!ret) return false;  // bail from subdir issue.
00108   }
00109   // if we made it to here, everything was groovy.
00110   return true;
00111 }
00112 
00114 
00115 #define static_class_name() "vsts_version_fixer"
00116 
00117 // global variables used to communicate with whacking_spider.
00118 string_array global_file_whacks;
00119 string_array global_dir_whacks;
00120 
00121 bool whacking_spider(const directory &current)
00122 {
00123   FUNCDEF("whacking_spider");
00124 //LOG(istring("whacking_spider: ") + current.path());
00125   // iterate across the files in the directory and check for evil ones.
00126   const string_array &files = current.files();
00127   for (int file_indy = 0; file_indy < files.length(); file_indy++) {
00128     const istring &current_file = files[file_indy];
00129 //LOG(istring("currfile ") + current_file);
00130     // now iterate across our pattern list to see if this thing is
00131     // one of the offending files.
00132     for (int pat_indy = 0; pat_indy < global_file_whacks.length(); pat_indy++) {
00133 //LOG(istring("currpat ") + global_file_whacks[pat_indy]);
00134       if (current_file.iends(global_file_whacks[pat_indy])) {
00135         filename goner(current.path() + "/" + current_file);
00136         BASE_LOG(istring("whack file: ") + goner.raw());
00137         goner.unlink();
00138         break;  // stop looking at the pattern list for matches.
00139       }
00140     }
00141   }
00142 
00143   // okay, now that we've cleaned out those files, let's look at the
00144   // subdirectories.
00145   const string_array &dirs = current.directories();
00146   for (int dir_indy = 0; dir_indy < dirs.length(); dir_indy++) {
00147     const istring &current_dir = dirs[dir_indy];
00148 //LOG(istring("currdir ") + current_dir);
00149     for (int pat_indy = 0; pat_indy < global_dir_whacks.length(); pat_indy++) {
00150       if (current_dir.iequals(global_dir_whacks[pat_indy])) {
00151         filename goner(current.path() + "/" + current_dir);
00152         BASE_LOG(istring("whack dir: ") + goner.raw());
00153 //hmmm: plug in recursive delete here instead.
00154 u_int kid;
00155 portable::launch_process("rm", istring("-rf ") + goner.raw(), portable::AWAIT_APP_EXIT, kid);
00156         break;  // skip remainder of patterns for this dir.
00157       }
00158     }
00159   }
00160   return true;
00161 }
00162 
00163 #undef static_class_name
00164 
00166 
00167 void vsts_version_fixer::whack_in_subdirs(const directory &start,
00168     const string_array &file_whacks, const string_array &dir_whacks)
00169 {
00170   FUNCDEF("whack_in_subdirs");
00171 
00172   // save the lists so the spider method can see them.
00173   // note that this approach with a global variable would be bad if there
00174   // were concurrent invocations of the spidering, but we're not doing
00175   // that here.
00176   global_file_whacks = file_whacks;
00177   global_dir_whacks = dir_whacks;
00178 
00179   bool worked = spider_directory(start, whacking_spider);
00180   if (!worked) {
00181     LOG(istring("spidering of ") + start.path() + " failed for some reason.");
00182   }
00183 }
00184 
00186 
00187 #define static_class_name() "vsts_version_fixer"
00188 
00189 istring global_build_ini;
00190 
00191 bool stamping_spider(const directory &current)
00192 {
00193   FUNCDEF("stamping_spider");
00194 //LOG(istring("stamping_spider: ") + current.path());
00195 
00196   const string_array &files = current.files();
00197   for (int file_indy = 0; file_indy < files.length(); file_indy++) {
00198     const istring &current_file = files[file_indy];
00199 //LOG(istring("currfile ") + current_file);
00200     if (current_file.ends("version.ini")) {
00201 //LOG(istring("found ver file: ") + current.path() + "/" + current_file);
00202       version_ini::one_stop_version_stamp(current.path() + "/" + current_file,
00203           global_build_ini, true);
00204     }
00205   }
00206   return true;
00207 }
00208 
00209 #undef static_class_name
00210 
00212 
00213 bool vsts_version_fixer::perform_version_stamping(const directory &start)
00214 {
00215   FUNCDEF("perform_version_stamping");
00216   return spider_directory(start, stamping_spider);
00217 }
00218 
00220 
00221 void vsts_version_fixer::remove_confusing_files()
00222 {
00223   // clean out a few directories that show up in the source tree from c#
00224   // projects compilation.  c# projects always rebuild every time anyways,
00225   // so this doesn't lose us any compilation time.  the only thing c#
00226   // projects don't ever seem to rebuild is their version resource, unless
00227   // they're forced to totally recompile like we cause below.
00228   directory repo_source(portable::env_string("REPOSITORY_DIR") + "/source");
00229   string_array source_file_whacks;  // none right now.
00230   string_array source_dir_whacks;
00231   source_dir_whacks += "obj";
00232   source_dir_whacks += "Debug";
00233   source_dir_whacks += "Release";
00234   source_dir_whacks += "bin";
00235   source_dir_whacks += "temp_build";
00236   whack_in_subdirs(repo_source, source_file_whacks, source_dir_whacks);
00237 
00238   // now reset but whack the same things in the dsm sdk support.
00239   repo_source = portable::env_string("REPOSITORY_DIR") + "/dsm_sdk";
00240   whack_in_subdirs(repo_source, source_file_whacks, source_dir_whacks);
00241 
00242   // clean out a variety of bad files in the objects hierarchy.
00243   // currently this is just the generated RES files which we have seen cause
00244   // vsts to think apps and dlls are up to date when they are actually not.
00245   directory repo_objects(portable::env_string("REPOSITORY_DIR"));
00246   string_array objects_file_whacks;
00247   objects_file_whacks += ".res";
00248   string_array objects_dir_whacks;  // none right now.
00249   whack_in_subdirs(repo_objects, objects_file_whacks, objects_dir_whacks);
00250 }
00251 
00252 int vsts_version_fixer::execute()
00253 {
00254   log(timestamp(true, true) + "vsts_version_fixer started.");
00255 
00256   remove_confusing_files();
00257 
00258   directory repo_source = portable::env_string("REPOSITORY_DIR") + "/source";
00259   global_build_ini = portable::env_string("REPOSITORY_DIR") + "/build.ini";
00260   perform_version_stamping(repo_source);
00261 
00262   log(timestamp(true, true) + "vsts_version_fixer finished.");
00263   return 0;
00264 }
00265 
00266 #endif
00267 
00268 #ifdef __BUILD_STATIC_APPLICATION__
00269   // static dependencies found by buildor_gen_deps.sh:
00270   #include <basis/array.cpp>
00271   #include <basis/byte_array.cpp>
00272   #include <basis/callstack_tracker.cpp>
00273   #include <basis/chaos.cpp>
00274   #include <basis/convert_utf.cpp>
00275   #include <basis/definitions.cpp>
00276   #include <basis/earth_time.cpp>
00277   #include <basis/guards.cpp>
00278   #include <basis/istring.cpp>
00279   #include <basis/log_base.cpp>
00280   #include <basis/memory_checker.cpp>
00281   #include <basis/mutex.cpp>
00282   #include <basis/object_base.cpp>
00283   #include <basis/outcome.cpp>
00284   #include <basis/packable.cpp>
00285   #include <basis/portable.cpp>
00286   #include <basis/sequence.cpp>
00287   #include <basis/set.cpp>
00288   #include <basis/utility.cpp>
00289   #include <basis/version_record.cpp>
00290   #include <data_struct/amorph.cpp>
00291   #include <data_struct/bit_vector.cpp>
00292   #include <data_struct/byte_hasher.cpp>
00293   #include <data_struct/configurator.cpp>
00294   #include <data_struct/hash_table.cpp>
00295   #include <data_struct/pointer_hash.cpp>
00296   #include <data_struct/stack.cpp>
00297   #include <data_struct/static_memory_gremlin.cpp>
00298   #include <data_struct/string_hash.cpp>
00299   #include <data_struct/string_hasher.cpp>
00300   #include <data_struct/string_table.cpp>
00301   #include <data_struct/symbol_table.cpp>
00302   #include <data_struct/table_configurator.cpp>
00303   #include <loggers/console_logger.cpp>
00304   #include <loggers/file_logger.cpp>
00305   #include <loggers/locked_logger.cpp>
00306   #include <loggers/null_logger.cpp>
00307   #include <loggers/program_wide_logger.cpp>
00308   #include <opsystem/application_base.cpp>
00309   #include <opsystem/application_shell.cpp>
00310   #include <opsystem/byte_filer.cpp>
00311   #include <opsystem/command_line.cpp>
00312   #include <opsystem/critical_events.cpp>
00313   #include <opsystem/directory.cpp>
00314   #include <opsystem/filename.cpp>
00315   #include <opsystem/ini_config.cpp>
00316   #include <opsystem/ini_parser.cpp>
00317   #include <opsystem/path_configuration.cpp>
00318   #include <opsystem/rendezvous.cpp>
00319   #include <opsystem/version_ini.cpp>
00320   #include <textual/byte_format.cpp>
00321   #include <textual/parser_bits.cpp>
00322   #include <textual/string_manipulation.cpp>
00323   #include <textual/tokenizer.cpp>
00324 #endif // __BUILD_STATIC_APPLICATION__
00325 

Generated on Fri Nov 21 04:29:07 2008 for HOOPLE Libraries by  doxygen 1.5.1