Skip to content

Commit

Permalink
Migrate P4Testgen tooling to core P4C (IWYU, clang-format, cpplint, c…
Browse files Browse the repository at this point in the history
…lang-tidy, git hooks) (p4lang#3663)
  • Loading branch information
fruffy authored Nov 8, 2022
1 parent 22e2468 commit e25e930
Show file tree
Hide file tree
Showing 39 changed files with 328 additions and 279 deletions.
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions .github/workflows/ci-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "p4c-lint"

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
cpplint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
- name: Check submodule ref points.
run: |
./tools/check-git-submodules.sh
- name: Run cpplint.
run: |
./tools/run-cpplint.sh
- name: Run clang-format.
run: |
./tools/run-clang-format.sh
29 changes: 13 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -453,22 +453,19 @@ install (DIRECTORY ${P4C_SOURCE_DIR}/p4include
DESTINATION ${P4C_ARTIFACTS_OUTPUT_DIRECTORY})

# cpplint
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)
add_custom_target(cpplint
COMMAND ${CPPLINT_CMD} ${CPPLINT_ARGS} ${CPPLINT_FILES}
WORKING_DIRECTORY ${P4C_SOURCE_DIR}
COMMENT "cpplint")
add_custom_target(cpplint-quiet
COMMAND ${CPPLINT_CMD} --quiet ${CPPLINT_ARGS} ${CPPLINT_FILES}
WORKING_DIRECTORY ${P4C_SOURCE_DIR}
COMMENT "cpplint quietly")
# add cpplint as a test so that make check can proceed in parallel
add_test(NAME cpplint
COMMAND ${CPPLINT_CMD} --quiet ${CPPLINT_ARGS} ${CPPLINT_FILES}
WORKING_DIRECTORY ${P4C_SOURCE_DIR})
set_tests_properties(cpplint PROPERTIES LABELS cpplint)
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)
add_custom_target(cpplint
COMMAND ${CPPLINT_CMD} ${CPPLINT_ARGS} ${CPPLINT_FILES}
WORKING_DIRECTORY ${P4C_SOURCE_DIR}
COMMENT "cpplint")
add_custom_target(cpplint-quiet
COMMAND ${CPPLINT_CMD} --quiet ${CPPLINT_ARGS} ${CPPLINT_FILES}
WORKING_DIRECTORY ${P4C_SOURCE_DIR}
COMMENT "cpplint quietly")
endif()

# tags, etags
set (CTAGS_DIRS backends extensions frontends ir lib tools midend)
Expand Down
3 changes: 0 additions & 3 deletions backends/bmv2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ set (BMV2_SIMPLE_SWITCH_SRCS
simple_switch/simpleSwitch.h
simple_switch/options.h
)
add_cpplint_files (${CMAKE_CURRENT_SOURCE_DIR} "${BMV2_SIMPLE_SWITCH_SRCS}")

