Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std::filesystem instead of rcpputils::fs #1576

Merged
merged 5 commits into from
Mar 25, 2024

Conversation

r7vme
Copy link
Contributor

@r7vme r7vme commented Feb 28, 2024

Based on PRs #1478 and #1479

Use std::filesystem instead of rcpputils::fs (ros2/rcpputils#164) in all packages of rosbag2.

The only place where it is still used is TemporaryDirectoryFixture in

temporary_dir_path_ = rcpputils::fs::create_temp_directory("tmp_test_dir_").string();

Because there is no alternative in the standard library

Signed-off-by: Kenta Yonekura <yoneken@ieee.org>
Signed-off-by: Kenta Yonekura <yoneken@ieee.org>
@r7vme r7vme requested a review from a team as a code owner February 28, 2024 15:33
@r7vme r7vme requested review from gbiggs and jhdcs and removed request for a team February 28, 2024 15:33
@clalancette
Copy link
Contributor

Because there is no alternative in the standard library

For what it is worth, the only users of rcpputils::fs::create_temp_directory are here in rosbag2:

temporary_dir_path_ = rcpputils::fs::create_temp_directory("tmp_test_dir_").string();
and
: output_dir_(rcpputils::fs::create_temp_directory("test_bag_rewrite"))
.

Since the goal is to eventually remove rcpputils::fs, I think it is reasonable enough to copy https://github.com/ros2/rcpputils/blob/292be119c13edb8baa1e78c348637c460ad7a846/src/filesystem_helper.cpp#L310-L342 somewhere into this repository.

@r7vme
Copy link
Contributor Author

r7vme commented Feb 29, 2024

@clalancette thanks, done. Do we run CI on Windows? Just want to be sure it works there too

@MichaelOrlov could you also please take a look?

@r7vme
Copy link
Contributor Author

r7vme commented Mar 1, 2024

@fujitatomoya thanks for the comments, addressed

Copy link
Contributor

@MichaelOrlov MichaelOrlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@r7vme Thank you for picking up and finishing this PR. It turns out to be a large PR.
In general, it looks good to me. However, I have a few findings which need to be addressed.
Among a few minor findings which I pointed out in the inline comments there is some missed usage of the rcutils_calculate_directory_size(uri.c_str(), &metadata.bag_size, allocator)) in the

