提交 60c7d38b 编写于 作者: A Aaron Xiao 提交者: Jiangtao Hu

Data: Get commit ID upon every compiling.

上级 6cf158a6
......@@ -126,6 +126,12 @@ function build() {
# Build python proto
build_py_proto
# Update task info template on compiling, but don't check in.
bazel-bin/modules/data/recorder/update_task_info \
--commit_id=$(git rev-parse HEAD)
git update-index --assume-unchanged \
modules/data/conf/task_info_template.pb.txt
}
function cibuild() {
......@@ -300,8 +306,8 @@ function release() {
# release info
META=${ROOT_DIR}/meta.txt
echo "Git commit: $(git show --oneline -s | awk '{print $1}')" > $META
echo "Build time: $TIME" >> $META
echo "Git commit: $(git rev-parse HEAD)" > $META
echo "Build time: $(get_now)" >> $META
}
function gen_coverage() {
......
......@@ -13,4 +13,12 @@ cc_library(
],
)
cc_binary(
name = "update_task_info",
srcs = ["update_task_info.cc"],
deps = [
":info_collector",
],
)
cpplint()
......@@ -19,53 +19,70 @@
#include "modules/canbus/common/canbus_gflags.h"
#include "modules/common/adapters/adapter_manager.h"
DEFINE_string(task_info_template_file,
"modules/data/conf/task_info_template.pb.txt",
"Path of the task info template file.");
namespace apollo {
namespace data {
Task InfoCollector::GetTaskInfo() {
Task task;
*task.mutable_vehicle() = GetVehicleInfo();
*task.mutable_environment() = GetEnvironmentInfo();
*task.mutable_hardware() = GetHardwareInfo();
*task.mutable_software() = GetSoftwareInfo();
*task.mutable_user() = GetUserInfo();
return task;
using apollo::common::util::GetProtoFromASCIIFile;
using apollo::common::util::GetProtoFromFile;
using apollo::common::util::SetProtoToASCIIFile;
InfoCollector::InfoCollector() : task_info_(LoadTaskInfoTemplate()) {
}
const Task &InfoCollector::GetTaskInfo() {
// Use MergeFrom to override the template.
GetVehicleInfo();
GetEnvironmentInfo();
GetHardwareInfo();
GetSoftwareInfo();
GetUserInfo();
return task_info_;
}
VehicleInfo InfoCollector::GetVehicleInfo() {
VehicleInfo vehicle;
const VehicleInfo &InfoCollector::GetVehicleInfo() {
VehicleInfo *vehicle = task_info_.mutable_vehicle();
static auto *chassis_detail = CHECK_NOTNULL(
apollo::common::adapter::AdapterManager::GetChassisDetail());
if (!chassis_detail->Empty()) {
*vehicle.mutable_license() = chassis_detail->GetLatestObserved().license();
*vehicle->mutable_license() = chassis_detail->GetLatestObserved().license();
}
CHECK(apollo::common::util::GetProtoFromFile(
FLAGS_canbus_conf_file, vehicle.mutable_canbus_conf()));
CHECK(apollo::common::util::GetProtoFromFile(
FLAGS_vehicle_config_path, vehicle.mutable_vehicle_config()));
return vehicle;
CHECK(GetProtoFromFile(FLAGS_canbus_conf_file,
vehicle->mutable_canbus_conf()));
CHECK(GetProtoFromFile(FLAGS_vehicle_config_path,
vehicle->mutable_vehicle_config()));
return *vehicle;
}
// TODO(xiaoxq): Implement the info getters.
EnvironmentInfo InfoCollector::GetEnvironmentInfo() {
EnvironmentInfo environment;
return environment;
const EnvironmentInfo &InfoCollector::GetEnvironmentInfo() {
return task_info_.environment();
}
const HardwareInfo &InfoCollector::GetHardwareInfo() {
return task_info_.hardware();
}
const SoftwareInfo &InfoCollector::GetSoftwareInfo() {
return task_info_.software();
}
HardwareInfo InfoCollector::GetHardwareInfo() {
HardwareInfo hardware;
return hardware;
const UserInfo &InfoCollector::GetUserInfo() {
return task_info_.user();
}
SoftwareInfo InfoCollector::GetSoftwareInfo() {
SoftwareInfo software;
return software;
Task InfoCollector::LoadTaskInfoTemplate() {
Task task_info;
CHECK(GetProtoFromASCIIFile(FLAGS_task_info_template_file, &task_info));
return task_info;
}
UserInfo InfoCollector::GetUserInfo() {
UserInfo user;
return user;
bool InfoCollector::SaveTaskInfoTemplate(const Task &task_info) {
return SetProtoToASCIIFile(task_info, FLAGS_task_info_template_file);
}
} // namespace data
......
......@@ -28,15 +28,25 @@ namespace data {
class InfoCollector {
public:
// Get task information, which doesn't contain TaskData.
static Task GetTaskInfo();
InfoCollector();
// Get task information.
const Task &GetTaskInfo();
// Get specific information.
// Listening topics: ChassisDetail.
static VehicleInfo GetVehicleInfo();
static EnvironmentInfo GetEnvironmentInfo();
static HardwareInfo GetHardwareInfo();
static SoftwareInfo GetSoftwareInfo();
static UserInfo GetUserInfo();
const VehicleInfo &GetVehicleInfo();
const EnvironmentInfo &GetEnvironmentInfo();
const HardwareInfo &GetHardwareInfo();
const SoftwareInfo &GetSoftwareInfo();
const UserInfo &GetUserInfo();
// Load and save the task information template.
static Task LoadTaskInfoTemplate();
static bool SaveTaskInfoTemplate(const Task &task_info);
private:
Task task_info_;
};
} // namespace data
......
/******************************************************************************
* Copyright 2017 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 "gflags/gflags.h"
#include "modules/common/log.h"
#include "modules/data/recorder/info_collector.h"
DEFINE_string(docker_image, "", "Current container's docker image.");
DEFINE_string(commit_id, "", "Current commit ID.");
namespace apollo {
namespace data {
void UpdateTaskInfo() {
Task task = InfoCollector::LoadTaskInfoTemplate();
// Update software information.
auto *software = task.mutable_software();
if (!FLAGS_docker_image.empty()) {
software->set_docker_image(FLAGS_docker_image);
}
if (!FLAGS_commit_id.empty()) {
software->set_commit_id(FLAGS_commit_id);
}
CHECK(InfoCollector::SaveTaskInfoTemplate(task));
}
} // namespace data
} // namespace apollo
int main(int argc, char **argv) {
google::InitGoogleLogging(argv[0]);
google::ParseCommandLineFlags(&argc, &argv, true);
apollo::data::UpdateTaskInfo();
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册