Skip to content

Commit 94ebfea

Browse files
committed
Making clang-tidy parallelizable
- Clang-tidy has had all but its readablity-identifier-naming check enabled to ensure that it runs its fastest. - Clang-tidy took far too long on a single thread, so each file gets its own clang-tidy call in make, which makes it parallelizable, speeding up the `make tidy` call. - A few files had a few issues to buffer out that were detected by clang-tidy. - Building Hyperload bootloader has been added to the presumbit checks. - Also, fixed openocd config location. - Added Hyperload to link_projects.sh. - Colorized and made the output of make app or make bootloader more concise.
1 parent 06041c6 commit 94ebfea

File tree

10 files changed

+104
-88
lines changed

10 files changed

+104
-88
lines changed

.clang-tidy

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Checks: '-*,-clang-diagnostic-error,readability-identifier-naming'
2+
WarningsAsErrors: '*'
3+
CheckOptions:
4+
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
5+
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
6+
- { key: readability-identifier-naming.VariableCase, value: lower_case }
7+
- { key: readability-identifier-naming.PrivateMemberCase, value: lower_case }
8+
- { key: readability-identifier-naming.PrivateMemberSuffix, value: _ }
9+
- { key: readability-identifier-naming.StructCase, value: CamelCase }
10+
- { key: readability-identifier-naming.StructSuffix, value: _t }
11+
- { key: readability-identifier-naming.ParameterCase, value: lower_case }
12+
- { key: readability-identifier-naming.FunctionCase, value: CamelCase }
13+
- { key: readability-identifier-naming.MacroDefinition, value: UPPER_CASE }
14+
- { key: readability-identifier-naming.EnumConstantCase, value: CamelCase }
15+
- { key: readability-identifier-naming.EnumConstantPrefix, value: k }
16+
- { key: readability-identifier-naming.ConstantMemberCase, value: CamelCase }
17+
- { key: readability-identifier-naming.ConstantMemberPrefix, value: k }
18+
- { key: readability-identifier-naming.ClassConstantCase, value: CamelCase }
19+
- { key: readability-identifier-naming.ClassConstantPrefix, value: k }
20+
- { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase }
21+
- { key: readability-identifier-naming.GlobalConstantPrefix, value: k }
22+
- { key: readability-identifier-naming.LocalConstantCase, value: CamelCase }
23+
- { key: readability-identifier-naming.LocalConstantPrefix, value: k }
24+
- { key: readability-identifier-naming.StaticConstantCase, value: CamelCase }
25+
- { key: readability-identifier-naming.StaticConstantPrefix, value: k }
26+
- { key: readability-identifier-naming.ConstantCase, value: CamelCase }
27+
- { key: readability-identifier-naming.ConstantPrefix, value: k }

firmware/Hyperload/source/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
#include "L0_LowLevel/interrupt.hpp"
1414
#include "L0_LowLevel/LPC40xx.h"
1515
#include "L1_Drivers/system_clock.hpp"
16+
#include "L1_Drivers/system_timer.hpp"
1617
#include "L1_Drivers/uart.hpp"
1718
#include "L2_Utilities/debug.hpp"
1819
#include "L2_Utilities/macros.hpp"
1920
#include "L2_Utilities/time.hpp"
2021
#include "L3_HAL/onboard_led.hpp"
21-
#include "L4_Application/globals.hpp"
2222
#include "L5_Testing/factory_test.hpp"
2323

2424
#if !defined(BOOTLOADER) && !defined(CLANG_TIDY)

firmware/examples/SystemClock/source/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <project_config.hpp>
21
#include <cinttypes>
32
#include <cstdint>
43
#include <cstdio>

firmware/examples/Uart/source/main.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include <project_config.hpp>
2-
31
#include <cstdio>
42
#include <iterator>
53

firmware/library/L0_LowLevel/SystemFiles/core_cm4.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
3737
#pragma clang system_header /* treat file as system include file */
3838
#endif
39-
#pragma GCC system_header
39+
// #pragma GCC system_header
4040

4141
#ifndef __CORE_CM4_H_GENERIC
4242
#define __CORE_CM4_H_GENERIC

firmware/library/L4_Application/globals.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// TODO(kammce): rename this file to ram.hpp
22
#pragma once
3+
#include <cstdint>
4+
#include "L2_Utilities/macros.hpp"
35
// ========================
46
// Memory Map information
57
// ========================

