Clang static analyzer

Aperta
#59 7 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
cmake, python
Ambito
build-system

Direzione di ricerca

The proposal touches mod/config.py, mod/project.py, cmake/fips_private.cmake and a new mod/tools/scan.py wrapper for scan-build. Start by reading how an existing optional tool such as mod/tools/ninja.py is wired into config.check_build_tool and project.build. Done means the ScanBuild build type selects a scan-build tool and the analyzer runs; the proposed diff references a scan module and a linux-make-scan config that do not exist in the repo yet, so confirm the current state first.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

feature

I suggest to add Clang static analyzer to the list of fips targets. It will help to keep project in a good shape. I just run it right now with Oryol project and it shows 0 issues. Cool!!!

Diff:

diff --git a/cmake/fips_private.cmake b/cmake/fips_private.cmake
index 752ca87..5dd9f7f 100644
--- a/cmake/fips_private.cmake
+++ b/cmake/fips_private.cmake
@@ -177,6 +177,8 @@ macro(fips_choose_config)
             set (FIPS_CONFIG "linux-make-release")
         elseif (${CMAKE_BUILD_TYPE} AND ${CMAKE_BUILD_TYPE} STREQUAL "Profiling")
             set (FIPS_CONFIG "linux-make-profiling")
+        elseif (${CMAKE_BUILD_TYPE} AND ${CMAKE_BUILD_TYPE} STREQUAL "ScanBuild")
+            set (FIPS_CONFIG "linux-make-scan")
         else()
             set (FIPS_CONFIG "linux-make-debug")
         endif()
diff --git a/mod/config.py b/mod/config.py
index 80503cb..1db545e 100644
--- a/mod/config.py
+++ b/mod/config.py
@@ -5,7 +5,7 @@ import glob
 import yaml
 from collections import OrderedDict
 from mod import log, util
-from mod.tools import cmake, make, ninja, xcodebuild
+from mod.tools import cmake, make, ninja, xcodebuild, scan
 from mod import emscripten, nacl, android

 platforms = [
@@ -67,13 +67,15 @@ build_tools = [
     'make',
     'ninja',
     'xcodebuild',
+    'scan-build',
     'cmake'
 ]

 build_types = [
     'Release',
     'Debug',
-    'Profiling'
+    'Profiling',
+    'ScanBuild'
 ]

 default_config = {
@@ -226,6 +228,8 @@ def check_build_tool(fips_dir, tool_name) :
         return ninja.check_exists(fips_dir)
     elif tool_name == 'xcodebuild' :
         return xcodebuild.check_exists(fips_dir)
+    elif tool_name == 'scan-build' :
+        return scan.check_exists(fips_dir)
     else :
         return False;

diff --git a/mod/project.py b/mod/project.py
index 8359ae5..cae9162 100644
--- a/mod/project.py
+++ b/mod/project.py
@@ -6,7 +6,7 @@ import subprocess
 import yaml

 from mod import log, util, config, dep, template, settings
-from mod.tools import git, cmake, make, ninja, xcodebuild, ccmake, cmake_gui
+from mod.tools import git, cmake, make, ninja, xcodebuild, scan, ccmake, cmake_gui

 #-------------------------------------------------------------------------------
 def init(fips_dir, proj_name) :
@@ -181,6 +181,8 @@ def make_clean(fips_dir, proj_dir, cfg_name) :
                     result = ninja.run_clean(fips_dir, build_dir)
                 elif cfg['build_tool'] == xcodebuild.name :
                     result = xcodebuild.run_clean(fips_dir, build_dir)
+                elif cfg['build_tool'] == scan.name :
+                    result = scan.run_clean(fips_dir, build_dir)
                 else :
                     result = cmake.run_clean(fips_dir, build_dir)

@@ -240,6 +242,8 @@ def build(fips_dir, proj_dir, cfg_name, target=None) :
                     result = ninja.run_build(fips_dir, target, build_dir, num_jobs)
                 elif cfg['build_tool'] == xcodebuild.name :
                     result = xcodebuild.run_build(fips_dir, target, cfg['build_type'], build_dir, num_jobs)
+                elif cfg['build_tool'] == scan.name :
+                    result = scan.run_build(fips_dir, target, build_dir, num_jobs)
                 else :
                     result = cmake.run_build(fips_dir, target, cfg['build_type'], build_dir)


configs/linux-make-scan.yml:


---
platform: linux 
generator: Unix Makefiles
build_tool: scan-build
build_type: ScanBuild

mod/tools/scan.py:

"""
wrapper for scan-build tool 
"""
import subprocess

name = 'scan-build'
platforms = ['linux'] #, 'osx', 'win']
optional = True
not_found = "required for generating Clang static analyze report"

#-------------------------------------------------------------------------------
def check_exists(fips_dir) :
    """test if make tool is in the path

    :returns: True if make tool is in path
    """
    try:
        out = subprocess.check_output('scan-build -h', shell=True)
        return True
    except (OSError, subprocess.CalledProcessError):
        return False;

#-------------------------------------------------------------------------------
def run_build(fips_dir, target, build_dir, num_jobs=1) :
    """make a build target

    :param target:      name of build target, or None
    :param build_dir:   directory where Makefile is located
    :param num_jobs:    number of jobs, default is 1
    :returns:           True if build was successful
    """
    cmdLine = 'scan-build --use-analyzer /usr/local/bin/clang -o {}/oryol-scan make -j{}'.format(build_dir, num_jobs)
    if target is not None :
        cmdLine += ' ' + target;
    print(cmdLine)
    res = subprocess.call(cmdLine, cwd=build_dir, shell=True)
    return res == 0

#-------------------------------------------------------------------------------
def run_clean(fips_dir, build_dir) :
    """run the special 'clean' target

    :param build_dir:   directory where Makefile is located
    :returns:           True if make returned with success
    """
    return True

Lingua principale
Python
Stelle
506
Fork
84
Merge medio
13h 14m
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di floooh/fips

Tutte le issue di floooh/fips

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.