[PATCH] D90362: scan-build supprot relative 'file' in cdb.

2020-10-28 Thread Yu Shan via Phabricator via cfe-commits
aabbaabb created this revision.
aabbaabb added reviewers: xazax.hun, phosek.
Herald added subscribers: cfe-commits, rnkovacs, whisperity.
Herald added a project: clang.
aabbaabb requested review of this revision.

Excluded folders in scan build is turned to absolute path before
comapre to 'file' in cdb. 'file' in cdb might be a path relative
to 'directory', so we need to turn it to absolute path before
comparison.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90362

Files:
  clang/tools/scan-build-py/libscanbuild/analyze.py


Index: clang/tools/scan-build-py/libscanbuild/analyze.py
===
--- clang/tools/scan-build-py/libscanbuild/analyze.py
+++ clang/tools/scan-build-py/libscanbuild/analyze.py
@@ -207,10 +207,14 @@
 def run_analyzer_parallel(args):
 """ Runs the analyzer against the given compilation database. """
 
-def exclude(filename):
+def exclude(filename, directory):
 """ Return true when any excluded directory prefix the filename. """
-return any(re.match(r'^' + directory, filename)
-   for directory in args.excludes)
+if not os.path.isabs(filename):
+# filename is either absolute or relative to directory. Need to 
turn
+# it to absolute since 'args.excludes' are absolute paths.
+filename = os.path.normpath(os.path.join(directory, filename))
+return any(re.match(r'^' + exclude_directory, filename)
+   for exclude_directory in args.excludes)
 
 consts = {
 'clang': args.clang,
@@ -225,7 +229,8 @@
 logging.debug('run analyzer against compilation database')
 with open(args.cdb, 'r') as handle:
 generator = (dict(cmd, **consts)
- for cmd in json.load(handle) if not exclude(cmd['file']))
+ for cmd in json.load(handle) if not exclude(
+cmd['file'], cmd['directory']))
 # when verbose output requested execute sequentially
 pool = multiprocessing.Pool(1 if args.verbose > 2 else None)
 for current in pool.imap_unordered(run, generator):


Index: clang/tools/scan-build-py/libscanbuild/analyze.py
===
--- clang/tools/scan-build-py/libscanbuild/analyze.py
+++ clang/tools/scan-build-py/libscanbuild/analyze.py
@@ -207,10 +207,14 @@
 def run_analyzer_parallel(args):
 """ Runs the analyzer against the given compilation database. """
 
-def exclude(filename):
+def exclude(filename, directory):
 """ Return true when any excluded directory prefix the filename. """
-return any(re.match(r'^' + directory, filename)
-   for directory in args.excludes)
+if not os.path.isabs(filename):
+# filename is either absolute or relative to directory. Need to turn
+# it to absolute since 'args.excludes' are absolute paths.
+filename = os.path.normpath(os.path.join(directory, filename))
+return any(re.match(r'^' + exclude_directory, filename)
+   for exclude_directory in args.excludes)
 
 consts = {
 'clang': args.clang,
@@ -225,7 +229,8 @@
 logging.debug('run analyzer against compilation database')
 with open(args.cdb, 'r') as handle:
 generator = (dict(cmd, **consts)
- for cmd in json.load(handle) if not exclude(cmd['file']))
+ for cmd in json.load(handle) if not exclude(
+cmd['file'], cmd['directory']))
 # when verbose output requested execute sequentially
 pool = multiprocessing.Pool(1 if args.verbose > 2 else None)
 for current in pool.imap_unordered(run, generator):
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90362: scan-build supprot relative 'file' in cdb.

2020-10-29 Thread Yu Shan via Phabricator via cfe-commits
aabbaabb added a comment.

Differential Revision: https://reviews.llvm.org/D90362


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90362/new/

https://reviews.llvm.org/D90362

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90362: scan-build supprot relative 'file' in cdb.

2020-10-29 Thread Yu Shan via Phabricator via cfe-commits
aabbaabb added a comment.

Gabor or Petr, 
Can any one of you help me commit this change? Not sure if I could commit 
myself.

In D90362#2361400 , @xazax.hun wrote:

> I know that the current situation is a mess, but there is an alternative 
> version of scan-build-py on Github, which is also distributed on pypi. Could 
> you check if that version is also susceptible to this problem and open a pull 
> request for the author in case it is?
>
> The repository is here: https://github.com/rizsotto/scan-build
>
> This would be the best way to ensure the bug is fixed for all the users.

Do you mean pull this change into that repo after this got submitted in trunk? 
Will do!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90362/new/

https://reviews.llvm.org/D90362

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90362: scan-build supprot relative 'file' in cdb.

2020-11-02 Thread Yu Shan via Phabricator via cfe-commits
aabbaabb added a comment.

kindly ping for help to submit this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90362/new/

https://reviews.llvm.org/D90362

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90362: scan-build supprot relative 'file' in cdb.

2020-11-02 Thread Yu Shan via Phabricator via cfe-commits
aabbaabb added a comment.