firmware/library/config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ SJ2_DECLARE_CONSTANT(TASK_SCHEDULER_SIZE, uint8_t, kTaskSchedulerSize);
104104
#if !defined(SJ2_ESP8266_BUFFER_SIZE)
105105
#define SJ2_ESP8266_BUFFER_SIZE 512
106106
#endif // !defined(SJ2_ESP8266_BUFFER_SIZE)
107-
SJ2_DECLARE_CONSTANT(ESP8266_BUFFER_SIZE, std::size_t, kEsp8266BufferSize);
107+
SJ2_DECLARE_CONSTANT(ESP8266_BUFFER_SIZE, size_t, kEsp8266BufferSize);
108108

109109
/// Used to define the log level of the build
110110
#if !defined(SJ2_LOG_LEVEL)

makefile

Lines changed: 53 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ endif
5252

5353
UNAME_S := $(shell uname -s)
5454
CLANG_TIDY = $(SJCLANG)/clang-tidy
55+
CLANG_TIDY_RUNNER = $(SJCLANG)/../share/clang/run-clang-tidy.py
5556

5657
# Internal build directories
5758
BUILD_DIR = build
@@ -109,7 +110,7 @@ DISABLED_WARNINGS = -Wno-main -Wno-variadic-macros
109110
# stdlib=libc++ : tell clang to ignore GCC standard libs
110111
INCLUDES = -I"$(CURRENT_DIRECTORY)/" \
111112
-I"$(LIB_DIR)/" \
112-
-idirafter"$(LIB_DIR)/L0_LowLevel/SystemFiles" \
113+
-I"$(LIB_DIR)/L0_LowLevel/SystemFiles" \
113114
-idirafter"$(LIB_DIR)/third_party/" \
114115
-idirafter"$(LIB_DIR)/third_party/printf" \
115116
-idirafter"$(LIB_DIR)/third_party/FreeRTOS/Source" \
@@ -214,6 +215,7 @@ LINT_FILES = $(shell find $(FIRMWARE) \
214215
-name "*.cpp" | \
215216
$(FILE_EXCLUDES) \
216217
2> /dev/null)
218+
LINT_FILES_PHONY = $(LINT_FILES:=.lint)
217219
# Remove all test files from SOURCE_FILES
218220
SOURCES = $(filter-out $(SOURCE_TESTS), $(SOURCE_FILES))
219221
ifeq ($(MAKECMDGOALS), test)
@@ -283,13 +285,13 @@ help:
283285
@echo " multi-debug - run multiarch gdb with current projects .elf file"
284286
@echo
285287

288+
# Shows the help menu without any targets specified
286289
default: help
287-
# Just shows the help menu
288290
bootloader: build
289291
# Build recipe
290292
application: build
291-
build: $(DBC_DIR) $(OBJ_DIR) $(BIN_DIR) $(SIZE) $(LIST) $(HEX) $(BINARY)
292-
# Complete rebuild and flash installation#
293+
build: $(DBC_DIR) $(OBJ_DIR) $(BIN_DIR) $(LIST) $(HEX) $(BINARY) $(SIZE)
294+
# Complete rebuild and flash installation
293295
cleaninstall: clean build flash
294296
# Debug recipe to show internal list contents
295297
show-lists:
@@ -314,102 +316,82 @@ show-lists:
314316
@echo "=========== OMIT_LIBRARIES =============="
315317
@echo $(OMIT_LIBRARIES)
316318

319+
# shell echo must be used to ensure that the \x1B makes it into the variable
320+
# simply doing YELLOW=\x1B[33;1m works on Linux but the forward slash is omitted
321+
# on mac.
322+
YELLOW=$(shell echo "\x1B[33;1m")
323+
RESET=$(shell echo "\x1B[0m")
324+
GREEN=$(shell echo "\x1B[32;1m")
325+
317326
$(HEX): $(EXECUTABLE)
318-
@echo ' '
319-
@echo 'Invoking: Cross ARM GNU Create Flash Image'
327+
@printf '$(YELLOW)Generating Hex Image $(RESET) : $@ '
320328
@$(OBJCOPY) -O ihex "$<" "$@"
321-
@echo 'Finished building: $@'
322-
@echo ' '
329+
@printf '$(GREEN)Hex Generated!$(RESET)\n'
323330

324331
$(BINARY): $(EXECUTABLE)
325-
@echo ' '
326-
@echo 'Invoking: Cross ARM GNU Create Flash Binary Image'
332+
@printf '$(YELLOW)Generating Binary Image $(RESET): $@ '
327333
@$(OBJCOPY) -O binary "$<" "$@"
328-
@echo 'Finished building: $@'
329-
@echo ' '
334+
@printf '$(GREEN)Binary Generated!$(RESET)\n'
330335

331336
$(SIZE): $(EXECUTABLE)
332337
@echo ' '
333-
@echo 'Invoking: Cross ARM GNU Print Size'
338+
@echo 'Showing Image Size Information: '
334339
@$(SIZEC) --format=berkeley "$<"
335-
@echo 'Finished building: $@'
336340
@echo ' '
337341

