Skip to content

Commit

Permalink
Use global properties instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
fruffy-bfn committed Dec 7, 2022
1 parent d3f01a6 commit 8981b13
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ list(FILTER P4C_LINT_LIST EXCLUDE REGEX "control-plane/p4runtime")
# cpplint
add_cpplint_files(${P4C_SOURCE_DIR} "${P4C_LINT_LIST}")

if(DEFINED CPPLINT_FILES)
get_property(TARGET cpplint CPPLINT_FILES PROPERTY cpplint-files)
get_property(CPPLINT_FILES GLOBAL PROPERTY cpplint-files)
if(CPPLINT_FILES)
list ( SORT CPPLINT_FILES )
set (CPPLINT_CMD ${P4C_SOURCE_DIR}/tools/cpplint.py)
set (CPPLINT_ARGS --root=${P4C_SOURCE_DIR} --extensions=h,hpp,cpp,ypp,l)
Expand All @@ -533,6 +533,7 @@ add_clang_format_files(${P4C_SOURCE_DIR} "${P4C_LINT_LIST}")
find_program(CLANG_FORMAT_CMD clang-format)

if(NOT ${CLANG_FORMAT_CMD})
get_property(CLANG_FORMAT_FILES GLOBAL PROPERTY clang-format-files)
if(DEFINED CLANG_FORMAT_FILES)
list(SORT CLANG_FORMAT_FILES)
set(CLANG_FORMAT_CMD clang-format)
Expand Down
28 changes: 10 additions & 18 deletions cmake/P4CUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,34 +59,26 @@ macro(add_cpplint_files dir filelist)
endif()
endforeach(__f)

# Since add_cpplint_files is a macro, we need to check whether the
# calling context has a parent. If not, add to the variable directly.
get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
set (CPPLINT_FILES ${CPPLINT_FILES} ${__cpplintFileList} PARENT_SCOPE)
else()
set (CPPLINT_FILES ${CPPLINT_FILES} ${__cpplintFileList})
endif()
# Get the global cpplint property and append to it.
get_property(CPPLINT_FILES GLOBAL PROPERTY cpplint-files)
list (APPEND CPPLINT_FILES "${__cpplintFileList}")
set_property(GLOBAL PROPERTY cpplint-files "${CPPLINT_FILES}")
endmacro(add_cpplint_files)

macro(add_clang_format_files dir filelist)
foreach(__f ${filelist})
string(REGEX MATCH "^/.*" abs_path "${__f}")
if (NOT ${abs_path} EQUAL "")
list (APPEND __cpplintFileList "${__f}")
list (APPEND __clangFormatFileList "${__f}")
else()
list (APPEND __cpplintFileList "${dir}/${__f}")
list (APPEND __clangFormatFileList "${dir}/${__f}")
endif()
endforeach(__f)

# Since add_cpplint_files is a macro, we need to check whether the
# calling context has a parent. If not, add to the variable directly.
get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
set (CLANG_FORMAT_FILES ${CLANG_FORMAT_FILES} ${__cpplintFileList} PARENT_SCOPE)
else()
set (CLANG_FORMAT_FILES ${CLANG_FORMAT_FILES} ${__cpplintFileList})
endif()
# Get the global clang-format property and append to it.
get_property(CLANG_FORMAT_FILES GLOBAL PROPERTY clang-format-files)
list (APPEND CLANG_FORMAT_FILES "${__clangFormatFileList}")
set_property(GLOBAL PROPERTY clang-format-files "${CLANG_FORMAT_FILES}")
endmacro(add_clang_format_files)


Expand Down

0 comments on commit 8981b13

Please sign in to comment.