Unverified Commit 458406c3 authored by Robert Kimball's avatar Robert Kimball Committed by GitHub

Test that header files include everything they need (#4496)

* Test that header files are standalone

* Working test

* Tests working

* Add doc string to header test file

* style
parent 49349a57
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#pragma once #pragma once
#include "ngraph/axis_vector.hpp"
#include "ngraph/node.hpp" #include "ngraph/node.hpp"
#include "ngraph/op/op.hpp" #include "ngraph/op/op.hpp"
#include "ngraph/op/util/fused_op.hpp" #include "ngraph/op/util/fused_op.hpp"
......
...@@ -201,6 +201,33 @@ set(SRC ...@@ -201,6 +201,33 @@ set(SRC
zero_dim_tensor_elimination.cpp zero_dim_tensor_elimination.cpp
) )
# This code generates one source file per header file under ngraph/src where the source file
# has just a single #include statement. This checks that each header in the source tree is
# complete and self-contained so it can be included without requiring any other includes.
set(DIRECTORIES_IGNORED runtime frontend)
set(NGRAPH_MAIN_SRC_DIR "${CMAKE_SOURCE_DIR}/src/ngraph")
file(GLOB_RECURSE LIST_RECURSE
"${NGRAPH_MAIN_SRC_DIR}/autodiff/*.hpp"
"${NGRAPH_MAIN_SRC_DIR}/builder/*.hpp"
"${NGRAPH_MAIN_SRC_DIR}/codegen/*.hpp"
"${NGRAPH_MAIN_SRC_DIR}/descriptor/*.hpp"
"${NGRAPH_MAIN_SRC_DIR}/distributed/*.hpp"
"${NGRAPH_MAIN_SRC_DIR}/op/*.hpp"
"${NGRAPH_MAIN_SRC_DIR}/pass/*.hpp"
"${NGRAPH_MAIN_SRC_DIR}/state*.hpp")
file(GLOB LIST
"${NGRAPH_MAIN_SRC_DIR}/*.hpp"
"${NGRAPH_MAIN_SRC_DIR}/runtime/*.hpp")
set(NGRAPH_HEADER_LIST ${LIST_RECURSE} ${LIST})
list(APPEND NGRAPH_HEADER_LIST ${LIST})
foreach(HEADER ${NGRAPH_HEADER_LIST})
file(RELATIVE_PATH OUT_PATH ${NGRAPH_MAIN_SRC_DIR} ${HEADER})
string(REGEX REPLACE "hpp$" "cpp" OUT_PATH ${OUT_PATH})
set(OUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/include_test/${OUT_PATH}")
configure_file("header_standalone.in.cpp" ${OUT_FILE})
list(APPEND SRC ${OUT_FILE})
endforeach()
if(NGRAPH_JSON_ENABLE) if(NGRAPH_JSON_ENABLE)
list(APPEND SRC core.cpp serialize.cpp) list(APPEND SRC core.cpp serialize.cpp)
endif() endif()
......
//*****************************************************************************
// 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.
//*****************************************************************************
/// \file This file is used to generate a series of .cpp files, one for each .hpp
/// file in ngraph, so the line below `#include "${HEADER}"` is expanded out to something
/// like `#include "/home/user/ngraph/src/ngraph/shape.hpp"`. The .cpp files are generated into
/// build/test/include_test/<headers>
/// The resulting .cpp file only includes this single file and then tries to compile it. If this
/// header file (shape.hpp in this example) does not #include everything it needs then the compile
/// will fail. You will need to add any missing #includes to make shape.hpp self-sufficient.
#define NGRAPH_OP(...)
#include "${HEADER}"
#undef NGRAPH_OP
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment