Browse files

Print each deprecation message only once per compilation. Fixes #678

  • Loading branch information...
1 parent f3d97f3 commit fbfc9b087963b3d2e041ff62de50171011b8fd18 @kintel kintel committed Mar 3, 2014
Showing with 33 additions and 12 deletions.
  1. +1 −1 src/control.cc
  2. +1 −1 src/fileutils.cc
  3. +2 −2 src/import.cc
  4. +1 −1 src/linearextrude.cc
  5. +1 −0 src/mainwin.cc
  6. +1 −1 src/modcontext.cc
  7. +2 −2 src/openscad.cc
  8. +1 −1 src/primitives.cc
  9. +17 −0 src/printutils.cc
  10. +4 −1 src/printutils.h
  11. +1 −1 src/rotateextrude.cc
  12. +1 −1 src/value.cc
View
2 src/control.cc
@@ -161,7 +161,7 @@ AbstractNode *ControlModule::instantiate(const Context* /*ctx*/, const ModuleIns
if (type == CHILD)
{
- PRINT("DEPRECATED: child() will be removed in future releases. Use children() instead.");
+ printDeprecation("DEPRECATED: child() will be removed in future releases. Use children() instead.");
int n = 0;
if (evalctx->numArgs() > 0) {
double v;
View
2 src/fileutils.cc
@@ -22,7 +22,7 @@ std::string lookup_file(const std::string &filename,
if (!fs::exists(absfile) && fs::exists(absfile_fallback)) {
resultfile = absfile_fallback.string();
- PRINTB("WARNING: Imported file (%s) found in document root instead of relative to the importing module. This behavior is deprecated", filename);
+ PRINT_DEPRECATION("DEPRECATED: Imported file (%s) found in document root instead of relative to the importing module. This behavior is deprecated", filename);
}
else {
resultfile = absfile.string();
View
4 src/import.cc
@@ -95,7 +95,7 @@ AbstractNode *ImportModule::instantiate(const Context *ctx, const ModuleInstanti
if (v.isUndefined()) {
v = c.lookup_variable("filename");
if (!v.isUndefined()) {
- PRINT("DEPRECATED: filename= is deprecated. Please use file=");
+ printDeprecation("DEPRECATED: filename= is deprecated. Please use file=");
}
}
std::string filename = lookup_file(v.isUndefined() ? "" : v.toString(), inst->path(), ctx->documentPath());
@@ -119,7 +119,7 @@ AbstractNode *ImportModule::instantiate(const Context *ctx, const ModuleInstanti
if (layerval.isUndefined()) {
layerval = c.lookup_variable("layername");
if (!layerval.isUndefined()) {
- PRINT("DEPRECATED: layername= is deprecated. Please use layer=");
+ printDeprecation("DEPRECATED: layername= is deprecated. Please use layer=");
}
}
node->layername = layerval.isUndefined() ? "" : layerval.toString();
View
2 src/linearextrude.cc
@@ -74,7 +74,7 @@ AbstractNode *LinearExtrudeModule::instantiate(const Context *ctx, const ModuleI
Value slices = c.lookup_variable("slices", true);
if (!file.isUndefined() && file.type() == Value::STRING) {
- PRINT("DEPRECATED: Support for reading files in linear_extrude will be removed in future releases. Use a child import() instead.");
+ printDeprecation("DEPRECATED: Support for reading files in linear_extrude will be removed in future releases. Use a child import() instead.");
node->filename = lookup_file(file.toString(), inst->path(), c.documentPath());
}
View
1 src/mainwin.cc
@@ -1313,6 +1313,7 @@ bool MainWindow::fileChangedOnDisk()
void MainWindow::compileTopLevelDocument()
{
updateTemporalVariables();
+ resetPrintedDeprecations();
this->last_compiled_doc = editor->toPlainText();
std::string fulltext =
View
2 src/modcontext.cc
@@ -115,7 +115,7 @@ const AbstractModule *ModuleContext::findLocalModule(const std::string &name) co
}
std::string replacement = Builtins::instance()->isDeprecated(name);
if (!replacement.empty()) {
- PRINTB("DEPRECATED: The %s() module will be removed in future releases. Use %s() instead.", name % replacement);
+ PRINT_DEPRECATION("DEPRECATED: The %s() module will be removed in future releases. Use %s() instead.", name % replacement);
}
return m;
}
View
4 src/openscad.cc
@@ -651,12 +651,12 @@ int main(int argc, char **argv)
output_file = vm["o"].as<string>().c_str();
}
if (vm.count("s")) {
- PRINT("DEPRECATED: The -s option is deprecated. Use -o instead.\n");
+ printDeprecation("DEPRECATED: The -s option is deprecated. Use -o instead.\n");
if (output_file) help(argv[0]);
output_file = vm["s"].as<string>().c_str();
}
if (vm.count("x")) {
- PRINT("DEPRECATED: The -x option is deprecated. Use -o instead.\n");
+ printDeprecation("DEPRECATED: The -x option is deprecated. Use -o instead.\n");
if (output_file) help(argv[0]);
output_file = vm["x"].as<string>().c_str();
}
View
2 src/primitives.cc
@@ -245,7 +245,7 @@ AbstractNode *PrimitiveModule::instantiate(const Context *ctx, const ModuleInsta
// backwards compatable
node->faces = c.lookup_variable("triangles");
if (node->faces.type() != Value::UNDEFINED) {
- PRINT("DEPRECATED: polyhedron(triangles=[]) will be removed in future releases. Use polyhedron(faces=[]) instead.");
+ printDeprecation("DEPRECATED: polyhedron(triangles=[]) will be removed in future releases. Use polyhedron(faces=[]) instead.");
}
}
}
View
17 src/printutils.cc
@@ -69,3 +69,20 @@ std::string two_digit_exp_format( double x )
s << x;
return two_digit_exp_format( s.str() );
}
+
+#include <set>
+
+std::set<std::string> printedDeprecations;
+
+void printDeprecation(const std::string &str)
+{
+ if (printedDeprecations.find(str) == printedDeprecations.end()) {
+ PRINT(str);
+ printedDeprecations.insert(str);
+ }
+}
+
+void resetPrintedDeprecations()
+{
+ printedDeprecations.clear();
+}
View
5 src/printutils.h
@@ -15,6 +15,10 @@ void set_output_handler(OutputHandlerFunc *newhandler, void *userdata);
extern std::list<std::string> print_messages_stack;
void print_messages_push();
void print_messages_pop();
+void printDeprecation(const std::string &str);
+void resetPrintedDeprecations();
+
+#define PRINT_DEPRECATION(_fmt, _arg) do { printDeprecation(str(boost::format(_fmt) % _arg)); } while (0)
void PRINT(const std::string &msg);
#define PRINTB(_fmt, _arg) do { PRINT(str(boost::format(_fmt) % _arg)); } while (0)
@@ -49,5 +53,4 @@ class logstream
}
};
-
#endif
View
2 src/rotateextrude.cc
@@ -69,7 +69,7 @@ AbstractNode *RotateExtrudeModule::instantiate(const Context *ctx, const ModuleI
Value scale = c.lookup_variable("scale", true);
if (!file.isUndefined()) {
- PRINT("DEPRECATED: Support for reading files in rotate_extrude will be removed in future releases. Use a child import() instead.");
+ printDeprecation("DEPRECATED: Support for reading files in rotate_extrude will be removed in future releases. Use a child import() instead.");
node->filename = lookup_file(file.toString(), inst->path(), c.documentPath());
}
View
2 src/value.cc
@@ -641,7 +641,7 @@ Value Value::operator[](const Value &v)
void Value::RangeType::normalize() {
if ((step_val>0) && (end_val < begin_val)) {
std::swap(begin_val,end_val);
- PRINT("DEPRECATED: Using ranges of the form [begin:end] with begin value greater than the end value is deprecated.");
+ printDeprecation("DEPRECATED: Using ranges of the form [begin:end] with begin value greater than the end value is deprecated.");
}
}

0 comments on commit fbfc9b0

Please sign in to comment.