338-
#--line-numbers --disassemble --source
339342
$(LIST): $(EXECUTABLE)
340-
@echo ' '
341-
@echo 'Invoking: Cross ARM GNU Create Assembly Listing'
343+
@printf '$(YELLOW)Generating Disassembly$(RESET) : $@ '
342344
@$(OBJDUMP) --disassemble --all-headers --source --demangle --wide "$<" > "$@"
343-
@echo 'Finished building: $@'
344-
@echo ' '
345+
@printf '$(GREEN)Disassembly Generated!$(RESET)\n'
345346

346347
$(EXECUTABLE): $(OBJECT_FILES)
347-
@echo 'Invoking: Cross ARM C++ Linker'
348+
@printf '$(YELLOW)Linking Executable $(RESET) : $@ '
348349
@mkdir -p "$(dir $@)"
349350
@$(CPPC) $(LINKFLAGS) -o "$@" $(OBJECT_FILES)
350-
@echo 'Finished building target: $@'
351+
@printf '$(GREEN)Executable Generated!$(RESET)\n'
351352

352353
$(OBJ_DIR)/%.o: %.cpp
353-
@echo 'Building file: $<'
354-
@echo 'Invoking: Cross ARM C++ Compiler'
354+
@printf '$(YELLOW)Building file (C++) $(RESET): $< '
355355
@mkdir -p "$(dir $@)"
356356
@$(CPPC) $(CPPFLAGS) -std=c++17 -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
357-
@echo 'Finished building: $<'
358-
@echo ' '
357+
@printf '$(GREEN)DONE!$(RESET)\n'
359358

360359
$(OBJ_DIR)/%.o: %.c
361-
@echo 'Building file: $<'
362-
@echo 'Invoking: Cross ARM C Compiler'
360+
@printf '$(YELLOW)Building file ( C ) $(RESET): $< '
363361
@mkdir -p "$(dir $@)"
364362
@$(CC) $(CFLAGS) -std=gnu11 -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
365-
@echo 'Finished building: $<'
366-
@echo ' '
363+
@printf '$(GREEN)DONE!$(RESET)\n'
367364

368365
$(OBJ_DIR)/%.o: %.s
369-
@echo 'Building Assembly file: $<'
370-
@echo 'Invoking: Cross ARM C Compiler'
366+
@printf '$(YELLOW)Building file (Asm) $(RESET): $< '
371367
@mkdir -p "$(dir $@)"
372368
@$(CC) $(CFLAGS) -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
373-
@echo 'Finished building: $<'
374-
@echo ' '
369+
@printf '$(GREEN)DONE!$(RESET)\n'
375370

376371
$(OBJ_DIR)/%.o: %.S
377-
@echo 'Building Assembly file: $<'
378-
@echo 'Invoking: Cross ARM C Compiler'
372+
@printf '$(YELLOW)Building file (Asm) $(RESET): $< '
379373
@mkdir -p "$(dir $@)"
380374
@$(CC) $(CFLAGS) -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
381-
@echo 'Finished building: $<'
382-
@echo ' '
375+
@printf '$(GREEN)DONE!$(RESET)\n'
383376

384377
$(OBJ_DIR)/%.o: $(LIB_DIR)/%.cpp
385-
@echo 'Building C++ file: $<'
386-
@echo 'Invoking: Cross ARM C++ Compiler'
378+
@printf '$(YELLOW)Building file (C++) $(RESET): $< '
387379
@mkdir -p "$(dir $@)"
388380
@$(CPPC) $(CPPFLAGS) -std=c++17 -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
389-
@echo 'Finished building: $<'
390-
@echo ' '
381+
@printf '$(GREEN)DONE!$(RESET)\n'
391382

392383
$(OBJ_DIR)/%.o: $(LIB_DIR)/%.c
393-
@echo 'Building C file: $<'
394-
@echo 'Invoking: Cross ARM C Compiler'
384+
@printf '$(YELLOW)Building file ( C ) $(RESET): $< '
395385
@mkdir -p "$(dir $@)"
396386
@$(CC) $(CFLAGS) -std=gnu11 -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
397-
@echo 'Finished building: $<'
398-
@echo ' '
387+
@printf '$(GREEN)DONE!$(RESET)\n'
399388

400389
$(DBC_BUILD):
401390
python2.7 "$(LIB_DIR)/$(DBC_DIR)/dbc_parse.py" -i "$(LIB_DIR)/$(DBC_DIR)/243.dbc" -s $(ENTITY) > $(DBC_BUILD)
402391

