From 7cc253a6ab4ef9bb2b100af340778ae55e44a8c1 Mon Sep 17 00:00:00 2001 From: Xiangquan Xiao Date: Thu, 14 Feb 2019 13:59:06 -0800 Subject: [PATCH] All: Final clean up of old file util usages. (#6865) --- modules/common/configs/vehicle_config_helper.cc | 4 ++-- modules/common/kv_db/kv_db.cc | 1 - modules/common/util/file.h | 11 ----------- modules/common/util/message_util.h | 8 ++++---- modules/common/util/message_util_test.cc | 4 ++-- .../vehicle_state/vehicle_state_provider_test.cc | 4 ++-- modules/control/common/leadlag_controller_test.cc | 4 ++-- modules/control/control_component_test.cc | 4 ++-- .../control/integration_tests/control_test_base.cc | 2 +- modules/data/data_component.cc | 13 ++++--------- modules/dreamview/backend/dreamview.cc | 3 +-- modules/dreamview/backend/hmi/hmi_worker.cc | 6 +++--- .../simulation_world/simulation_world_updater.cc | 3 ++- modules/localization/rtk/rtk_localization_test.cc | 3 ++- modules/map/relative_map/tools/navigator.cc | 4 ++-- modules/monitor/hardware/resource_monitor.cc | 2 +- modules/monitor/software/process_monitor.cc | 6 +++--- .../camera/app/lane_camera_perception.cc | 4 ++-- .../onboard/component/lane_detection_component.cc | 4 ++-- .../integration_tests/planning_test_base.cc | 14 ++++++-------- .../feature_proto_file_to_model_features.cc | 4 ++-- 21 files changed, 45 insertions(+), 63 deletions(-) diff --git a/modules/common/configs/vehicle_config_helper.cc b/modules/common/configs/vehicle_config_helper.cc index de443f23cf..0c13aabfe0 100644 --- a/modules/common/configs/vehicle_config_helper.cc +++ b/modules/common/configs/vehicle_config_helper.cc @@ -19,8 +19,8 @@ #include #include +#include "cyber/common/file.h" #include "modules/common/configs/config_gflags.h" -#include "modules/common/util/file.h" namespace apollo { namespace common { @@ -34,7 +34,7 @@ void VehicleConfigHelper::Init() { Init(FLAGS_vehicle_config_path); } void VehicleConfigHelper::Init(const std::string &config_file) { VehicleConfig params; - CHECK(apollo::common::util::GetProtoFromFile(config_file, ¶ms)) + CHECK(cyber::common::GetProtoFromFile(config_file, ¶ms)) << "Unable to parse vehicle config file " << config_file; Init(params); } diff --git a/modules/common/kv_db/kv_db.cc b/modules/common/kv_db/kv_db.cc index 03525ea2ed..69a29fa78c 100644 --- a/modules/common/kv_db/kv_db.cc +++ b/modules/common/kv_db/kv_db.cc @@ -20,7 +20,6 @@ #include "gflags/gflags.h" #include "cyber/common/log.h" -#include "modules/common/util/file.h" #include "modules/common/util/string_util.h" #include "modules/common/util/util.h" diff --git a/modules/common/util/file.h b/modules/common/util/file.h index 45d841d5ad..e12f8aff66 100644 --- a/modules/common/util/file.h +++ b/modules/common/util/file.h @@ -35,21 +35,10 @@ namespace util { // usages we'll retire the aliases here. using apollo::cyber::common::SetProtoToASCIIFile; using apollo::cyber::common::GetProtoFromASCIIFile; -using apollo::cyber::common::SetProtoToBinaryFile; -using apollo::cyber::common::GetProtoFromBinaryFile; using apollo::cyber::common::GetProtoFromFile; -using apollo::cyber::common::GetContent; -using apollo::cyber::common::GetAbsolutePath; using apollo::cyber::common::PathExists; using apollo::cyber::common::DirectoryExists; -using apollo::cyber::common::Glob; -using apollo::cyber::common::CopyFile; -using apollo::cyber::common::CopyDir; -using apollo::cyber::common::Copy; using apollo::cyber::common::EnsureDirectory; -using apollo::cyber::common::RemoveAllFiles; -using apollo::cyber::common::ListSubPaths; -using apollo::cyber::common::GetFileName; } // namespace util } // namespace common diff --git a/modules/common/util/message_util.h b/modules/common/util/message_util.h index 857c90d9ee..abd102c3ef 100644 --- a/modules/common/util/message_util.h +++ b/modules/common/util/message_util.h @@ -24,9 +24,9 @@ #include #include +#include "cyber/common/file.h" #include "google/protobuf/message.h" #include "modules/common/time/time.h" -#include "modules/common/util/file.h" #include "modules/common/util/string_util.h" /** @@ -75,8 +75,8 @@ bool DumpMessage(const std::shared_ptr& msg, auto type_name = T::descriptor()->full_name(); std::string dump_path = dump_dir + "/" + type_name; - if (!DirectoryExists(dump_path)) { - if (!EnsureDirectory(dump_path)) { + if (!cyber::common::DirectoryExists(dump_path)) { + if (!cyber::common::EnsureDirectory(dump_path)) { AERROR << "Cannot enable dumping for '" << type_name << "' because the path " << dump_path << " cannot be created or is not a directory."; @@ -85,7 +85,7 @@ bool DumpMessage(const std::shared_ptr& msg, } auto sequence_num = msg->header().sequence_num(); - return util::SetProtoToASCIIFile( + return cyber::common::SetProtoToASCIIFile( *msg, util::StrCat(dump_path, "/", sequence_num, ".pb.txt")); } diff --git a/modules/common/util/message_util_test.cc b/modules/common/util/message_util_test.cc index e53b04f5e1..040f380623 100644 --- a/modules/common/util/message_util_test.cc +++ b/modules/common/util/message_util_test.cc @@ -31,8 +31,8 @@ TEST(MessageUtilTest, DumpMessage) { auto simple_msg = std::make_shared(); FillHeader("test", simple_msg.get()); EXPECT_TRUE(DumpMessage(simple_msg)); - EXPECT_TRUE( - PathExists("/tmp/apollo.common.util.test.SimpleMessage/0.pb.txt")); + EXPECT_TRUE(cyber::common::PathExists( + "/tmp/apollo.common.util.test.SimpleMessage/0.pb.txt")); } TEST(MessageUtilTest, MessageFingerprint) { diff --git a/modules/common/vehicle_state/vehicle_state_provider_test.cc b/modules/common/vehicle_state/vehicle_state_provider_test.cc index ffa742e554..5aa3b4763b 100644 --- a/modules/common/vehicle_state/vehicle_state_provider_test.cc +++ b/modules/common/vehicle_state/vehicle_state_provider_test.cc @@ -21,8 +21,8 @@ #include "Eigen/Core" #include "gtest/gtest.h" +#include "cyber/common/file.h" #include "modules/canbus/proto/chassis.pb.h" -#include "modules/common/util/file.h" #include "modules/localization/common/localization_gflags.h" #include "modules/localization/proto/localization.pb.h" @@ -38,7 +38,7 @@ class VehicleStateProviderTest : public ::testing::Test { virtual void SetUp() { std::string localization_file = "modules/localization/testdata/3_localization_result_1.pb.txt"; - CHECK(common::util::GetProtoFromFile(localization_file, &localization_)); + CHECK(cyber::common::GetProtoFromFile(localization_file, &localization_)); chassis_.set_speed_mps(3.0); chassis_.set_gear_location(canbus::Chassis::GEAR_DRIVE); FLAGS_enable_map_reference_unify = false; diff --git a/modules/control/common/leadlag_controller_test.cc b/modules/control/common/leadlag_controller_test.cc index e4a2a8921f..9d59541ec0 100644 --- a/modules/control/common/leadlag_controller_test.cc +++ b/modules/control/common/leadlag_controller_test.cc @@ -19,8 +19,8 @@ #include #include +#include "cyber/common/file.h" #include "gtest/gtest.h" -#include "modules/common/util/file.h" #include "modules/control/proto/control_conf.pb.h" #include "modules/control/proto/leadlag_conf.pb.h" @@ -32,7 +32,7 @@ class LeadlagControllerTest : public ::testing::Test { virtual void SetUp() { std::string control_conf_file = "/apollo/modules/control/testdata/conf/control_conf.pb.txt"; - CHECK(common::util::GetProtoFromFile(control_conf_file, &control_conf_)); + CHECK(cyber::common::GetProtoFromFile(control_conf_file, &control_conf_)); lon_controller_conf_ = control_conf_.lon_controller_conf(); } diff --git a/modules/control/control_component_test.cc b/modules/control/control_component_test.cc index a566dd024f..e3556a62bc 100644 --- a/modules/control/control_component_test.cc +++ b/modules/control/control_component_test.cc @@ -201,8 +201,8 @@ bool ControlComponentTest::RunControl(const std::string& test_case_name) { cyber::common::SetProtoToASCIIFile(control_command_, golden_result_file); } else { ControlCommand golden_result; - bool load_success = - common::util::GetProtoFromASCIIFile(full_golden_path, &golden_result); + bool load_success = cyber::common::GetProtoFromASCIIFile( + full_golden_path, &golden_result); if (!load_success) { AERROR << "Failed to load golden file: " << full_golden_path; cyber::common::SetProtoToASCIIFile(control_command_, tmp_golden_path); diff --git a/modules/control/integration_tests/control_test_base.cc b/modules/control/integration_tests/control_test_base.cc index 9f982c7f08..5053a0378a 100644 --- a/modules/control/integration_tests/control_test_base.cc +++ b/modules/control/integration_tests/control_test_base.cc @@ -160,7 +160,7 @@ bool ControlTestBase::test_control(const std::string &test_case_name, cyber::common::GetProtoFromASCIIFile(full_golden_path, &golden_result); if (!load_success) { AERROR << "Failed to load golden file: " << full_golden_path; - common::util::SetProtoToASCIIFile(control_command_, tmp_golden_path); + cyber::common::SetProtoToASCIIFile(control_command_, tmp_golden_path); AINFO << "Current result is written to " << tmp_golden_path; return false; } diff --git a/modules/data/data_component.cc b/modules/data/data_component.cc index 67ab3e43cf..14c7dbbf7b 100644 --- a/modules/data/data_component.cc +++ b/modules/data/data_component.cc @@ -16,7 +16,6 @@ #include "modules/data/data_component.h" #include "cyber/common/log.h" - #include "modules/common/adapters/adapter_gflags.h" #include "modules/common/util/message_util.h" #include "modules/data/common/data_gflags.h" @@ -26,8 +25,7 @@ namespace apollo { namespace data { bool DataComponent::Init() { - CHECK(apollo::common::util::GetProtoFromFile(FLAGS_data_conf_file, - &data_conf_)) + CHECK(cyber::common::GetProtoFromFile(FLAGS_data_conf_file, &data_conf_)) << "Unable to load data conf file: " << FLAGS_data_conf_file; if (!data_conf_.data_enabled()) { @@ -45,8 +43,7 @@ bool DataComponent::Init() { bool DataComponent::Proc( const std::shared_ptr &request) { - ADEBUG << "Received data input command: " - << request->DebugString(); + ADEBUG << "Received data input command: " << request->DebugString(); OnDataInputCommand(request); @@ -58,10 +55,8 @@ bool DataComponent::Proc( void DataComponent::CreateReader() { data_input_cmd_reader_ = node_->CreateReader( FLAGS_data_topic, - std::bind( - &DataComponent::OnDataInputCommand, - this, - std::placeholders::_1)); + std::bind(&DataComponent::OnDataInputCommand, this, + std::placeholders::_1)); CHECK(data_input_cmd_reader_ != nullptr); } diff --git a/modules/dreamview/backend/dreamview.cc b/modules/dreamview/backend/dreamview.cc index af46ca1c2b..966516427a 100644 --- a/modules/dreamview/backend/dreamview.cc +++ b/modules/dreamview/backend/dreamview.cc @@ -21,7 +21,6 @@ #include "cyber/common/file.h" #include "modules/common/configs/vehicle_config_helper.h" #include "modules/common/time/time.h" - #include "modules/dreamview/backend/common/dreamview_gflags.h" namespace apollo { @@ -29,7 +28,7 @@ namespace dreamview { using apollo::common::Status; using apollo::common::VehicleConfigHelper; -using apollo::common::util::PathExists; +using cyber::common::PathExists; Dreamview::~Dreamview() { Stop(); } diff --git a/modules/dreamview/backend/hmi/hmi_worker.cc b/modules/dreamview/backend/hmi/hmi_worker.cc index 543cd127d3..7917953109 100644 --- a/modules/dreamview/backend/hmi/hmi_worker.cc +++ b/modules/dreamview/backend/hmi/hmi_worker.cc @@ -85,7 +85,7 @@ std::string TitleCase(const std::string& origin) { // List subdirs and return a dict of {subdir_title: subdir_path}. Map ListDirAsDict(const std::string& dir) { Map result; - const auto subdirs = apollo::common::util::ListSubPaths(dir); + const auto subdirs = cyber::common::ListSubPaths(dir); for (const auto& subdir : subdirs) { const auto subdir_title = TitleCase(subdir); const auto subdir_path = StrCat(dir, "/", subdir); @@ -99,9 +99,9 @@ Map ListFilesAsDict(const std::string& dir, const std::string& extension) { Map result; const std::string pattern = StrCat(dir, "/*", extension); - for (const std::string& file_path : apollo::common::util::Glob(pattern)) { + for (const std::string& file_path : cyber::common::Glob(pattern)) { // Remove the extention and convert to title case as the file title. - const std::string filename = apollo::common::util::GetFileName(file_path); + const std::string filename = cyber::common::GetFileName(file_path); const std::string file_title = TitleCase(filename.substr(0, filename.length() - extension.length())); result.insert({file_title, file_path}); diff --git a/modules/dreamview/backend/simulation_world/simulation_world_updater.cc b/modules/dreamview/backend/simulation_world/simulation_world_updater.cc index 798066a654..02df72546a 100644 --- a/modules/dreamview/backend/simulation_world/simulation_world_updater.cc +++ b/modules/dreamview/backend/simulation_world/simulation_world_updater.cc @@ -16,6 +16,7 @@ #include "modules/dreamview/backend/simulation_world/simulation_world_updater.h" +#include "cyber/common/file.h" #include "google/protobuf/util/json_util.h" #include "modules/common/util/json_util.h" #include "modules/common/util/map_util.h" @@ -27,7 +28,7 @@ namespace dreamview { using apollo::common::monitor::MonitorMessageItem; using apollo::common::util::ContainsKey; -using apollo::common::util::GetProtoFromASCIIFile; +using apollo::cyber::common::GetProtoFromASCIIFile; using apollo::hdmap::EndWayPointFile; using apollo::relative_map::NavigationInfo; using apollo::routing::RoutingRequest; diff --git a/modules/localization/rtk/rtk_localization_test.cc b/modules/localization/rtk/rtk_localization_test.cc index 8c4f97da89..30f430796b 100644 --- a/modules/localization/rtk/rtk_localization_test.cc +++ b/modules/localization/rtk/rtk_localization_test.cc @@ -19,6 +19,7 @@ #include "google/protobuf/text_format.h" #include "gtest/gtest.h" +#include "cyber/common/file.h" #include "cyber/common/log.h" #include "modules/common/util/util.h" @@ -32,7 +33,7 @@ class RTKLocalizationTest : public ::testing::Test { protected: template void load_data(const std::string &filename, T *data) { - CHECK(common::util::GetProtoFromFile(filename, data)) + CHECK(cyber::common::GetProtoFromFile(filename, data)) << "Failed to open file " << filename; } diff --git a/modules/map/relative_map/tools/navigator.cc b/modules/map/relative_map/tools/navigator.cc index 95c95a6b10..112819eaf8 100644 --- a/modules/map/relative_map/tools/navigator.cc +++ b/modules/map/relative_map/tools/navigator.cc @@ -53,8 +53,8 @@ int main(int argc, char** argv) { NavigatorConfig navigator_config; AINFO << "The navigator configuration filename is: " << FLAGS_navigator_config_filename; - if (!apollo::common::util::GetProtoFromFile(FLAGS_navigator_config_filename, - &navigator_config)) { + if (!apollo::cyber::common::GetProtoFromFile(FLAGS_navigator_config_filename, + &navigator_config)) { AERROR << "Failed to parse " << FLAGS_navigator_config_filename; return -1; } diff --git a/modules/monitor/hardware/resource_monitor.cc b/modules/monitor/hardware/resource_monitor.cc index 016f2400b2..d691043e7b 100644 --- a/modules/monitor/hardware/resource_monitor.cc +++ b/modules/monitor/hardware/resource_monitor.cc @@ -64,7 +64,7 @@ void ResourceMonitor::UpdateStatus( status->clear_status(); // Monitor available disk space. for (const auto& disk_space : config.disk_spaces()) { - for (const auto& path : apollo::common::util::Glob(disk_space.path())) { + for (const auto& path : cyber::common::Glob(disk_space.path())) { const auto space = boost::filesystem::space(path); const int available_gb = static_cast(space.available >> 30); if (available_gb < disk_space.insufficient_space_error()) { diff --git a/modules/monitor/software/process_monitor.cc b/modules/monitor/software/process_monitor.cc index 246fab0133..88704d895b 100644 --- a/modules/monitor/software/process_monitor.cc +++ b/modules/monitor/software/process_monitor.cc @@ -27,7 +27,7 @@ DEFINE_string(process_monitor_name, "ProcessMonitor", "Name of the process monitor."); DEFINE_double(process_monitor_interval, 1.5, - "Process status checking interval (s)."); + "Process status checking interval in seconds."); namespace apollo { namespace monitor { @@ -40,10 +40,10 @@ ProcessMonitor::ProcessMonitor() void ProcessMonitor::RunOnce(const double current_time) { // Get running processes. std::vector running_processes; - for (const auto& cmd_file : apollo::common::util::Glob("/proc/*/cmdline")) { + for (const auto& cmd_file : cyber::common::Glob("/proc/*/cmdline")) { // Get process command string. std::string cmd_string; - if (apollo::common::util::GetContent(cmd_file, &cmd_string) && + if (cyber::common::GetContent(cmd_file, &cmd_string) && !cmd_string.empty()) { // In /proc//cmdline, the parts are seperated with \0, which will be // converted back to whitespaces here. diff --git a/modules/perception/camera/app/lane_camera_perception.cc b/modules/perception/camera/app/lane_camera_perception.cc index 28de0b9ad8..256ddc201e 100644 --- a/modules/perception/camera/app/lane_camera_perception.cc +++ b/modules/perception/camera/app/lane_camera_perception.cc @@ -23,8 +23,8 @@ #include #include +#include "cyber/common/file.h" #include "cyber/common/log.h" -#include "modules/common/util/file.h" #include "modules/perception/base/object.h" #include "modules/perception/camera/app/debug_info.h" #include "modules/perception/camera/common/global_config.h" @@ -48,7 +48,7 @@ bool LaneCameraPerception::Init( std::string config_file = GetAbsolutePath(options.root_dir, options.conf_file); config_file = GetAbsolutePath(work_root, config_file); - CHECK(apollo::common::util::GetProtoFromFile( + CHECK(cyber::common::GetProtoFromFile( config_file, &perception_param_)) << "Read config failed: "; CHECK(inference::CudaUtil::set_device_id(perception_param_.gpu_id())); diff --git a/modules/perception/onboard/component/lane_detection_component.cc b/modules/perception/onboard/component/lane_detection_component.cc index e078a2fcac..5587fd0bce 100644 --- a/modules/perception/onboard/component/lane_detection_component.cc +++ b/modules/perception/onboard/component/lane_detection_component.cc @@ -28,10 +28,10 @@ #include #include +#include "cyber/common/file.h" #include "cyber/common/log.h" #include "modules/common/math/math_utils.h" #include "modules/common/time/time_util.h" -#include "modules/common/util/file.h" #include "modules/perception/common/perception_gflags.h" #include "modules/perception/common/sensor_manager/sensor_manager.h" #include "modules/perception/lib/utils/time_util.h" @@ -53,7 +53,7 @@ static int GetGpuId(const camera::CameraPerceptionInitOptions &options) { std::string config_file = GetAbsolutePath(options.root_dir, options.conf_file); config_file = GetAbsolutePath(work_root, config_file); - if (!apollo::common::util::GetProtoFromFile(config_file, &perception_param)) { + if (!cyber::common::GetProtoFromFile(config_file, &perception_param)) { AERROR << "Read config failed: " << config_file; return -1; } diff --git a/modules/planning/integration_tests/planning_test_base.cc b/modules/planning/integration_tests/planning_test_base.cc index c29f131b9a..142e687fdb 100644 --- a/modules/planning/integration_tests/planning_test_base.cc +++ b/modules/planning/integration_tests/planning_test_base.cc @@ -20,14 +20,13 @@ #include "cyber/common/log.h" #include "modules/canbus/proto/chassis.pb.h" +#include "modules/common/adapters/adapter_gflags.h" #include "modules/localization/proto/localization.pb.h" #include "modules/perception/proto/traffic_light_detection.pb.h" +#include "modules/planning/common/planning_gflags.h" #include "modules/prediction/proto/prediction_obstacle.pb.h" #include "modules/routing/proto/routing.pb.h" -#include "modules/common/adapters/adapter_gflags.h" -#include "modules/planning/common/planning_gflags.h" - namespace apollo { namespace planning { @@ -163,8 +162,7 @@ void PlanningTestBase::SetUp() { CHECK(FeedTestData()) << "Failed to feed test data"; - CHECK(apollo::cyber::common::GetProtoFromFile(FLAGS_planning_config_file, - &config_)) + CHECK(cyber::common::GetProtoFromFile(FLAGS_planning_config_file, &config_)) << "failed to load planning config file " << FLAGS_planning_config_file; CHECK(planning_->Init(config_).ok()) << "Failed to init planning module"; @@ -243,17 +241,17 @@ bool PlanningTestBase::RunPlanning(const std::string& test_case_name, TrimPlanning(&adc_trajectory_, no_trajectory_point); if (FLAGS_test_update_golden_log) { AINFO << "The golden file is regenerated:" << full_golden_path; - common::util::SetProtoToASCIIFile(adc_trajectory_, full_golden_path); + cyber::common::SetProtoToASCIIFile(adc_trajectory_, full_golden_path); } else { ADCTrajectory golden_result; bool load_success = - common::util::GetProtoFromASCIIFile(full_golden_path, &golden_result); + cyber::common::GetProtoFromASCIIFile(full_golden_path, &golden_result); TrimPlanning(&golden_result, no_trajectory_point); if (!load_success || !common::util::IsProtoEqual(golden_result, adc_trajectory_)) { char tmp_fname[100] = "/tmp/XXXXXX"; int fd = mkstemp(tmp_fname); - if (!common::util::SetProtoToASCIIFile(adc_trajectory_, fd)) { + if (!cyber::common::SetProtoToASCIIFile(adc_trajectory_, fd)) { AERROR << "Failed to write to file " << tmp_fname; } AERROR << "found error\ndiff -y " << tmp_fname << " " << full_golden_path; diff --git a/modules/prediction/pipeline/feature_proto_file_to_model_features.cc b/modules/prediction/pipeline/feature_proto_file_to_model_features.cc index e16c3b991d..2f8969b48b 100644 --- a/modules/prediction/pipeline/feature_proto_file_to_model_features.cc +++ b/modules/prediction/pipeline/feature_proto_file_to_model_features.cc @@ -138,8 +138,8 @@ void OfflineProcessFeatureProtoFile( if (list_data_for_learning.data_for_learning_size() <= 0) { ADEBUG << "Skip writing empty data_for_learning."; } else { - apollo::common::util::SetProtoToBinaryFile(list_data_for_learning, - output_filename); + apollo::cyber::common::SetProtoToBinaryFile( + list_data_for_learning, output_filename); } } -- GitLab