Bug 212280 - [CMake] Add static analyzers
Summary: [CMake] Add static analyzers
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CMake (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Don Olmstead
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-22 14:30 PDT by Don Olmstead
Modified: 2020-05-26 12:29 PDT (History)
12 users (show)

See Also:


Attachments
Patch (7.54 KB, patch)
2020-05-22 14:46 PDT, Don Olmstead
no flags Details | Formatted Diff | Diff
Patch (7.55 KB, patch)
2020-05-22 14:50 PDT, Don Olmstead
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Don Olmstead 2020-05-22 14:30:25 PDT
Add some static analyzers supported through CMake. IWYU, clang-tidy, LWYU.
Comment 1 Don Olmstead 2020-05-22 14:46:37 PDT Comment hidden (obsolete)
Comment 2 Don Olmstead 2020-05-22 14:50:22 PDT
Created attachment 400079 [details]
Patch
Comment 3 David Kilzer (:ddkilzer) 2020-05-22 16:17:31 PDT
Comment on attachment 400079 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=400079&action=review

r=me

> ChangeLog:11
> +        Add support for static analyzers within CMake builds. Supported analyzers are
> +        clang-tidy, iwyu (include-what-you-use) and lwyu (link-what-you-use). They can
> +        be enabled by passing a semicolon separated list to CMake through the ANALYZERS
> +        option.

Is the clang static analyzer supported in a different way?  (I'm curious because that's the first "analyzer" I think of when I see the word.  No need to change this patch to accomodate.)

> Source/cmake/WebKitFeatures.cmake:92
> +        message(STATUS "Unified builds are disabled when analyzing sources")

I'm curious why this is.  When using the clang static analyzer, it's actually more useful to build with unified sources because it gives the static analyzer more code to work with (especially in deep mode).
Comment 4 David Kilzer (:ddkilzer) 2020-05-22 16:19:01 PDT
Comment on attachment 400079 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=400079&action=review

>> Source/cmake/WebKitFeatures.cmake:92
>> +        message(STATUS "Unified builds are disabled when analyzing sources")
> 
> I'm curious why this is.  When using the clang static analyzer, it's actually more useful to build with unified sources because it gives the static analyzer more code to work with (especially in deep mode).

Okay, I see why disabling this would be useful for IWYU, but it probably doesn't make a difference on the other two (unless clang-tidy gets too slow or uses too much memory with unified sources).
Comment 5 Don Olmstead 2020-05-26 10:29:58 PDT
Comment on attachment 400079 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=400079&action=review

>> ChangeLog:11
>> +        option.
> 
> Is the clang static analyzer supported in a different way?  (I'm curious because that's the first "analyzer" I think of when I see the word.  No need to change this patch to accomodate.)

My understanding is that the clang static analyzer runs by masquerading as a compiler.

https://stackoverflow.com/a/21785566

To support it for ports using CMake I think you'd need to do something like the above potentially in the build-webkit script. I haven't been able to find the magical invocation to make it work on Windows but that would be my assumption.

>>> Source/cmake/WebKitFeatures.cmake:92
>>> +        message(STATUS "Unified builds are disabled when analyzing sources")
>> 
>> I'm curious why this is.  When using the clang static analyzer, it's actually more useful to build with unified sources because it gives the static analyzer more code to work with (especially in deep mode).
> 
> Okay, I see why disabling this would be useful for IWYU, but it probably doesn't make a difference on the other two (unless clang-tidy gets too slow or uses too much memory with unified sources).

I split this off of https://bugs.webkit.org/show_bug.cgi?id=206738 which specifically wants UNIFIED_BUILDS turned off. The link-what-you-use functionality just plays with linker options to determine if something isn't used by the linker so it seemed excessive to turn off unified builds over that hence the check for the EXEs.
Comment 6 Michael Catanzaro 2020-05-26 11:27:36 PDT
(In reply to Don Olmstead from comment #5)
> To support it for ports using CMake I think you'd need to do something like
> the above potentially in the build-webkit script. I haven't been able to
> find the magical invocation to make it work on Windows but that would be my
> assumption.

I think setting -DCMAKE_CXX_COMPILER=scan-build might suffice, but haven't tried this.
Comment 7 EWS 2020-05-26 12:29:33 PDT
Committed r262156: <https://trac.webkit.org/changeset/262156>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 400079 [details].