Просмотр исходного кода

add 1.11 features: more robust patsubst, fix other bugs

David Rose 23 лет назад
Родитель
Сommit
b89e085397

+ 1 - 1
ppremake/config_msvc.h

@@ -80,5 +80,5 @@
  **         Also be sure to change the version number        **
  **         Also be sure to change the version number        **
  **             at the beginning of configure.in.            **
  **             at the beginning of configure.in.            **
  ****************                              ****************/
  ****************                              ****************/
-#define VERSION "1.1"
+#define VERSION "1.11"
 /****************  UPDATE VERSION NUMBER HERE  ****************/
 /****************  UPDATE VERSION NUMBER HERE  ****************/

+ 1 - 1
ppremake/configure.in

@@ -5,7 +5,7 @@ dnl ****************  UPDATE VERSION NUMBER HERE  ****************
 dnl **         Also be sure to change the version number        **
 dnl **         Also be sure to change the version number        **
 dnl **                at the end of config_msvc.h.              **
 dnl **                at the end of config_msvc.h.              **
 dnl ****************                              ****************
 dnl ****************                              ****************
-AM_INIT_AUTOMAKE(ppremake, 1.1)
+AM_INIT_AUTOMAKE(ppremake, 1.11)
 dnl ****************  UPDATE VERSION NUMBER HERE  ****************
 dnl ****************  UPDATE VERSION NUMBER HERE  ****************
 
 
 AM_CONFIG_HEADER(config.h)
 AM_CONFIG_HEADER(config.h)

+ 16 - 6
ppremake/ppCommandFile.cxx