I think there are also some patches that only exist here not on that repo so 
there is no strict upstream/downstream, just two forked versions.
Since in our use case, we would likely use this version instead of the python 
version (easier to update/maintain), I suggest just adding the fix we need here.
For this specific bug, the python version is already fixed in a different way 
by reading the code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90362/new/

https://reviews.llvm.org/D90362

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101139: Create install targets for scan-build-py.

2021-05-12 Thread Yu Shan via Phabricator via cfe-commits
aabbaabb updated this revision to Diff 344904.
aabbaabb marked 3 inline comments as done.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101139/new/

https://reviews.llvm.org/D101139

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake
  clang/tools/CMakeLists.txt
  clang/tools/scan-build-py/CMakeLists.txt
  clang/tools/scan-build-py/bin/analyze-build
  clang/tools/scan-build-py/bin/analyze-c++
  clang/tools/scan-build-py/bin/analyze-cc
  clang/tools/scan-build-py/bin/intercept-build
  clang/tools/scan-build-py/bin/intercept-c++
  clang/tools/scan-build-py/bin/intercept-cc
  clang/tools/scan-build-py/bin/scan-build
  clang/tools/scan-build-py/libear/__init__.py
  clang/tools/scan-build-py/libear/config.h.in
  clang/tools/scan-build-py/libear/ear.c
  clang/tools/scan-build-py/libexec/libear/__init__.py
  clang/tools/scan-build-py/libexec/libear/config.h.in
  clang/tools/scan-build-py/libexec/libear/ear.c
  clang/tools/scan-build-py/libexec/libscanbuild/__init__.py
  clang/tools/scan-build-py/libexec/libscanbuild/analyze.py
  clang/tools/scan-build-py/libexec/libscanbuild/arguments.py
  clang/tools/scan-build-py/libexec/libscanbuild/clang.py
  clang/tools/scan-build-py/libexec/libscanbuild/compilation.py
  clang/tools/scan-build-py/libexec/libscanbuild/intercept.py
  clang/tools/scan-build-py/libexec/libscanbuild/report.py
  clang/tools/scan-build-py/libexec/libscanbuild/resources/scanview.css
  clang/tools/scan-build-py/libexec/libscanbuild/resources/selectable.js
  clang/tools/scan-build-py/libexec/libscanbuild/resources/sorttable.js
  clang/tools/scan-build-py/libexec/libscanbuild/shell.py
  clang/tools/scan-build-py/libscanbuild/__init__.py
  clang/tools/scan-build-py/libscanbuild/analyze.py
  clang/tools/scan-build-py/libscanbuild/arguments.py
  clang/tools/scan-build-py/libscanbuild/clang.py
  clang/tools/scan-build-py/libscanbuild/compilation.py
  clang/tools/scan-build-py/libscanbuild/intercept.py
  clang/tools/scan-build-py/libscanbuild/report.py
  clang/tools/scan-build-py/libscanbuild/resources/scanview.css
  clang/tools/scan-build-py/libscanbuild/resources/selectable.js
  clang/tools/scan-build-py/libscanbuild/resources/sorttable.js
  clang/tools/scan-build-py/libscanbuild/shell.py
  clang/tools/scan-build-py/tests/__init__.py
  clang/tools/scan-build-py/tests/unit/test_analyze.py

Index: clang/tools/scan-build-py/tests/unit/test_analyze.py
===
--- clang/tools/scan-build-py/tests/unit/test_analyze.py
+++ clang/tools/scan-build-py/tests/unit/test_analyze.py
@@ -18,9 +18,9 @@
 # scan-build can be easily matched up to compare results.
 def test_directory_name_comparison(self):
 with libear.TemporaryDirectory() as tmpdir, \
- sut.report_directory(tmpdir, False) as report_dir1, \
- sut.report_directory(tmpdir, False) as report_dir2, \
- sut.report_directory(tmpdir, False) as report_dir3:
+ sut.report_directory(tmpdir, False, 'html') as report_dir1, \
+ sut.report_directory(tmpdir, False, 'html') as report_dir2, \
+ sut.report_directory(tmpdir, False, 'html') as report_dir3:
 self.assertLess(report_dir1, report_dir2)
 self.assertLess(report_dir2, report_dir3)
 
Index: clang/tools/scan-build-py/tests/__init__.py
===
--- clang/tools/scan-build-py/tests/__init__.py
+++ clang/tools/scan-build-py/tests/__init__.py
@@ -3,6 +3,12 @@
 # See https://llvm.org/LICENSE.txt for license information.
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
+import os
+import sys
+
+this_dir = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(os.path.dirname(this_dir), 'libexec'))
+
 import unittest
 
 import tests.unit
