From e60331a232a5412dc0b14a9e7358c8153e29cd0b Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Thu, 27 Aug 2020 14:04:02 +0300 Subject: [PATCH] Use relative paths in error messages (#1963) --- ngraph/CMakeLists.txt | 2 +- ngraph/core/include/ngraph/check.hpp | 17 +--------- ngraph/core/src/check.cpp | 48 ++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 ngraph/core/src/check.cpp diff --git a/ngraph/CMakeLists.txt b/ngraph/CMakeLists.txt index 8b26ba41c63..1792012d435 100644 --- a/ngraph/CMakeLists.txt +++ b/ngraph/CMakeLists.txt @@ -424,7 +424,7 @@ if(NGRAPH_DEPRECATED_ENABLE) add_definitions(-DNGRAPH_DEPRECATED_ENABLE) endif() -add_definitions(-DPROJECT_ROOT_DIR="${CMAKE_CURRENT_SOURCE_DIR}") +add_definitions(-DPROJECT_ROOT_DIR="${CMAKE_SOURCE_DIR}") #----------------------------------------------------------------------------------------------- # Print Global Options diff --git a/ngraph/core/include/ngraph/check.hpp b/ngraph/core/include/ngraph/check.hpp index a54aa7250af..5fa4d52d2d5 100644 --- a/ngraph/core/include/ngraph/check.hpp +++ b/ngraph/core/include/ngraph/check.hpp @@ -52,22 +52,7 @@ namespace ngraph private: static std::string make_what(const CheckLocInfo& check_loc_info, const std::string& context_info, - const std::string& explanation) - { - std::stringstream ss; - ss << "Check '" << check_loc_info.check_string << "' failed at " << check_loc_info.file - << ":" << check_loc_info.line; - if (!context_info.empty()) - { - ss << ":" << std::endl << context_info; - } - if (!explanation.empty()) - { - ss << ":" << std::endl << explanation; - } - ss << std::endl; - return ss.str(); - } + const std::string& explanation); }; } diff --git a/ngraph/core/src/check.cpp b/ngraph/core/src/check.cpp new file mode 100644 index 00000000000..0bb1a880577 --- /dev/null +++ b/ngraph/core/src/check.cpp @@ -0,0 +1,48 @@ +//***************************************************************************** +// Copyright 2017-2020 Intel Corporation +// +// 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 "ngraph/check.hpp" + +using namespace ngraph; + +std::string CheckFailure::make_what(const CheckLocInfo& check_loc_info, + const std::string& context_info, + const std::string& explanation) +{ + // Use relative path only for internal code + auto getRelativePath = [](const std::string& path) -> std::string { + // Path to local OpenVINO repository + static const std::string project_root(PROJECT_ROOT_DIR); + // All internal paths start from project root + if (path.find(project_root) != 0) + return path; + // Add +1 to remove first / + return path.substr(project_root.length() + 1); + }; + std::stringstream ss; + ss << "Check '" << check_loc_info.check_string << "' failed at " + << getRelativePath(check_loc_info.file) << ":" << check_loc_info.line; + if (!context_info.empty()) + { + ss << ":" << std::endl << context_info; + } + if (!explanation.empty()) + { + ss << ":" << std::endl << explanation; + } + ss << std::endl; + return ss.str(); +}