From 538245e3c7bd95b756323fcee4ac9accc1ff7278 Mon Sep 17 00:00:00 2001 From: Aaron Xiao Date: Tue, 6 Nov 2018 16:58:12 -0800 Subject: [PATCH] Common: Retire yaml_util which is not used. --- modules/common/util/BUILD | 28 ------- .../common/util/testdata/simple_proto.pb.txt | 14 ---- .../common/util/testdata/simple_proto.yaml | 9 --- modules/common/util/yaml_util.cc | 78 ------------------- modules/common/util/yaml_util.h | 36 --------- modules/common/util/yaml_util_test.cc | 46 ----------- modules/dreamview/backend/hmi/BUILD | 1 - modules/dreamview/backend/hmi/hmi_worker.cc | 1 - 8 files changed, 213 deletions(-) delete mode 100644 modules/common/util/testdata/simple_proto.pb.txt delete mode 100644 modules/common/util/testdata/simple_proto.yaml delete mode 100644 modules/common/util/yaml_util.cc delete mode 100644 modules/common/util/yaml_util.h delete mode 100644 modules/common/util/yaml_util_test.cc diff --git a/modules/common/util/BUILD b/modules/common/util/BUILD index 15c1781f9d..22f245f88b 100644 --- a/modules/common/util/BUILD +++ b/modules/common/util/BUILD @@ -268,34 +268,6 @@ cc_test( ], ) -cc_library( - name = "yaml_util", - srcs = [ - "yaml_util.cc", - ], - hdrs = [ - "yaml_util.h", - ], - deps = [ - "@com_google_protobuf//:protobuf", - "@yaml_cpp//:yaml", - ], -) - -cc_test( - name = "yaml_util_test", - size = "small", - srcs = [ - "yaml_util_test.cc", - ], - deps = [ - ":util", - ":yaml_util", - "//modules/common/util/testdata:simple_proto", - "@gtest//:main", - ], -) - cc_library( name = "http_client", srcs = ["http_client.cc"], diff --git a/modules/common/util/testdata/simple_proto.pb.txt b/modules/common/util/testdata/simple_proto.pb.txt deleted file mode 100644 index 8926cd2fb5..0000000000 --- a/modules/common/util/testdata/simple_proto.pb.txt +++ /dev/null @@ -1,14 +0,0 @@ -message { - integer: 1 - text: "234" - header { - module_name: "Message 1" - status { - msg: "Status" - error_code: OK - } - } -} -message { - integer: 2 -} diff --git a/modules/common/util/testdata/simple_proto.yaml b/modules/common/util/testdata/simple_proto.yaml deleted file mode 100644 index befe12a77a..0000000000 --- a/modules/common/util/testdata/simple_proto.yaml +++ /dev/null @@ -1,9 +0,0 @@ -message: - - integer: 1 - text: "234" - header: - module_name: "Message 1" - status: - msg: "Status" - error_code: "OK" - - integer: 2 diff --git a/modules/common/util/yaml_util.cc b/modules/common/util/yaml_util.cc deleted file mode 100644 index 540a0e011b..0000000000 --- a/modules/common/util/yaml_util.cc +++ /dev/null @@ -1,78 +0,0 @@ -/****************************************************************************** - * Copyright 2018 The Apollo Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *****************************************************************************/ - -#include "modules/common/util/yaml_util.h" - -#include -#include - -namespace apollo { -namespace common { -namespace util { -namespace { - -void YamlNodeToJson(const YAML::Node& node, std::ostringstream* oss) { - switch (node.Type()) { - case YAML::NodeType::Undefined: - *oss << "\"\""; - break; - case YAML::NodeType::Null: - *oss << "\"\""; - break; - case YAML::NodeType::Scalar: - *oss << "\"" << node.as() << "\""; - break; - case YAML::NodeType::Sequence: - *oss << "[\n"; - for (const auto& sub_node : node) { - YamlNodeToJson(sub_node, oss); - *oss << ", "; - } - *oss << "]\n"; - break; - case YAML::NodeType::Map: - *oss << "{\n"; - for (const auto& sub_node : node) { - YamlNodeToJson(sub_node.first, oss); - *oss << ": "; - YamlNodeToJson(sub_node.second, oss); - *oss << ",\n"; - } - *oss << "}\n"; - break; - } -} - -} // namespace - -// Load YAML file to an equivalent json string. -std::string YamlToJson(const std::string& yaml_file) { - std::ostringstream oss; - YamlNodeToJson(YAML::LoadFile(yaml_file), &oss); - return oss.str(); -} - -// Load YAML file to an equivalent proto message. -// Return false if failed. -bool YamlToProto(const std::string& yaml_file, - google::protobuf::Message* proto) { - const std::string json = YamlToJson(yaml_file); - return google::protobuf::util::JsonStringToMessage(json, proto).ok(); -} - -} // namespace util -} // namespace common -} // namespace apollo diff --git a/modules/common/util/yaml_util.h b/modules/common/util/yaml_util.h deleted file mode 100644 index 6e85cdfadc..0000000000 --- a/modules/common/util/yaml_util.h +++ /dev/null @@ -1,36 +0,0 @@ -/****************************************************************************** - * Copyright 2018 The Apollo Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *****************************************************************************/ -#pragma once - -#include - -#include "google/protobuf/message.h" - -namespace apollo { -namespace common { -namespace util { - -// Load YAML file to an equivalent json string. -std::string YamlToJson(const std::string& yaml_file); - -// Load YAML file to an equivalent proto message. -// Return false if failed. -bool YamlToProto(const std::string& yaml_file, - google::protobuf::Message* proto); - -} // namespace util -} // namespace common -} // namespace apollo diff --git a/modules/common/util/yaml_util_test.cc b/modules/common/util/yaml_util_test.cc deleted file mode 100644 index df2fe8fb5c..0000000000 --- a/modules/common/util/yaml_util_test.cc +++ /dev/null @@ -1,46 +0,0 @@ -/****************************************************************************** - * Copyright 2018 The Apollo Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *****************************************************************************/ - -#include "modules/common/util/yaml_util.h" - -#include "gtest/gtest.h" - -#include "modules/common/util/file.h" -#include "modules/common/util/testdata/simple.pb.h" -#include "modules/common/util/util.h" - -namespace apollo { -namespace common { -namespace util { - -TEST(YamlUtilTest, YamlToProto) { - const std::string kInputYamlFile = - "/apollo/modules/common/util/testdata/simple_proto.yaml"; - const std::string kExpectedProtoFile = - "/apollo/modules/common/util/testdata/simple_proto.pb.txt"; - - test::SimpleRepeatedMessage loaded_proto; - EXPECT_TRUE(YamlToProto(kInputYamlFile, &loaded_proto)); - - test::SimpleRepeatedMessage expected_proto; - ASSERT_TRUE(GetProtoFromASCIIFile(kExpectedProtoFile, &expected_proto)); - - EXPECT_TRUE(IsProtoEqual(expected_proto, loaded_proto)); -} - -} // namespace util -} // namespace common -} // namespace apollo diff --git a/modules/dreamview/backend/hmi/BUILD b/modules/dreamview/backend/hmi/BUILD index 11a6397d3c..e4498d8b9c 100644 --- a/modules/dreamview/backend/hmi/BUILD +++ b/modules/dreamview/backend/hmi/BUILD @@ -66,7 +66,6 @@ cc_library( "//modules/common/proto:drive_event_proto", "//modules/common/util:map_util", "//modules/common/util:message_util", - "//modules/common/util:yaml_util", "//modules/data/util:info_collector", "//modules/dreamview/backend/common:dreamview_gflags", "//modules/dreamview/proto:hmi_config_proto", diff --git a/modules/dreamview/backend/hmi/hmi_worker.cc b/modules/dreamview/backend/hmi/hmi_worker.cc index 2c1ba4f87c..f87baefad2 100644 --- a/modules/dreamview/backend/hmi/hmi_worker.cc +++ b/modules/dreamview/backend/hmi/hmi_worker.cc @@ -27,7 +27,6 @@ #include "modules/common/util/message_util.h" #include "modules/common/util/string_tokenizer.h" #include "modules/common/util/string_util.h" -#include "modules/common/util/yaml_util.h" #include "modules/data/util/info_collector.h" #include "modules/dreamview/backend/common/dreamview_gflags.h" #include "modules/dreamview/backend/hmi/vehicle_manager.h" -- GitLab