Index: clang/tools/scan-build-py/libscanbuild/resources/sorttable.js
===
--- clang/tools/scan-build-py/libscanbuild/resources/sorttable.js
+++ /dev/null
@@ -1,492 +0,0 @@
-/*
-  SortTable
-  version 2
-  7th April 2007
-  Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/
-
-  Instructions:
-  Download this file
-  Add  to your HTML
-  Add class="sortable" to any table you'd like to make sortable
-  Click on the headers to sort
-
-  Thanks to many, many people for contributions and suggestions.
-  Licenced as X11: http://www.kryogenix.org/code/browser/licence.html
-  This basically means: do what you want with it.
-*/
-
-
-var stIsIE = /*@cc_on!@*/false;
-
-sorttable = {
-  init: function() {
-// quit if this function has already been called
-if (arguments.callee.done) return;
-// flag this function so we don't do the same thing twice
-arguments.callee.done = true;
-// kill the timer
-if (_timer) clearInterval(_timer);
-
-if (!document.createElement || !document.getElementsByTagName) return;
-
-sorttable.DATE_RE = /^(\d\d?)[

[PATCH] D101139: Create install targets for scan-build-py.

2021-05-13 Thread Yu Shan via Phabricator via cfe-commits
aabbaabb updated this revision to Diff 345329.
aabbaabb added a comment.

put libs in 'lib' folder, 'analyze-*' and 'scan-*' compiler wrappers to 
'libexec', also copy the resources in 'libscanbuild'

Tests:

To install:
DESTDIR=${INSTALL_DIR} ninja install-scan-build-py -j1000

Test at source folder:
PATH=~/llvm-project/build/libexec:~/llvm-project/build/bin:$PATH python -m 
unittest tests.unit
PATH=~/llvm-project/build/libexec:~/llvm-project/build/bin:$PATH python -m 
unittest tests.functional.cases

One error in functional test: test_successful_build_on_empty_env
I think this is intended behavior (clang not found?) since the test sets an 
empty environment for make.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101139/new/

https://reviews.llvm.org/D101139

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake
  clang/tools/CMakeLists.txt
  clang/tools/scan-build-py/CMakeLists.txt
  clang/tools/scan-build-py/bin/analyze-build
  clang/tools/scan-build-py/bin/analyze-c++
  clang/tools/scan-build-py/bin/analyze-cc
  clang/tools/scan-build-py/bin/intercept-build
  clang/tools/scan-build-py/bin/intercept-c++
  clang/tools/scan-build-py/bin/intercept-cc
  clang/tools/scan-build-py/bin/scan-build
  clang/tools/scan-build-py/lib/libear/__init__.py
  clang/tools/scan-build-py/lib/libear/config.h.in
  clang/tools/scan-build-py/lib/libear/ear.c
  clang/tools/scan-build-py/lib/libscanbuild/__init__.py
  clang/tools/scan-build-py/lib/libscanbuild/analyze.py
  clang/tools/scan-build-py/lib/libscanbuild/arguments.py
  clang/tools/scan-build-py/lib/libscanbuild/clang.py
  clang/tools/scan-build-py/lib/libscanbuild/compilation.py
  clang/tools/scan-build-py/lib/libscanbuild/intercept.py
  clang/tools/scan-build-py/lib/libscanbuild/report.py
  clang/tools/scan-build-py/lib/libscanbuild/resources/scanview.css
  clang/tools/scan-build-py/lib/libscanbuild/resources/selectable.js
  clang/tools/scan-build-py/lib/libscanbuild/resources/sorttable.js
  clang/tools/scan-build-py/lib/libscanbuild/shell.py
  clang/tools/scan-build-py/libear/__init__.py
  clang/tools/scan-build-py/libear/config.h.in
  clang/tools/scan-build-py/libear/ear.c
  clang/tools/scan-build-py/libexec/analyze-c++
  clang/tools/scan-build-py/libexec/analyze-cc
  clang/tools/scan-build-py/libexec/intercept-c++
  clang/tools/scan-build-py/libexec/intercept-cc
  clang/tools/scan-build-py/libscanbuild/__init__.py
  clang/tools/scan-build-py/libscanbuild/analyze.py
  clang/tools/scan-build-py/libscanbuild/arguments.py
  clang/tools/scan-build-py/libscanbuild/clang.py
  clang/tools/scan-build-py/libscanbuild/compilation.py
  clang/tools/scan-build-py/libscanbuild/intercept.py
  clang/tools/scan-build-py/libscanbuild/report.py
  clang/tools/scan-build-py/libscanbuild/resources/scanview.css
  clang/tools/scan-build-py/libscanbuild/resources/selectable.js
  clang/tools/scan-build-py/libscanbuild/resources/sorttable.js
  clang/tools/scan-build-py/libscanbuild/shell.py
  clang/tools/scan-build-py/tests/__init__.py
  clang/tools/scan-build-py/tests/functional/cases/__init__.py
  clang/tools/scan-build-py/tests/functional/cases/test_exec_anatomy.py
  clang/tools/scan-build-py/tests/functional/cases/test_from_cdb.py
  clang/tools/scan-build-py/tests/unit/test_analyze.py

Index: clang/tools/scan-build-py/tests/unit/test_analyze.py
===
--- clang/tools/scan-build-py/tests/unit/test_analyze.py
+++ clang/tools/scan-build-py/tests/unit/test_analyze.py
@@ -18,9 +18,9 @@
 # scan-build can be easily matched up to compare results.
 def test_directory_name_comparison(self):
 with libear.TemporaryDirectory() as tmpdir, \
- sut.report_directory(tmpdir, False) as report_dir1, \
- sut.report_directory(tmpdir, False) as report_dir2, \
- sut.report_directory(tmpdir, False) as report_dir3:
+ sut.report_directory(tmpdir, False, 'html') as report_dir1, \
+ sut.report_directory(tmpdir, False, 'html') as report_dir2, \
+ sut.report_directory(tmpdir, False, 'html') as report_dir3:
 self.assertLess(report_dir1, report_dir2)
 self.assertLess(report_dir2, report_dir3)
 
Index: clang/tools/scan-build-py/tests/functional/cases/test_from_cdb.py
===
--- clang/tools/scan-build-py/tests/functional/cases/test_from_cdb.py
+++ clang/tools/scan-build-py/tests/functional/cases/test_from_cdb.py
@@ -15,7 +15,7 @@
 def prepare_cdb(name, target_dir):
 target_file = 'build_{0}.json'.format(name)
 this_dir, _ = os.path.split(__file__)
-path = os.path.normpath(os.path.join(this_dir, '..', 'src'))
+path = os.path.abspath(os.path.join(this_dir, '..', 'src'))
 source_dir = os.path.join(path, 'compilation_database')
 source_file = os.path.join(source_dir, target_file + '.in')
 target_file = os.path.join(target_dir, 'compile_commands.json')
Index: clang/

[PATCH] D101139: Create install targets for scan-build-py.

2021-04-23 Thread Yu Shan via Phabricator via cfe-commits
aabbaabb added a comment.

The python script assumes relative directory while finding things. For example, 
for resources folder, it uses os.path.join(this_dir, 'resources') in report.py, 
which means resource need to be in the same dir as report.py. Similarly for the 
libscanbuild. it assumes the library is always at one level up from bin folder. 
Installing them to different directories would break the script.

In D101139#2713450 , @phosek wrote:

> I don't think this is sufficient. First, we want to be explicit and always 
> list individual files to install, we don't use patterns. Second, since 
> libscanbuild is a library, it shouldn't be installed inside the `bin` 
> directory. I think those should go either into `lib` or `share`. 
> `libscanbuild/resources` should definitely go into `share` as is already the 
> case for `scan-build`. Third, `libear` is a native component so that one 
> needs to be compiled first.




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101139/new/

https://reviews.llvm.org/D101139

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101139: Create install targets for scan-build-py.

2021-04-23 Thread Yu Shan via Phabricator via cfe-commits
aabbaabb added a comment.

In D101139#2713450 , @phosek wrote:

> I don't think this is sufficient. First, we want to be explicit and always 
> list individual files to install, we don't use patterns. Second, since 
> libscanbuild is a library, it shouldn't be installed inside the `bin` 
> directory. I think those should go either into `lib` or `share`. 
> `libscanbuild/resources` should definitely go into `share` as is already the 
> case for `scan-build`. Third, `libear` is a native component so that one 
> needs to be compiled first.

libear is built dynamically at runtime from build_libear function in 
libear/__init__.py which would be called by libscanbuild/analyze.py. It is not 
built statically.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101139/new/

https://reviews.llvm.org/D101139

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101139: Create install targets for scan-build-py.

2021-04-26 Thread Yu Shan via Phabricator via cfe-commits
aabbaabb added a comment.

In D101139#2718057 , @phosek wrote:

> In D101139#2713530 , @aabbaabb 
> wrote:
>
>> The python script assumes relative directory while finding things. For 
>> example, for resources folder, it uses os.path.join(this_dir, 'resources') 
>> in report.py, which means resource need to be in the same dir as report.py. 
>> Similarly for the libscanbuild. it assumes the library is always at one 
>> level up from bin folder. Installing them to different directories would 
>> break the script.
>
> We could reorganize things to match the final layout, that's the strategy 
> that https://github.com/llvm/llvm-project/tree/main/clang/tools/scan-build 
> uses as well.
>
> In D101139#2713551 , @aabbaabb 
> wrote:
>
>> libear is built dynamically at runtime from build_libear function in 
>> libear/__init__.py which would be called by libscanbuild/analyze.py. It is 
>> not built statically.
>
> Could we modify the code to avoid building libear at runtime and instead 
> build it with CMake. Is libear even needed when using compilation database?

If i copy libscanbuild/resources to out/share/, libscanbuild to 
out/libscanbuild, bin/* to bin, then resources would be in a different layout 
than the original src. You mean modifying the original source and move 
libscanbuild/resources out to share/resources and update the code reference?

We are not using libear, we are only using analyze-build not scan-build. For 
our usage, I could define a target that only copies analyze-build, not 
scan-build. However, I am not sure whether this is appropriate. On the other 
hand, building libear statically might require significant change to the code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101139/new/

https://reviews.llvm.org/D101139

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101139: Create install targets for scan-build-py.

2021-04-28 Thread Yu Shan via Phabricator via cfe-commits
aabbaabb updated this revision to Diff 341352.
aabbaabb edited the summary of this revision.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101139/new/

https://reviews.llvm.org/D101139

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake
  clang/tools/CMakeLists.txt
  clang/tools/scan-build-py/CMakeLists.txt
  clang/tools/scan-build-py/bin/analyze-build
  clang/tools/scan-build-py/bin/analyze-c++
  clang/tools/scan-build-py/bin/analyze-cc
  clang/tools/scan-build-py/bin/intercept-build
  clang/tools/scan-build-py/bin/intercept-c++
  clang/tools/scan-build-py/bin/intercept-cc
  clang/tools/scan-build-py/bin/scan-build
  clang/tools/scan-build-py/lib/libear/__init__.py
  clang/tools/scan-build-py/lib/libear/config.h.in
  clang/tools/scan-build-py/lib/libear/ear.c
  clang/tools/scan-build-py/lib/libscanbuild/__init__.py
  clang/tools/scan-build-py/lib/libscanbuild/analyze.py
  clang/tools/scan-build-py/lib/libscanbuild/arguments.py
  clang/tools/scan-build-py/lib/libscanbuild/clang.py
  clang/tools/scan-build-py/lib/libscanbuild/compilation.py
  clang/tools/scan-build-py/lib/libscanbuild/intercept.py
  clang/tools/scan-build-py/lib/libscanbuild/report.py
  clang/tools/scan-build-py/lib/libscanbuild/resources/scanview.css
  clang/tools/scan-build-py/lib/libscanbuild/resources/selectable.js
  clang/tools/scan-build-py/lib/libscanbuild/resources/sorttable.js
  clang/tools/scan-build-py/lib/libscanbuild/shell.py
  clang/tools/scan-build-py/libear/__init__.py
  clang/tools/scan-build-py/libear/config.h.in
  clang/tools/scan-build-py/libear/ear.c
  clang/tools/scan-build-py/libscanbuild/__init__.py
  clang/tools/scan-build-py/libscanbuild/analyze.py
  clang/tools/scan-build-py/libscanbuild/arguments.py
  clang/tools/scan-build-py/libscanbuild/clang.py
  clang/tools/scan-build-py/libscanbuild/compilation.py
  clang/tools/scan-build-py/libscanbuild/intercept.py
  clang/tools/scan-build-py/libscanbuild/report.py
  clang/tools/scan-build-py/libscanbuild/resources/scanview.css
  clang/tools/scan-build-py/libscanbuild/resources/selectable.js
  clang/tools/scan-build-py/libscanbuild/resources/sorttable.js
  clang/tools/scan-build-py/libscanbuild/shell.py

Index: clang/tools/scan-build-py/bin/scan-build
===
--- clang/tools/scan-build-py/bin/scan-build
+++ clang/tools/scan-build-py/bin/scan-build
@@ -8,7 +8,7 @@
 import sys
 import os.path
 this_dir = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(os.path.dirname(this_dir))
+sys.path.append(os.path.join(os.path.dirname(this_dir), 'lib'))
 
 from libscanbuild.analyze import scan_build
 
Index: clang/tools/scan-build-py/bin/intercept-cc
===
--- clang/tools/scan-build-py/bin/intercept-cc
+++ clang/tools/scan-build-py/bin/intercept-cc
@@ -7,7 +7,7 @@
 import sys
 import os.path
 this_dir = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(os.path.dirname(this_dir))
+sys.path.append(os.path.join(os.path.dirname(this_dir), 'lib'))
 
 from libscanbuild.intercept import intercept_compiler_wrapper
 sys.exit(intercept_compiler_wrapper())
Index: clang/tools/scan-build-py/bin/intercept-c++
===
--- clang/tools/scan-build-py/bin/intercept-c++
+++ clang/tools/scan-build-py/bin/intercept-c++
@@ -7,7 +7,7 @@
 import sys
 import os.path
 this_dir = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(os.path.dirname(this_dir))
+sys.path.append(os.path.join(os.path.dirname(this_dir), 'lib'))
 
 from libscanbuild.intercept import intercept_compiler_wrapper
 sys.exit(intercept_compiler_wrapper())
Index: clang/tools/scan-build-py/bin/intercept-build
===
--- clang/tools/scan-build-py/bin/intercept-build
+++ clang/tools/scan-build-py/bin/intercept-build
@@ -8,7 +8,7 @@
 import sys
 import os.path
 this_dir = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(os.path.dirname(this_dir))
+sys.path.append(os.path.join(os.path.dirname(this_dir), 'lib'))
 
 from libscanbuild.intercept import intercept_build
 
Index: clang/tools/scan-build-py/bin/analyze-cc
===
--- clang/tools/scan-build-py/bin/analyze-cc
+++ clang/tools/scan-build-py/bin/analyze-cc
@@ -7,7 +7,7 @@
 import sys
 import os.path
 this_dir = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(os.path.dirname(this_dir))
+sys.path.append(os.path.join(os.path.dirname(this_dir), 'lib'))
 
 from libscanbuild.analyze import analyze_compiler_wrapper
 sys.exit(analyze_compiler_wrapper())
Index: clang/tools/scan-build-py/bin/analyze-c++
===
--- clang/tools/scan-build-py/bin/analyze-c++
+++ clang/tools/scan-build-py/bin/analyze-c++
@@ -7,7 +7,8 @@
 import sys
 import os.path
 this_dir = os.path.dirname(os.path.realpat

[PATCH] D101139: Create install targets for scan-build-py.

2021-04-28 Thread Yu Shan via Phabricator via cfe-commits
aabbaabb added a comment.

In D101139#2721880 , @phosek wrote:

> In D101139#2718112 , @aabbaabb 
> wrote:
>
>> In D101139#2718057 , @phosek wrote:
>>
>>> In D101139#2713530 , @aabbaabb 
>>> wrote:
>>>
 The python script assumes relative directory while finding things. For 
 example, for resources folder, it uses os.path.join(this_dir, 'resources') 
 in report.py, which means resource need to be in the same dir as 
 report.py. Similarly for the libscanbuild. it assumes the library is 
 always at one level up from bin folder. Installing them to different 
 directories would break the script.
>>>
>>> We could reorganize things to match the final layout, that's the strategy 
>>> that https://github.com/llvm/llvm-project/tree/main/clang/tools/scan-build 
>>> uses as well.
>>>
>>> In D101139#2713551 , @aabbaabb 
>>> wrote:
>>>
 libear is built dynamically at runtime from build_libear function in 
 libear/__init__.py which would be called by libscanbuild/analyze.py. It is 
 not built statically.
>>>
>>> Could we modify the code to avoid building libear at runtime and instead 
>>> build it with CMake. Is libear even needed when using compilation database?
>>
>> If i copy libscanbuild/resources to out/share/, libscanbuild to 
>> out/libscanbuild, bin/* to bin, then resources would be in a different 
>> layout than the original src. You mean modifying the original source and 
>> move libscanbuild/resources out to share/resources and update the code 
>> reference?
>
> Do we still keep the source in sync with 
> https://github.com/rizsotto/scan-build? I was under the impression that the 
> two codebases have already started diverging.
>
>> We are not using libear, we are only using analyze-build not scan-build. For 
>> our usage, I could define a target that only copies analyze-build, not 
>> scan-build. However, I am not sure whether this is appropriate. On the other 
>> hand, building libear statically might require significant change to the 
>> code.
>
> We may consider introducing a CMake option to control whether to include 
> libear or not (which would also control whether to include `scan-build` or 
> not).

Updated the layout and listed individual files.
It is not trivial to separate out scan-build with analyze-build since all the 
logic is in one python lib file. Furthermore, libear is compiled with the cc 
compiler that is supplied as an argument to the tool, so i cannot turn that 
into a prebuilt without a large refactor to the codebase. I added a comment 
listing the reason.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101139/new/

https://reviews.llvm.org/D101139

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101139: Create install targets for scan-build-py.

2021-05-03 Thread Yu Shan via Phabricator via cfe-commits
aabbaabb updated this revision to Diff 342529.
aabbaabb added a comment.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

Rename scan-build to scan-build-py during install to prevent overwriting pearl 
implementation.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101139/new/

https://reviews.llvm.org/D101139

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake
  clang/tools/CMakeLists.txt
  clang/tools/scan-build-py/CMakeLists.txt
  clang/tools/scan-build-py/bin/analyze-build
  clang/tools/scan-build-py/bin/analyze-c++
  clang/tools/scan-build-py/bin/analyze-cc
  clang/tools/scan-build-py/bin/intercept-build
  clang/tools/scan-build-py/bin/intercept-c++
  clang/tools/scan-build-py/bin/intercept-cc
  clang/tools/scan-build-py/bin/scan-build
  clang/tools/scan-build-py/lib/libear/__init__.py
  clang/tools/scan-build-py/lib/libear/config.h.in
  clang/tools/scan-build-py/lib/libear/ear.c
  clang/tools/scan-build-py/lib/libscanbuild/__init__.py
  clang/tools/scan-build-py/lib/libscanbuild/analyze.py
  clang/tools/scan-build-py/lib/libscanbuild/arguments.py
  clang/tools/scan-build-py/lib/libscanbuild/clang.py
  clang/tools/scan-build-py/lib/libscanbuild/compilation.py
  clang/tools/scan-build-py/lib/libscanbuild/intercept.py
  clang/tools/scan-build-py/lib/libscanbuild/report.py
  clang/tools/scan-build-py/lib/libscanbuild/resources/scanview.css
  clang/tools/scan-build-py/lib/libscanbuild/resources/selectable.js
  clang/tools/scan-build-py/lib/libscanbuild/resources/sorttable.js
  clang/tools/scan-build-py/lib/libscanbuild/shell.py
  clang/tools/scan-build-py/libear/__init__.py
  clang/tools/scan-build-py/libear/config.h.in
  clang/tools/scan-build-py/libear/ear.c
  clang/tools/scan-build-py/libscanbuild/__init__.py
  clang/tools/scan-build-py/libscanbuild/analyze.py
  clang/tools/scan-build-py/libscanbuild/arguments.py
  clang/tools/scan-build-py/libscanbuild/clang.py
  clang/tools/scan-build-py/libscanbuild/compilation.py
  clang/tools/scan-build-py/libscanbuild/intercept.py
  clang/tools/scan-build-py/libscanbuild/report.py
  clang/tools/scan-build-py/libscanbuild/resources/scanview.css
  clang/tools/scan-build-py/libscanbuild/resources/selectable.js
  clang/tools/scan-build-py/libscanbuild/resources/sorttable.js
  clang/tools/scan-build-py/libscanbuild/shell.py

Index: clang/tools/scan-build-py/libscanbuild/resources/sorttable.js
===
--- clang/tools/scan-build-py/libscanbuild/resources/sorttable.js
+++ /dev/null
@@ -1,492 +0,0 @@
-/*
-  SortTable
-  version 2
-  7th April 2007
-  Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/
-
-  Instructions:
-  Download this file
-  Add  to your HTML
-  Add class="sortable" to any table you'd like to make sortable
-  Click on the headers to sort
-
-  Thanks to many, many people for contributions and suggestions.
-  Licenced as X11: http://www.kryogenix.org/code/browser/licence.html
-  This basically means: do what you want with it.
-*/
-
-
-var stIsIE = /*@cc_on!@*/false;
-
-sorttable = {
-  init: function() {
-// quit if this function has already been called
-if (arguments.callee.done) return;
-// flag this function so we don't do the same thing twice
-arguments.callee.done = true;
-// kill the timer
-if (_timer) clearInterval(_timer);
-
-if (!document.createElement || !document.getElementsByTagName) return;
-
-sorttable.DATE_RE = /^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/;
-
-forEach(document.getElementsByTagName('table'), function(table) {
-  if (table.className.search(/\bsortable\b/) != -1) {
-sorttable.makeSortable(table);
-  }
-});
-
-  },
-
-  makeSortable: function(table) {
-if (table.getElementsByTagName('thead').length == 0) {
-  // table doesn't have a tHead. Since it should have, create one and
-  // put the first table row in it.
-  the = document.createElement('thead');
-  the.appendChild(table.rows[0]);
-  table.insertBefore(the,table.firstChild);
-}
-// Safari doesn't support table.tHead, sigh
-if (table.tHead == null) table.tHead = table.getElementsByTagName('thead')[0];
-
-if (table.tHead.rows.length != 1) return; // can't cope with two header rows
-
-// Sorttable v1 put rows with a class of "sortbottom" at the bottom (as
-// "total" rows, for example). This is B&R, since what you're supposed
-// to do is put them in a tfoot. So, if there are sortbottom rows,
-// for backward compatibility, move them to tfoot (creating it if needed).
-sortbottomrows = [];
-for (var i=0; i5' : ' ▴';
-this.appendChild(sortrevind);
-return;
-  }
-  if (this.className.search(/\bsorttable_sorted_reverse\b/) != -1) {
-// if we're already sorted by this column in reverse, just
-// re-reverse the table, which is quicker
-sorttable.reverse(this.sorttable_tbody);
- 

[PATCH] D101139: Create install targets for scan-build-py.

2021-05-03 Thread Yu Shan via Phabricator via cfe-commits
aabbaabb marked an inline comment as done.
aabbaabb added inline comments.



Comment at: clang/tools/scan-build-py/CMakeLists.txt:8
+ "bin/intercept-cc"
+ "bin/scan-build")
+

wanders wrote:
> This overwrites the "bin/scan-build" that was installed from the scan-build 
> (no -py) subdirectory.
> 
> So with this  "scan-build" will suddenly mean the python variant instead of 
> the per variant. That might be fine (?), but can't be a good idea to have 
> that done by first installing the perl scan-build and then overwriting it 
> with the python scan-build.  Also the man-page that the perl variant installs 
> is not overwritten so "man scan-build" will show manual page for the perl 
> variant.
Thanks for the comment. I have renamed scan-build to scan-build-py during 
installation.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101139/new/

https://reviews.llvm.org/D101139

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101139: Create install targets for scan-build-py.

2021-05-06 Thread Yu Shan via Phabricator via cfe-commits
aabbaabb updated this revision to Diff 343541.
aabbaabb marked 3 inline comments as done.
aabbaabb added a comment.

Renamed lib to libexec and add custom rules to copy files to build output.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101139/new/

https://reviews.llvm.org/D101139

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake
  clang/tools/CMakeLists.txt
  clang/tools/scan-build-py/CMakeLists.txt
  clang/tools/scan-build-py/bin/analyze-build
  clang/tools/scan-build-py/bin/analyze-c++
  clang/tools/scan-build-py/bin/analyze-cc
  clang/tools/scan-build-py/bin/intercept-build
  clang/tools/scan-build-py/bin/intercept-c++
  clang/tools/scan-build-py/bin/intercept-cc
  clang/tools/scan-build-py/bin/scan-build
  clang/tools/scan-build-py/libear/__init__.py
  clang/tools/scan-build-py/libear/config.h.in
  clang/tools/scan-build-py/libear/ear.c
  clang/tools/scan-build-py/libexec/libear/__init__.py
  clang/tools/scan-build-py/libexec/libear/config.h.in
  clang/tools/scan-build-py/libexec/libear/ear.c
  clang/tools/scan-build-py/libexec/libscanbuild/__init__.py
  clang/tools/scan-build-py/libexec/libscanbuild/analyze.py
  clang/tools/scan-build-py/libexec/libscanbuild/arguments.py
  clang/tools/scan-build-py/libexec/libscanbuild/clang.py
  clang/tools/scan-build-py/libexec/libscanbuild/compilation.py
  clang/tools/scan-build-py/libexec/libscanbuild/intercept.py
  clang/tools/scan-build-py/libexec/libscanbuild/report.py
  clang/tools/scan-build-py/libexec/libscanbuild/resources/scanview.css
  clang/tools/scan-build-py/libexec/libscanbuild/resources/selectable.js
  clang/tools/scan-build-py/libexec/libscanbuild/resources/sorttable.js
  clang/tools/scan-build-py/libexec/libscanbuild/shell.py
  clang/tools/scan-build-py/libscanbuild/__init__.py
  clang/tools/scan-build-py/libscanbuild/analyze.py
  clang/tools/scan-build-py/libscanbuild/arguments.py
  clang/tools/scan-build-py/libscanbuild/clang.py
  clang/tools/scan-build-py/libscanbuild/compilation.py
  clang/tools/scan-build-py/libscanbuild/intercept.py
  clang/tools/scan-build-py/libscanbuild/report.py
  clang/tools/scan-build-py/libscanbuild/resources/scanview.css
  clang/tools/scan-build-py/libscanbuild/resources/selectable.js
  clang/tools/scan-build-py/libscanbuild/resources/sorttable.js
  clang/tools/scan-build-py/libscanbuild/shell.py
  clang/tools/scan-build-py/tests/__init__.py
  clang/tools/scan-build-py/tests/unit/test_analyze.py

Index: clang/tools/scan-build-py/tests/unit/test_analyze.py
===
--- clang/tools/scan-build-py/tests/unit/test_analyze.py
+++ clang/tools/scan-build-py/tests/unit/test_analyze.py
@@ -18,9 +18,9 @@
 # scan-build can be easily matched up to compare results.
 def test_directory_name_comparison(self):
 with libear.TemporaryDirectory() as tmpdir, \
- sut.report_directory(tmpdir, False) as report_dir1, \
- sut.report_directory(tmpdir, False) as report_dir2, \
- sut.report_directory(tmpdir, False) as report_dir3:
+ sut.report_directory(tmpdir, False, 'html') as report_dir1, \
+ sut.report_directory(tmpdir, False, 'html') as report_dir2, \
+ sut.report_directory(tmpdir, False, 'html') as report_dir3:
 self.assertLess(report_dir1, report_dir2)
 self.assertLess(report_dir2, report_dir3)
 
Index: clang/tools/scan-build-py/tests/__init__.py
===
--- clang/tools/scan-build-py/tests/__init__.py
+++ clang/tools/scan-build-py/tests/__init__.py
@@ -3,6 +3,12 @@
 # See https://llvm.org/LICENSE.txt for license information.
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
+import os
+import sys
+
+this_dir = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(os.path.dirname(this_dir), 'libexec'))
+
 import unittest
 
 import tests.unit
Index: clang/tools/scan-build-py/libscanbuild/resources/sorttable.js
===
--- clang/tools/scan-build-py/libscanbuild/resources/sorttable.js
+++ /dev/null
@@ -1,492 +0,0 @@
-/*
-  SortTable
-  version 2
-  7th April 2007
-  Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/
-
-  Instructions:
-  Download this file
-  Add  to your HTML
-  Add class="sortable" to any table you'd like to make sortable
-  Click on the headers to sort
-
-  Thanks to many, many people for contributions and suggestions.
-  Licenced as X11: http://www.kryogenix.org/code/browser/licence.html
-  This basically means: do what you want with it.
-*/
-
-
-var stIsIE = /*@cc_on!@*/false;
-
-sorttable = {
-  init: function() {
-// quit if this function has already been called
-if (arguments.callee.done) return;
-// flag this function so we don't do the same thing twice
-arguments.callee.done = true;
-// kill the timer
-if (_timer) clearInterval(_timer);
-
-if (!