BagMetadata MetadataIo::read_metadata(const std::string & uri)
{
try {
YAML::Node yaml_file = YAML::LoadFile(get_metadata_file_name(uri));
auto metadata = yaml_file["rosbag2_bagfile_information"].as<rosbag2_storage::BagMetadata>();
rcutils_allocator_t allocator = rcutils_get_default_allocator();
if (RCUTILS_RET_OK !=
rcutils_calculate_directory_size(uri.c_str(), &metadata.bag_size, allocator))
{
throw std::runtime_error(
std::string("Exception on calculating the size of directory :") + uri);

which could be replaced by using https://en.cppreference.com/w/cpp/filesystem/file_size instead

@r7vme
Copy link
Contributor Author

r7vme commented Mar 4, 2024

@MichaelOrlov addressed your comments here 0b53db4

Should I squash last 4 commits into one?

@MichaelOrlov
Copy link
Contributor

@r7vme Thank you for addressing most of the comments from the review.
It seems one comment was missed

Among a few minor findings which I pointed out in the inline comments there is some missed usage of the rcutils_calculate_directory_size(uri.c_str(), &metadata.bag_size, allocator)) in the

BagMetadata MetadataIo::read_metadata(const std::string & uri)
{
try {
YAML::Node yaml_file = YAML::LoadFile(get_metadata_file_name(uri));
auto metadata = yaml_file["rosbag2_bagfile_information"].as<rosbag2_storage::BagMetadata>();
rcutils_allocator_t allocator = rcutils_get_default_allocator();
if (RCUTILS_RET_OK !=
rcutils_calculate_directory_size(uri.c_str(), &metadata.bag_size, allocator))
{
throw std::runtime_error(
std::string("Exception on calculating the size of directory :") + uri);

which could be replaced by using https://en.cppreference.com/w/cpp/filesystem/file_size instead

@r7vme r7vme force-pushed the 164-use-std-filesystem branch 3 times, most recently from 956252b to 11ecdd0 Compare March 8, 2024 12:52
@r7vme
Copy link
Contributor Author

r7vme commented Mar 8, 2024

@MichaelOrlov regarding rcutils_calculate_directory_size. Unfortunately there is no alteranative in std::filesystem. std::filesystem::file_size will return filesystem error: cannot get file size: Is a directory on Linux if run for directrory. I would leave this piece as is. But I definitely missed this comment in the first place.

Signed-off-by: Roman Sokolkov <rsokolkov@gmail.com>
@r7vme
Copy link
Contributor Author

r7vme commented Mar 13, 2024

@clalancette @MichaelOrlov looks like Rpr__rosbag2__ubuntu_noble_amd64 fails on all latest PRs with The command '/bin/sh -c pip3 install -U setuptools==59.6.0' returned a non-zero code: 1

@MichaelOrlov
Copy link
Contributor

@r7vme Yeah, we are aware of it. This is a generic issue due to the transition to the Ubuntu 24.04 on Rolling. This issue is going to be addressed sometime soon.

@MichaelOrlov
Copy link
Contributor

@r7vme As regards

Should I squash last 4 commits into one?

Please do not squash commits in the future. It is very helpful for the reviewer to see changes in the separate commits.
We have automatically mandatory squash for all commits in the PR during the final merge to the target branch.

Copy link
Contributor

@MichaelOrlov MichaelOrlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@r7vme Thanks, LGTM!

@MichaelOrlov
Copy link
Contributor

Gist: https://gist.githubusercontent.com/MichaelOrlov/f323f6647c62a2395c5006aa68777d14/raw/fa6e1966d9c3fc82d4d4eeb990dd9e3461fe97b8/ros2.repos
BUILD args: --packages-above-and-dependencies rosbag2_compression rosbag2_compression_zstd rosbag2_cpp rosbag2_storage rosbag2_test_common rosbag2_transport rosbag2_tests
TEST args: --packages-above rosbag2_compression rosbag2_compression_zstd rosbag2_cpp rosbag2_storage rosbag2_test_common rosbag2_transport rosbag2_tests
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/13467

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@r7vme
Copy link
Contributor Author

r7vme commented Mar 15, 2024

@MichaelOrlov thanks, is there anything required from my side? Or you can restart failed CI job Rpr__rosbag2__ubuntu_noble_amd64 ?

@clalancette
Copy link
Contributor

@MichaelOrlov thanks, is there anything required from my side? Or you can restart failed CI job Rpr__rosbag2__ubuntu_noble_amd64 ?

These aren't going to work right at the moment. We are close to making them work, but need a bit more time. The regular CI above is good enough.

@MichaelOrlov
Copy link
Contributor

MichaelOrlov commented Mar 15, 2024

@r7vme Some tests failing on Windows CI https://ci.ros2.org/job/ci_windows/21225/
At first glance, it seems failure relates to the filesystem operation.

C:\ci\ws\src\r7vme\rosbag2\rosbag2_cpp\test\rosbag2_cpp\test_sequential_reader.cpp:224
Expected equality of these values:
  closed_file
    Which is: "C:/Users/ContainerAdministrator/AppData/Local/Temp/some/folder/bag_file1"
  bag_file_1_path_.string()
    Which is: "C:/Users/ContainerAdministrator/AppData/Local/Temp/some/folder\\bag_file1"

C:\ci\ws\src\r7vme\rosbag2\rosbag2_cpp\test\rosbag2_cpp\test_sequential_reader.cpp:225
Expected equality of these values:
  opened_file
    Which is: "C:/Users/ContainerAdministrator/AppData/Local/Temp/some/folder/bag_file2"
  bag_file_2_path_.string()
    Which is: "C:/Users/ContainerAdministrator/AppData/Local/Temp/some/folder\\bag_file2"

Could you please take a look at failures and test use cases? It seems we have forgotten to use .string_generic() instead of .string() for fs::path somewhere.

Signed-off-by: Roman Sokolkov <rsokolkov@gmail.com>
@MichaelOrlov
Copy link
Contributor

Re-run CI afer attempt to fix test errors on Windows build
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/13484

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@MichaelOrlov
Copy link
Contributor

@r7vme We have one more test failure on Windows

[ RUN      ] StorageTestFixture.storage_preset_profile_applies_over_defaults
[INFO] [1710819321.702947900] [rosbag2_storage]: Opened database 'C:/Users/ContainerAdministrator/AppData/Local/Temp/tmp_test_dir_a05376/rosbag.db3' for READ_WRITE.
[       OK ] StorageTestFixture.storage_preset_profile_applies_over_defaults (32 ms)
[ RUN      ] StorageTestFixture.throws_on_invalid_pragma_in_config_file

Could you please take a look on it?

Signed-off-by: Roman Sokolkov <rsokolkov@gmail.com>
@r7vme
Copy link
Contributor Author

r7vme commented Mar 19, 2024

@MichaelOrlov I reverted remove_all in test fixture. This part is used in failed test. Let's see it if helps. No other ideas unforunately

@MichaelOrlov
Copy link
Contributor

Trying to re-run Windows CI after reverting remove_all in the test fixture to see if it is a root cause of the CI failure

  • Windows Build Status

@r7vme
Copy link
Contributor Author

r7vme commented Mar 20, 2024

@clalancette could you please take another look? your comment was addressed

Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MichaelOrlov I reverted remove_all in test fixture. This part is used in failed test. Let's see it if helps. No other ideas unforunately

I have to say that I'm surprised that this fixed the problem. We are using a similar pattern in https://github.com/ros2/rcl_logging/blob/rolling/rcl_logging_spdlog/test/test_logging_interface.cpp , and it is working fine by using std::filesystem::remove_all.

That said, I'm still approving since I'm OK with putting this in as-is. It just means that we won't be able to remove rcpputils::fs until we do another PR to fix whatever bug std::filesystem::remove_all is hitting.

@r7vme
Copy link
Contributor Author

r7vme commented Mar 22, 2024

@MichaelOrlov I guess can be merged finally?

@MichaelOrlov
Copy link
Contributor

@r7vme Yes we can merge I think. However, please hold off for a couple of days. I need to wrap up some other things and I want to mitigate the potential merge or rebase conflicts.

@MichaelOrlov MichaelOrlov merged commit 415ddda into ros2:rolling Mar 25, 2024
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants