Skip to content

Commit

Permalink
[geometry] Fix refine_mesh for cwd-relative paths (#22106)
Browse files Browse the repository at this point in the history
When the user does 'bazel run :refine_mesh' we should still allow a
relative path for input or output. We call chdir here to undo the
chdir performed by 'bazel run' into the runfiles tree.
  • Loading branch information
jwnimmer-tri authored Oct 31, 2024
1 parent 50536db commit 16e7281
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions geometry/proximity/refine_mesh.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include <unistd.h>

#include <cstdlib>
#include <filesystem>

#include <gflags/gflags.h>
Expand Down Expand Up @@ -39,6 +42,14 @@ int do_main(int argc, char* argv[]) {
return 1;
}

// Make cwd be what the user expected, not the runfiles tree.
if (const char* path = std::getenv("BUILD_WORKING_DIRECTORY")) {
const int error = ::chdir(path);
if (error != 0) {
log()->warn("Could not chdir to '{}'", path);
}
}

VolumeMesh<double> mesh =
internal::ReadVtkToVolumeMesh(std::filesystem::path(argv[1]));
std::vector<int> bad_tets =
Expand Down

0 comments on commit 16e7281

Please sign in to comment.