set (BMV2_PSA_SWITCH_SRCS
psa_switch/main.cpp
Expand All @@ -42,7 +41,6 @@ set (BMV2_PSA_SWITCH_SRCS
psa_switch/options.cpp
psa_switch/options.h
)
add_cpplint_files (${CMAKE_CURRENT_SOURCE_DIR} "${BMV2_PSA_SWITCH_SRCS}")

set (BMV2_BACKEND_COMMON_SRCS
common/JsonObjects.cpp
Expand Down Expand Up @@ -83,7 +81,6 @@ set (BMV2_BACKEND_COMMON_HDRS
)

set (IR_DEF_FILES ${IR_DEF_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/bmv2.def PARENT_SCOPE)
add_cpplint_files (${CMAKE_CURRENT_SOURCE_DIR} "${BMV2_BACKEND_COMMON_SRCS};${BMV2_BACKEND_COMMON_HDRS}")

build_unified(BMV2_BACKEND_COMMON_SRCS)
add_library(bmv2backend ${P4C_STATIC_BUILD} ${BMV2_BACKEND_COMMON_SRCS})
Expand Down
6 changes: 3 additions & 3 deletions backends/common/removeComplexExpressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef MIDEND_REMOVE_COMPLEX_EXPRESSIONS_H_
#define MIDEND_REMOVE_COMPLEX_EXPRESSIONS_H_
#ifndef BACKENDS_COMMON_REMOVECOMPLEXEXPRESSIONS_H_
#define BACKENDS_COMMON_REMOVECOMPLEXEXPRESSIONS_H_

#include "ir/ir.h"
#include "frontends/p4/typeMap.h"
Expand Down Expand Up @@ -100,4 +100,4 @@ class RemoveComplexExpressions : public Transform {

}

#endif /* MIDEND_REMOVE_COMPLEX_EXPRESSIONS_H_ */
#endif /* BACKENDS_COMMON_REMOVECOMPLEXEXPRESSIONS_H_ */
1 change: 0 additions & 1 deletion backends/dpdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ foreach(src IN LISTS DPDK_IR_SRCS)
endforeach()
set(EXTENSION_FRONTEND_SOURCES ${EXTENSION_FRONTEND_SOURCES} ${QUAL_DPDK_IR_SRCS} PARENT_SCOPE)

add_cpplint_files(${CMAKE_CURRENT_SOURCE_DIR} "${P4C_DPDK_SOURCES};${P4C_DPDK_HEADERS};${DPDK_IR_SRCS}")
add_executable(p4c-dpdk ${P4C_DPDK_SOURCES})
target_link_libraries (p4c-dpdk dpdk_runtime ${P4C_LIBRARIES} ${P4C_LIB_DEPS})
add_dependencies(p4c-dpdk dpdk_runtime genIR frontend)
Expand Down
2 changes: 0 additions & 2 deletions backends/ebpf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ set (P4C_EBPF_HDRS
psa/externs/ebpfPsaMeter.h
)

add_cpplint_files(${CMAKE_CURRENT_SOURCE_DIR} "${P4C_EBPF_SRCS};${P4C_EBPF_HDRS}")

set (P4C_EBPF_DIST_HEADERS p4include/ebpf_model.p4)

build_unified(P4C_EBPF_SRCS)
Expand Down
2 changes: 0 additions & 2 deletions backends/graphs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ set (GRAPHS_HDRS
graph_visitor.h
)

add_cpplint_files(${CMAKE_CURRENT_SOURCE_DIR} "${GRAPHS_SRCS};${GRAPHS_HDRS}")

build_unified(GRAPHS_SRCS ALL)
add_executable(p4c-graphs ${GRAPHS_SRCS} ${EXTENSION_P4_14_CONV_SOURCES})
target_link_libraries (p4c-graphs ${P4C_LIBRARIES} ${P4C_LIB_DEPS})
Expand Down
2 changes: 0 additions & 2 deletions backends/p4test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ set (P4TEST_HDRS
midend.h
)

add_cpplint_files (${CMAKE_CURRENT_SOURCE_DIR} "${P4TEST_SRCS};${P4TEST_HDRS}")

build_unified(P4TEST_SRCS ALL)
add_executable(p4test ${P4TEST_SRCS} ${EXTENSION_P4_14_CONV_SOURCES})
target_link_libraries (p4test ${P4C_LIBRARIES} ${P4C_LIB_DEPS})
Expand Down
23 changes: 8 additions & 15 deletions backends/p4tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ if(ENABLE_IWYU)
-Xiwyu
--no_fwd_decls
-Xiwyu
--mapping_file=${CMAKE_CURRENT_LIST_DIR}/scripts/tools/iwyu_mappings/p4c.imp
--mapping_file=${P4C_SOURCE_DIR}/tools/iwyu_mappings/p4c.imp
-Xiwyu
--mapping_file=${CMAKE_CURRENT_LIST_DIR}/scripts/tools/iwyu_mappings/boost-1.75-all.imp
--mapping_file=${P4C_SOURCE_DIR}/tools/iwyu_mappings/boost-1.75-all.imp
-Xiwyu
--mapping_file=${CMAKE_CURRENT_LIST_DIR}/scripts/tools/iwyu_mappings/libcxx.imp
--mapping_file=${P4C_SOURCE_DIR}/tools/iwyu_mappings/libcxx.imp
-Xiwyu
--mapping_file=${CMAKE_CURRENT_LIST_DIR}/scripts/tools/iwyu_mappings/gcc.libc.imp
--mapping_file=${P4C_SOURCE_DIR}/tools/iwyu_mappings/gcc.libc.imp
-Xiwyu
--mapping_file=${CMAKE_CURRENT_LIST_DIR}/scripts/tools/iwyu_mappings/stl.c.headers.imp
--mapping_file=${P4C_SOURCE_DIR}/tools/iwyu_mappings/stl.c.headers.imp
)
message("IWYU command: ${iwyu_path}")
endif()
Expand All @@ -79,16 +79,9 @@ enable_testing()
set(ENABLE_TESTING ON)

# Include sub projects.
add_and_lint_subdirectory(${CMAKE_CURRENT_LIST_DIR}/common ${P4C_SOURCE_DIR}/tools)
add_and_lint_subdirectory(${CMAKE_CURRENT_LIST_DIR}/testgen ${P4C_SOURCE_DIR}/tools)
add_and_lint_subdirectory(${CMAKE_CURRENT_LIST_DIR}/p4check ${P4C_SOURCE_DIR}/tools)

# Add clang-format to checks.
add_test(
NAME "testgen-clang-format"
COMMAND sh -c "${CMAKE_CURRENT_LIST_DIR}/scripts/tools/run-clang-format.sh"
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/common)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/testgen)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/p4check)

# Custom IR constructs for P4Tools.
set(IR_DEF_FILES ${IR_DEF_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/common/testgen.def PARENT_SCOPE)
3 changes: 0 additions & 3 deletions backends/p4tools/scripts/tools/iwyu_mappings/p4c.imp

This file was deleted.

28 changes: 0 additions & 28 deletions backends/p4tools/scripts/tools/run-cpplint.sh

This file was deleted.

2 changes: 0 additions & 2 deletions backends/ubpf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ set(P4C_UBPF_HEADERS

set (P4C_UBPF_DIST_HEADERS p4include/ubpf_model.p4)

add_cpplint_files(${CMAKE_CURRENT_SOURCE_DIR} "${P4C_UBPF_SOURCES};${P4C_UBPF_HEADERS}")

build_unified(P4C_UBPF_SOURCES ALL)
add_executable(p4c-ubpf ${P4C_UBPF_SOURCES})
target_link_libraries (p4c-ubpf ${P4C_LIBRARIES} ${P4C_LIB_DEPS})
Expand Down
14 changes: 7 additions & 7 deletions backends/ubpf/ubpfHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef P4C_UBPFHELPERS_H
#define P4C_UBPFHELPERS_H
#ifndef BACKENDS_UBPF_UBPFHELPERS_H_
#define BACKENDS_UBPF_UBPFHELPERS_H_

namespace UBPF {

#ifndef UNUSED
# define UNUSED __attribute__((__unused__))
#endif
#ifndef UNUSED
#define UNUSED __attribute__((__unused__))
#endif

}
} // namespace UBPF

#endif //P4C_UBPFHELPERS_H
#endif // BACKENDS_UBPF_UBPFHELPERS_H_
Loading

0 comments on commit e25e930

Please sign in to comment.