@@ -801,7 +801,11 @@ handle_endif_command() {
   nest->pop(this);
   nest->pop(this);
 
 
   if (nest->_block != _block_nesting) {
   if (nest->_block != _block_nesting) {
-    cerr << "If block not closed within scoping block.\n";
+    if (nest->_block != (BlockNesting *)NULL) {
+      cerr << "If block not closed within scoping block " << nest->_block->_name << ".\n";
+    } else {
+      cerr << "If block not closed within scoping block " << _block_nesting->_name << ".\n";
+    }
     return false;
     return false;
   }
   }
 
 
@@ -1106,15 +1110,15 @@ handle_output_command() {
   nest->push(this);
   nest->push(this);
 
 
   if (!_in_for) {
   if (!_in_for) {
-    string filename = trim_blanks(_scope->expand_string(nest->_name));
+    Filename filename = trim_blanks(_scope->expand_string(nest->_name));
     if (filename.empty()) {
     if (filename.empty()) {
       cerr << "Attempt to output to empty filename\n";
       cerr << "Attempt to output to empty filename\n";
       return false;
       return false;
     }
     }
     
     
-    if (filename[0] != '/') {
+    if (filename.is_local()) {
       string prefix = _scope->expand_variable("DIRPREFIX");
       string prefix = _scope->expand_variable("DIRPREFIX");
-      filename = prefix + filename;
+      filename = Filename(prefix, filename);
     }
     }
 
 
     nest->_params = filename;
     nest->_params = filename;
@@ -1157,7 +1161,7 @@ handle_end_command() {
   nest->pop(this);
   nest->pop(this);
 
 
   if (nest->_if != _if_nesting) {
   if (nest->_if != _if_nesting) {
-    cerr << "If block not closed within scoping block.\n";
+    cerr << "If block not closed within scoping block " << name << ".\n";
     return false;
     return false;
   }
   }
 
 
@@ -1436,7 +1440,13 @@ handle_mkdir_command() {
     vector<string>::const_iterator wi;
     vector<string>::const_iterator wi;
     for (wi = words.begin(); wi != words.end(); ++wi) {
     for (wi = words.begin(); wi != words.end(); ++wi) {
       Filename dirname(*wi);
       Filename dirname(*wi);
-      Filename filename(*wi, "file");
+
+      if (dirname.is_local()) {
+        string prefix = _scope->expand_variable("DIRPREFIX");
+        dirname = Filename(prefix, dirname);
+      }
+
+      Filename filename(dirname, "file");
       if (!filename.make_dir()) {
       if (!filename.make_dir()) {
         if (!dirname.is_directory()) {
         if (!dirname.is_directory()) {
           cerr << "Unable to create directory " << dirname << "\n";
           cerr << "Unable to create directory " << dirname << "\n";

+ 1 - 0
ppremake/ppDirectory.cxx

@@ -498,6 +498,7 @@ read_depends_file(PPNamedScopes *named_scopes) {
     }
     }
     
     
     named_scopes->set_current(_dirname);
     named_scopes->set_current(_dirname);
+    current_output_directory = this;
     PPCommandFile depends(_scope);
     PPCommandFile depends(_scope);
     if (!depends.read_file(depends_filename)) {
     if (!depends.read_file(depends_filename)) {
       cerr << "Error reading dependency definition file "
       cerr << "Error reading dependency definition file "

+ 15 - 1
ppremake/ppFilenamePattern.cxx

@@ -167,7 +167,21 @@ transform(const string &filename,
       return _prefix;
       return _prefix;
     } else {
     } else {
       string body = transform_from.extract_body(filename);
       string body = transform_from.extract_body(filename);
-      return _prefix + body + _suffix;
+      string result = _prefix + body;
+
+      // Now the suffix might contain more % characters.  Replace all
+      // of them.
+      size_t p = 0;
+      size_t pct = _suffix.find(PATTERN_WILDCARD, p);
+      while (pct != string::npos) {
+        result += _suffix.substr(p, pct - p);
+        result += body;
+        p = pct + 1;
+        pct = _suffix.find(PATTERN_WILDCARD, p);
+      }
+      result += _suffix.substr(p);
+
+      return result;
     }
     }
   }
   }
 
 

+ 6 - 1
ppremake/ppMain.cxx

@@ -104,7 +104,12 @@ read_source(const string &root) {
   }
   }
 
 
   // Now cd to the source root and get the actual path.
   // Now cd to the source root and get the actual path.
-  string osdir = trydir.to_os_specific();
+  string osdir;
+#ifdef HAVE_CYGWIN
+  osdir = trydir;
+#else
+  osdir = trydir.to_os_specific();
+#endif
   if (chdir(osdir.c_str()) < 0) {
   if (chdir(osdir.c_str()) < 0) {
     perror("chdir");
     perror("chdir");
     return false;
     return false;

+ 15 - 8
ppremake/ppScope.cxx

@@ -2023,7 +2023,7 @@ string PPScope::
 expand_patsubst(const string &params, bool separate_words) {
 expand_patsubst(const string &params, bool separate_words) {
   // Split the string up into tokens based on the commas.
   // Split the string up into tokens based on the commas.
   vector<string> tokens;
   vector<string> tokens;
-  tokenize_params(params, tokens, true);
+  tokenize_params(params, tokens, false);
 
 
   if (tokens.size() < 3) {
   if (tokens.size() < 3) {
     cerr << "patsubst requires at least three parameters.\n";
     cerr << "patsubst requires at least three parameters.\n";
@@ -2039,9 +2039,9 @@ expand_patsubst(const string &params, bool separate_words) {
   // only if separate_words is true.
   // only if separate_words is true.
   vector<string> words;
   vector<string> words;
   if (separate_words) {
   if (separate_words) {
-    tokenize_whitespace(tokens.back(), words);
+    tokenize_whitespace(expand_string(tokens.back()), words);
   } else {
   } else {
-    words.push_back(tokens.back());
+    words.push_back(expand_string(tokens.back()));
   }
   }
 
 
   // Build up a vector of from/to patterns.
   // Build up a vector of from/to patterns.
@@ -2053,10 +2053,10 @@ expand_patsubst(const string &params, bool separate_words) {
   size_t i;
   size_t i;
   for (i = 0; i < tokens.size() - 1; i += 2) {
   for (i = 0; i < tokens.size() - 1; i += 2) {
     // Each "from" pattern might be a collection of patterns separated
     // Each "from" pattern might be a collection of patterns separated
-    // by spaces.
+    // by spaces, and it is expanded immediately.
     from.push_back(Patterns());
     from.push_back(Patterns());
     vector<string> froms;
     vector<string> froms;
-    tokenize_whitespace(tokens[i], froms);
+    tokenize_whitespace(expand_string(tokens[i]), froms);
     vector<string>::const_iterator fi;
     vector<string>::const_iterator fi;
     for (fi = froms.begin(); fi != froms.end(); ++fi) {
     for (fi = froms.begin(); fi != froms.end(); ++fi) {
       PPFilenamePattern pattern(*fi);
       PPFilenamePattern pattern(*fi);
@@ -2068,8 +2068,14 @@ expand_patsubst(const string &params, bool separate_words) {
       from.back().push_back(pattern);
       from.back().push_back(pattern);
     }
     }
 
 
-    // However, the corresponding "to" pattern is just one pattern.
-    to.push_back(PPFilenamePattern(tokens[i + 1]));
+    // However, the corresponding "to" pattern is just one pattern,
+    // and it is expanded immediately only if it does not contain a
+    // wildcard character.
+    PPFilenamePattern to_pattern(tokens[i + 1]);
+    if (!to_pattern.has_wildcard()) {
+      to_pattern = PPFilenamePattern(expand_string(tokens[i + 1]));
+    }
+    to.push_back(to_pattern);
   }
   }
   size_t num_patterns = from.size();
   size_t num_patterns = from.size();
   assert(num_patterns == to.size());
   assert(num_patterns == to.size());
@@ -2082,7 +2088,8 @@ expand_patsubst(const string &params, bool separate_words) {
       for (pi = from[i].begin(); pi != from[i].end() && !matched; ++pi) {
       for (pi = from[i].begin(); pi != from[i].end() && !matched; ++pi) {
         if ((*pi).matches(*wi)) {
         if ((*pi).matches(*wi)) {
           matched = true;
           matched = true;
-          (*wi) = to[i].transform(*wi, (*pi));
+          string transformed = to[i].transform(*wi, (*pi));
+          (*wi) = expand_string(transformed);
         }
         }
       }
       }
     }
     }