Browse Source

Lint job with clang-tidy.

Yao Wei Tjong 姚伟忠 5 years ago
parent
commit
f18fefa2cd

File diff suppressed because it is too large
+ 0 - 2
.clang-tidy


+ 3 - 2
.github/workflows/ci_cd.rake

@@ -23,7 +23,7 @@
 desc 'Prepare environment for CI'
 task :ci do
   ENV['URHO3D_PCH'] = '0' if ENV['PLATFORM'] == 'linux-gcc' # TODO - PCH causes cache miss on initial build for Linux/GCC, why?
-  platform_modifier = /(.*)-(.+)/.match(ENV['PLATFORM'])
+  platform_modifier = /(.+?)-(.+)/.match(ENV['PLATFORM'])
   if platform_modifier
     ENV['PLATFORM'] = platform_modifier[1]
     ENV['MODIFIER'] = platform_modifier[2]
@@ -40,7 +40,7 @@ task :ci do
     end
   else
     ENV['URHO3D_DEPLOYMENT_TARGET'] = 'generic' if /linux|mingw/ =~ ENV['PLATFORM']
-    if ENV['MODIFIER'] == 'clang'
+    if /clang/ =~ ENV['MODIFIER']
       ENV['CC'] = 'clang'
       ENV['CXX'] = 'clang++'
     end
@@ -60,6 +60,7 @@ task :ci do
   end
   ENV['URHO3D_LIB_TYPE'] = ENV['LIB_TYPE'].upcase
   ENV['URHO3D_TESTING'] = '1' if /linux|macOS|win/ =~ ENV['PLATFORM']
+  ENV['URHO3D_LINT'] = '1' if ENV['MODIFIER'] == 'clang-tidy'
   # Enable all the bells and whistles
   %w[URHO3D_DATABASE_SQLITE URHO3D_EXTRAS].each { |it| ENV[it] = '1' }
 end

+ 1 - 0
.github/workflows/main.yml

@@ -54,6 +54,7 @@ jobs:
           - { platform: android, lib-type: static }
           - { platform: android, lib-type: shared }
           - { platform: web, lib-type: static }
+          - { platform: linux-clang-tidy, lib-type: static}
     env:
       HOST: ${{ github.job }}
       PLATFORM: ${{ matrix.platform }}

+ 6 - 1
CMake/Modules/UrhoCommon.cmake

@@ -730,6 +730,11 @@ else ()
             set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcolor-diagnostics")
             set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
         endif ()
+        if (URHO3D_LINT)
+            # Don't show any diagnostics while in linter mode
+            set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
+            set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
+        endif ()
         if ((NOT APPLE AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.1) OR (APPLE AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.0.0))
             # Workaround for Clang 7.0.1 and above until the Bullet upstream has fixed the Clang 7 diagnostic checks issue (see https://github.com/bulletphysics/bullet3/issues/2114)
             # ditto for AppleClang 11.0.0 and above
@@ -1856,7 +1861,7 @@ macro (setup_lint)
     if (URHO3D_LINT)
         find_program (CLANG_TIDY clang-tidy NO_CMAKE_FIND_ROOT_PATH)
         if (CLANG_TIDY)
-            set (URHO3D_PCH 0)
+            set (CMAKE_C_CLANG_TIDY ${CLANG_TIDY} -config=)
             set (CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY} -config=)
             set (CMAKE_EXPORT_COMPILE_COMMANDS 1)
         else ()

+ 14 - 0
Rakefile

@@ -65,6 +65,7 @@ task build: [:cmake] do
     concurrent = '/maxCpuCount'
   else
     concurrent = "-j #{$max_jobs}"
+    filter = "2>#{lint_err_file}" if ENV['URHO3D_LINT']
   end
   system %Q{cmake --build "#{build_tree}" #{build_config} #{target} -- #{concurrent} #{ENV['BUILD_PARAMS']} #{filter}} or abort
   system "ccache -s" if ENV['USE_CCACHE']
@@ -75,6 +76,9 @@ task :test do
   if ENV['PLATFORM'] == 'android'
     Rake::Task['gradle'].invoke('test')
     next
+  elsif ENV['URHO3D_LINT']
+    Rake::Task['lint'].invoke
+    next
   end
   dir = build_tree
   wrapper = ENV['CI'] && ENV['PLATFORM'] == 'linux' ? 'xvfb-run' : ''
@@ -89,6 +93,12 @@ task :gradle, [:task] do |_, args|
   system "./gradlew #{args[:task]} #{ENV['CI'] ? '--console plain' : ''}" or abort
 end
 
+task :lint do
+  lint_err = File.read(lint_err_file)
+  puts lint_err
+  abort 'Failed to pass linter checks' unless lint_err.empty?
+  puts 'Passed the linter checks'
+end
 
 ### Internal methods ###
 
@@ -127,6 +137,10 @@ def init_default
   end
 end
 
+def lint_err_file
+  'build/clang-tidy.out'
+end
+
 
 # Load custom rake scripts
 Dir['.github/workflows/*.rake'].each { |r| load r }

+ 31 - 0
Source/ThirdParty/.clang-tidy

@@ -0,0 +1,31 @@
+#
+# Copyright (c) 2008-2020 the Urho3D project.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+
+---
+Checks: '-*,bugprone-integer-division'
+WarningsAsErrors: ''
+HeaderFilterRegex: ''
+AnalyzeTemporaryDtors: false
+FormatStyle: none
+...
+
+# vi: set ts=2 sw=2 expandtab:

+ 3 - 0
Source/Urho3D/CMakeLists.txt

@@ -434,6 +434,9 @@ if (URHO3D_LUA)
             COMMENT "Generating tolua++ API binding on the fly for ${DIR}")
     endforeach ()
     source_group ("Source Files\\LuaScript\\Generated" FILES ${LUA_GEN_CPP_FILES})
+    if (URHO3D_LINT)
+        execute_process (COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../ThirdParty/.clang-tidy ${CMAKE_CURRENT_BINARY_DIR}/LuaScript/generated)
+    endif ()
 endif ()
 
 # Aggregate all source files

+ 1 - 0
script/.build-options

@@ -4,6 +4,7 @@ MINGW
 WEB
 IOS
 TVOS
+URHO3D_LINT
 URHO3D_64BIT
 URHO3D_ANGELSCRIPT
 URHO3D_LUA

Some files were not shown because too many files changed in this diff