403-
$(DBC_DIR):
404-
mkdir -p $(DBC_DIR)
405-
406-
$(OBJ_DIR):
407-
@echo 'Creating Objects Folder: $<'
408-
mkdir -p $(OBJ_DIR)
409-
410-
$(BIN_DIR):
411-
@echo 'Creating Binary Folder: $<'
412-
mkdir -p $(BIN_DIR)
392+
$(OBJ_DIR) $(BIN_DIR) $(DBC_DIR):
393+
@echo 'Creating Folder: $@'
394+
mkdir -p "$@"
413395

414396
clean:
415397
rm -fR $(BUILD_DIR)
@@ -427,7 +409,6 @@ telemetry:
427409
test: $(COVERAGE) $(TEST_EXEC)
428410

429411
run-test: $(COVERAGE)
430-
# Set LD_LIBRARY_PATH to the clang
431412
$(TEST_EXEC) $(TEST_ARGS)
432413
gcovr --root="$(FIRMWARE)/" --keep --object-directory="$(BUILD_DIR)/" \
433414
-e "$(LIB_DIR)/newlib" \
@@ -440,36 +421,43 @@ $(COVERAGE):
440421
mkdir -p $(COVERAGE)
441422

442423
$(TEST_EXEC): $(TEST_FRAMEWORK) $(OBJECT_FILES)
424+
@printf '$(YELLOW)Linking Test Executable $(RESET) : $@ '
443425
@mkdir -p "$(dir $@)"
444-
@echo 'Finished building target: $@'
445426
@$(CPPC) -fprofile-arcs -fPIC -fexceptions -fno-inline \
446427
-fno-inline-small-functions -fno-default-inline \
447428
-fkeep-inline-functions -fno-elide-constructors \
448429
-ftest-coverage -O0 -fsanitize=address \
449430
-std=c++17 -stdlib=libc++ -lc++ -lc++abi \
450431
-o $(TEST_EXEC) $(OBJECT_FILES)
432+
@printf '$(GREEN)Test Executable Generated!$(RESET)\n'
451433

452434
%.hpp.gch: %.hpp
453-
@echo 'Precompiling HPP file: $<'
454-
@echo 'Invoking: C Compiler'
435+
@printf '$(YELLOW)Precompiling file (h++) $(RESET): $< '
455436
@mkdir -p "$(dir $@)"
456437
@$(CPPC) $(CFLAGS) -std=c++17 -stdlib=libc++ -MF"$(@:%.o=%.d)" -MT"$(@)" \
457438
-o "$@" $(LIB_DIR)/L5_Testing/testing_frameworks.hpp
458-
@echo 'Finished building: $<'
459-
@echo ' '
439+
@printf '$(GREEN)DONE!$(RESET)\n'
460440

461441
lint:
462442
@python2.7 $(TOOLS)/cpplint/cpplint.py $(LINT_FILES)
463443

464-
tidy:
465-
@$(CLANG_TIDY) -extra-arg=-std=c++17 $(LINT_FILES) -- -std=c++17 \
466-
$(INCLUDES) -D CLANG_TIDY=1 -D HOST_TEST=1
444+
tidy: $(LINT_FILES_PHONY)
445+
@printf '$(GREEN)Tidy Evaluation Complete. Everything clear!$(RESET)\n'
446+
447+
%.lint: %
448+
@printf '$(YELLOW)Evaluating file: $(RESET)$< '
449+
@$(CLANG_TIDY) $(if $(or $(findstring .hpp,$<), $(findstring .cpp,$<)), \
450+
-extra-arg="-std=c++17") "$<" -- \
451+
-D CLANG_TIDY=1 -D HOST_TEST=1 \
452+
-isystem"$(SJCLANG)/../include/c++/v1/" \
453+
-stdlib=libc++ $(INCLUDES) 2> /dev/null
454+
@printf '$(GREEN)DONE!$(RESET)\n'
467455

468456
presubmit:
469457
@$(TOOLS)/presubmit.sh
470458

471459
openocd:
472-
openocd -f $(TOOLS)/OpenOCD/sjtwo.cfg
460+
openocd -f $(FIRMWARE)/debug/sjtwo.cfg
473461

474462
debug:
475463
arm-none-eabi-gdb -ex "target remote :3333" $(EXECUTABLE)

tools/link_projects.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ then
1919
fi
2020

2121
# DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )
22-
PROJECTS=(${SJBASE}/firmware/HelloWorld/ ${SJBASE}/firmware/examples/*/)
22+
PROJECTS=(${SJBASE}/firmware/HelloWorld/ ${SJBASE}/firmware/Hyperload/ \
23+
${SJBASE}/firmware/examples/*/)
2324
for PROJECT in ${PROJECTS[@]}
2425
do
2526
echo "Creating link for: $PROJECT/env.sh"

0 commit comments

Comments
 (0)