@@ -531,8 +531,62 @@ CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \
531531 tools/icu/* .h \
532532 ) )
533533
534- cpplint :
535- @$(PYTHON ) tools/cpplint.py $(CPPLINT_FILES )
534+ GOOGLE_DOWNLOAD ?= tools/format/download_from_google_storage
535+ GOOGLE_DOWNLOAD_FLAGS ?= --no_resume --no_auth
536+
537+ tools/format/clang-format-mac : tools/format/clang-format-mac.sha1
538+ @echo " Downloading clang-format, may take some time"
539+ @$(GOOGLE_DOWNLOAD ) $(GOOGLE_DOWNLOAD_FLAGS ) --platform=darwin \
540+ --bucket chromium-clang-format -s $<
541+
542+ tools/format/clang-format-win.exe : tools/format/clang-format-win.exe.sha1
543+ @echo " Downloading clang-format, may take some time"
544+ @$(GOOGLE_DOWNLOAD ) $(GOOGLE_DOWNLOAD_FLAGS ) --platform=win32 \
545+ --bucket chromium-clang-format -s $<
546+
547+ tools/format/clang-format-linux64 : tools/format/clang-format-linux64.sha1
548+ @echo " Downloading clang-format, may take some time"
549+ @$(GOOGLE_DOWNLOAD ) $(GOOGLE_DOWNLOAD_FLAGS ) --platform=linux* \
550+ --bucket chromium-clang-format -s $<
551+
552+ ifeq ($(OSTYPE ) ,darwin)
553+ CLANG_EXTERNAL_FORMAT ?= tools/format/clang-format-mac
554+ else ifeq ($(OSTYPE),linux)
555+ CLANG_EXTERNAL_FORMAT ?= tools/format/clang-format-linux64
556+ else
557+ CLANG_EXTERNAL_FORMAT ?= tools/format/clang-format-win.exe
558+ endif
559+
560+ ifneq ("$(wildcard $(CLANG_EXTERNAL_FORMAT ) ) ", "")
561+ CLANG_FORMAT ?= $(CLANG_EXTERNAL_FORMAT )
562+ else
563+ CLANG_FORMAT ?= clang-format
564+ endif
565+
566+ CLANG_LINT ?= ./tools/format/git-clang-format --binary $(CLANG_FORMAT )
567+ CLANG_LINT_BASE ?= origin/master
568+ CLANG_LINT_COMMIT ?= $(shell git merge-base @ $(CLANG_LINT_BASE ) )
569+
570+ download-clang-format : $(CLANG_EXTERNAL_FORMAT )
571+
572+ check-clang-format-version :
573+ @ ($( CLANG_FORMAT) -version | grep -q " 3\.[78]\.0" ) || \
574+ (echo " Wrong clang-format version, expected either 3.7.0 or 3.8.0" && \
575+ exit 1)
576+
577+ cpplint : check-clang-format-version
578+ @echo " Formatting against $( CLANG_LINT_COMMIT) "
579+ @if [[ $$ ($( CLANG_LINT) $( CLANG_LINT_COMMIT) --diff -- $( CPPLINT_FILES) | grep " diff " ) ]]; then \
580+ echo " Lint issues detected, please run \" make format-commit\" " ; \
581+ exit 1; \
582+ fi
583+
584+ format-commit : check-clang-format-version
585+ @$(CLANG_LINT ) -- $(CPPLINT_FILES )
586+
587+ install-pre-commit-hook : check-clang-format-version
588+ @echo " #!/bin/sh\nexec make format-commit" > .git/hooks/pre-commit
589+ @chmod +x .git/hooks/pre-commit
536590
537591lint : jslint cpplint
538592
@@ -541,4 +595,5 @@ lint: jslint cpplint
541595 dynamiclib test test-all test-addons build-addons website-upload pkg \
542596 blog blogclean tar binary release-only bench-http-simple bench-idle \
543597 bench-all bench bench-misc bench-array bench-buffer bench-net \
544- bench-http bench-fs bench-tls cctest run-ci
598+ bench-http bench-fs bench-tls cctest run-ci format-commit \
599+ install-pre-commit-hook download-clang-format check-clang-format-version
0 commit comments