From 2495df6bab07f14f0eed7062dec17d24599aa838 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sat, 14 Jul 2012 21:57:41 -0400 Subject: Add timestamp to cache key for modules importing files. Fixes #141 diff --git a/src/import.cc b/src/import.cc index 221ee55..9d011b0 100644 --- a/src/import.cc +++ b/src/import.cc @@ -237,6 +237,7 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const std::string ImportNode::toString() const { std::stringstream stream; + fs::path path(this->filename); stream << this->name(); stream << "(file = " << this->filename << ", " @@ -244,7 +245,13 @@ std::string ImportNode::toString() const "origin = [" << std::dec << this->origin_x << ", " << this->origin_y << "], " "scale = " << this->scale << ", " "convexity = " << this->convexity << ", " - "$fn = " << this->fn << ", $fa = " << this->fa << ", $fs = " << this->fs << ")"; + "$fn = " << this->fn << ", $fa = " << this->fa << ", $fs = " << this->fs +#ifndef OPENSCAD_TESTING + // timestamp is needed for caching, but disturbs the test framework + << ", " "timestamp = " << (fs::exists(path) ? fs::last_write_time(path) : 0) +#endif + << ")"; + return stream.str(); } diff --git a/src/linearextrude.cc b/src/linearextrude.cc index 89098da..4d2730c 100644 --- a/src/linearextrude.cc +++ b/src/linearextrude.cc @@ -38,6 +38,9 @@ #include using namespace boost::assign; // bring 'operator+=()' into scope +#include +namespace fs = boost::filesystem; + class LinearExtrudeModule : public AbstractModule { public: @@ -143,11 +146,17 @@ std::string LinearExtrudeNode::toString() const stream << this->name() << "("; if (!this->filename.empty()) { // Ignore deprecated parameters if empty + fs::path path(this->filename); stream << "file = " << this->filename << ", " "layer = " << QuotedString(this->layername) << ", " "origin = [" << this->origin_x << ", " << this->origin_y << "], " - "scale = " << this->scale << ", "; + "scale = " << this->scale << ", " +#ifndef OPENSCAD_TESTING + // timestamp is needed for caching, but disturbs the test framework + << "timestamp = " << (fs::exists(path) ? fs::last_write_time(path) : 0) << ", " +#endif + ; } stream << "height = " << std::dec << this->height << ", " diff --git a/src/rotateextrude.cc b/src/rotateextrude.cc index 10a8ef9..165d03b 100644 --- a/src/rotateextrude.cc +++ b/src/rotateextrude.cc @@ -38,6 +38,9 @@ #include using namespace boost::assign; // bring 'operator+=()' into scope +#include +namespace fs = boost::filesystem; + class RotateExtrudeModule : public AbstractModule { public: @@ -112,11 +115,17 @@ std::string RotateExtrudeNode::toString() const stream << this->name() << "("; if (!this->filename.empty()) { // Ignore deprecated parameters if empty + fs::path path(this->filename); stream << "file = " << this->filename << ", " "layer = " << QuotedString(this->layername) << ", " "origin = [" << std::dec << this->origin_x << ", " << this->origin_y << "], " - "scale = " << this->scale << ", "; + "scale = " << this->scale << ", " +#ifndef OPENSCAD_TESTING + // timestamp is needed for caching, but disturbs the test framework + << "timestamp = " << (fs::exists(path) ? fs::last_write_time(path) : 0) << ", " +#endif + ; } stream << "convexity = " << this->convexity << ", " diff --git a/src/surface.cc b/src/surface.cc index 756ad74..d962e38 100644 --- a/src/surface.cc +++ b/src/surface.cc @@ -43,6 +43,9 @@ #include using namespace boost::assign; // bring 'operator+=()' into scope +#include +namespace fs = boost::filesystem; + class SurfaceModule : public AbstractModule { public: @@ -222,9 +225,15 @@ PolySet *SurfaceNode::evaluate_polyset(class PolySetEvaluator *) const std::string SurfaceNode::toString() const { std::stringstream stream; + fs::path path(this->filename); stream << this->name() << "(file = " << this->filename << ", " - "center = " << (this->center ? "true" : "false") << ")"; + "center = " << (this->center ? "true" : "false") +#ifndef OPENSCAD_TESTING + // timestamp is needed for caching, but disturbs the test framework + << ", " "timestamp = " << (fs::exists(path) ? fs::last_write_time(path) : 0) +#endif + << ")"; return stream.str(); } diff --git a/tests/dumptest.cc b/tests/dumptest.cc index 6851fb1..b75a2e2 100644 --- a/tests/dumptest.cc +++ b/tests/dumptest.cc @@ -132,7 +132,10 @@ int main(int argc, char **argv) fprintf(stderr, "Error: Unable to read back dumped file\n"); exit(1); } - fs::current_path(original_path); + + if (fs::path(filename).has_parent_path()) { + fs::current_path(fs::path(filename).parent_path()); + } AbstractNode::resetIndexCounter(); root_node = root_module->evaluate(&root_ctx, &root_inst); -- cgit v0.10.1