Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package bazel-compilation-database for 
openSUSE:Factory checked in at 2026-09-19 22:20:22
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/bazel-compilation-database (Old)
 and      /work/SRC/openSUSE:Factory/.bazel-compilation-database.new.383539 
(New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "bazel-compilation-database"

Sat Sep 19 22:20:22 2026 rev:2 rq:1378867 version:0.5.2

Changes:
--------
--- 
/work/SRC/openSUSE:Factory/bazel-compilation-database/bazel-compilation-database.changes
    2019-12-27 14:01:02.440880497 +0100
+++ 
/work/SRC/openSUSE:Factory/.bazel-compilation-database.new.383539/bazel-compilation-database.changes
        2026-09-19 22:21:29.313470426 +0200
@@ -1,0 +2,23 @@
+Sun Sep 13 06:21:15 UTC 2026 - Martin Pluskal <[email protected]>
+
+- Update to version 0.5.2:
+  * Rewrite generate.sh in Python as generate.py, fixing JSON
+    processing issues.
+  * Support clang-tidy checks through the aspect.
+  * Add a tool to obtain the dynamic Bazel output_base value instead
+    of relying on realpath.
+  * Pass extra options on to Bazel after `--` and allow overriding
+    the target query expression.
+  * Propagate the aspect through filegroup rules and collect sources
+    from non_arc_srcs attributes.
+  * Handle generated headers and virtual_includes via the
+    header_files output group.
+  * Assume header-only libraries are C++ and omit targets without
+    compilation commands.
+  * Replace removed ObjCProvider APIs for Bazel 4.0 compatibility.
+  * Honor local defines, defines containing spaces, and read the
+    Bazel binary path from an environment variable.
+- Switch _service tar_scm/recompress/set_version from legacy
+  mode="disabled" to mode="manual".
+
+-------------------------------------------------------------------

Old:
----
  bazel-compilation-database-0.4.1.tar.xz

New:
----
  bazel-compilation-database-0.5.2.tar.xz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ bazel-compilation-database.spec ++++++
--- /var/tmp/diff_new_pack.yAxjAS/_old  2026-09-19 22:21:30.271510386 +0200
+++ /var/tmp/diff_new_pack.yAxjAS/_new  2026-09-19 22:21:30.273510469 +0200
@@ -1,7 +1,7 @@
 #
 # spec file for package bazel-compilation-database
 #
-# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
+# Copyright (c) 2026 SUSE LLC and contributors
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -12,19 +12,17 @@
 # license that conforms to the Open Source Definition (Version 1.9)
 # published by the Open Source Initiative.
 
-# Please submit bugfixes or comments via http://bugs.opensuse.org/
+# Please submit bugfixes or comments via https://bugs.opensuse.org/
 #
 
 
-%define src_install_dir /usr/src/%{name}
-
+%define src_install_dir %{_prefix}/src/%{name}
 Name:           bazel-compilation-database
-Version:        0.4.1
+Version:        0.5.2
 Release:        0
 Summary:        Clang JSON Compilation Database generator for Bazel
 License:        Apache-2.0 
-Group:          Development/Tools/Building
-Url:            https://github.com/grailbio/bazel-compilation-database
+URL:            https://github.com/grailbio/bazel-compilation-database
 Source:         %{name}-%{version}.tar.xz
 BuildRequires:  fdupes
 
@@ -34,7 +32,6 @@
 
 %package source
 Summary:        Source code of bazel-compilation-database
-Group:          Development/Sources
 BuildArch:      noarch
 
 %description source

++++++ _service ++++++
--- /var/tmp/diff_new_pack.yAxjAS/_old  2026-09-19 22:21:30.304511762 +0200
+++ /var/tmp/diff_new_pack.yAxjAS/_new  2026-09-19 22:21:30.307511888 +0200
@@ -1,16 +1,16 @@
 <services>
-  <service mode="disabled" name="tar_scm">
+  <service mode="manual" name="tar_scm">
     <param 
name="url">https://github.com/grailbio/bazel-compilation-database</param>
     <param name="scm">git</param>
     <param name="changesgenerate">enable</param>
     <param name="filename">bazel-compilation-database</param>
     <param name="versionformat">@PARENT_TAG@</param>
-    <param name="revision">0.4.1</param>
+    <param name="revision">0.5.2</param>
   </service>
-  <service mode="disabled" name="recompress">
+  <service mode="manual" name="recompress">
     <param name="file">*.tar</param>
     <param name="compression">xz</param>
   </service>
-  <service mode="disabled" name="set_version"/>
+  <service mode="manual" name="set_version"/>
 </services>
 

++++++ _servicedata ++++++
--- /var/tmp/diff_new_pack.yAxjAS/_old  2026-09-19 22:21:30.328512764 +0200
+++ /var/tmp/diff_new_pack.yAxjAS/_new  2026-09-19 22:21:30.331512889 +0200
@@ -1,6 +1,6 @@
 <servicedata>
 <service name="tar_scm">
                 <param 
name="url">https://github.com/grailbio/bazel-compilation-database</param>
-              <param 
name="changesrevision">842648bfece8af38a403ba47dd06180f13d767b8</param></service></servicedata>
+              <param 
name="changesrevision">765d43e7e0f8f28e07a48609c79407e7c133a6f8</param></service></servicedata>
 (No newline at EOF)
 

++++++ bazel-compilation-database-0.4.1.tar.xz -> 
bazel-compilation-database-0.5.2.tar.xz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/bazel-compilation-database-0.4.1/.github/workflows/migration.yml 
new/bazel-compilation-database-0.5.2/.github/workflows/migration.yml
--- old/bazel-compilation-database-0.4.1/.github/workflows/migration.yml        
1970-01-01 01:00:00.000000000 +0100
+++ new/bazel-compilation-database-0.5.2/.github/workflows/migration.yml        
2021-09-10 05:15:42.000000000 +0200
@@ -0,0 +1,19 @@
+name: Migration
+
+on:
+  push:
+    branches: [ master ]
+  pull_request:
+    branches: [ master ]
+
+jobs:
+  test:
+    runs-on: ubuntu-latest
+    strategy:
+      fail-fast: false
+    steps:
+    - uses: actions/checkout@v2
+    - name: Run migration tests
+      env:
+        BAZELISK_GITHUB_TOKEN: ${{ secrets.BAZELISK_GITHUB_TOKEN }}
+      run: tests/check_migration.sh
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/bazel-compilation-database-0.4.1/.github/workflows/tests.yml 
new/bazel-compilation-database-0.5.2/.github/workflows/tests.yml
--- old/bazel-compilation-database-0.4.1/.github/workflows/tests.yml    
1970-01-01 01:00:00.000000000 +0100
+++ new/bazel-compilation-database-0.5.2/.github/workflows/tests.yml    
2021-09-10 05:15:42.000000000 +0200
@@ -0,0 +1,21 @@
+name: Tests
+
+on:
+  push:
+    branches: [ master ]
+  pull_request:
+    branches: [ master ]
+
+jobs:
+  test:
+    runs-on: ${{ matrix.os }}
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [macos-latest, ubuntu-latest]
+    steps:
+    - uses: actions/checkout@v2
+    - name: Run tests
+      env:
+        BAZELISK_GITHUB_TOKEN: ${{ secrets.BAZELISK_GITHUB_TOKEN }}
+      run: tests/run_tests.sh
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/bazel-compilation-database-0.4.1/.travis.yml 
new/bazel-compilation-database-0.5.2/.travis.yml
--- old/bazel-compilation-database-0.4.1/.travis.yml    2019-10-15 
15:53:51.000000000 +0200
+++ new/bazel-compilation-database-0.5.2/.travis.yml    1970-01-01 
01:00:00.000000000 +0100
@@ -1,6 +0,0 @@
-sudo: false  # Not needing sudo enables container builds.
-dist: xenial
-
-script:
-  - tests/run_tests.sh
-  - tests/check_migration.sh
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/bazel-compilation-database-0.4.1/.ycm_extra_conf.py 
new/bazel-compilation-database-0.5.2/.ycm_extra_conf.py
--- old/bazel-compilation-database-0.4.1/.ycm_extra_conf.py     2019-10-15 
15:53:51.000000000 +0200
+++ new/bazel-compilation-database-0.5.2/.ycm_extra_conf.py     2021-09-10 
05:15:42.000000000 +0200
@@ -17,9 +17,9 @@
 """Configuration file for YouCompleteMe to fetch C++ compilation flags from
 Bazel.
 
-See https://valloric.github.io/YouCompleteMe/#c-family-semantic-completion for
+See https://github.com/ycm-core/YouCompleteMe#c-family-semantic-completion for
 how YCM works. In that section:
-For Option 1 (compilation database), use the generate.sh script in this
+For Option 1 (compilation database), use the generate.py script in this
 repository.
 For Option 2 (.ycm_extra_conf.py), symlink this file to the root of your
 workspace and bazel's output_base, or set it as your global config.
@@ -36,16 +36,20 @@
 import xml.etree.ElementTree as ElementTree
 
 
+_BAZEL = os.getenv("BAZEL_COMPDB_BAZEL_PATH") or "bazel"
+
+
 def bazel_info():
     """Returns a dict containing key values from bazel info."""
 
     bazel_info_dict = dict()
     try:
-        out = subprocess.check_output(['bazel', 
'info']).decode('utf-8').strip().split('\n')
+        out = subprocess.check_output([_BAZEL, 
'info']).decode('utf-8').strip().split('\n')
     except subprocess.CalledProcessError as err:
         # This exit code is returned when this command is run outside of a 
bazel workspace.
         if err.returncode == 2:
             sys.exit(0)
+        sys.exit(err.returncode)
 
     for line in out:
         key_val = line.strip().partition(": ")
@@ -57,7 +61,7 @@
     """Executes bazel query with the given args and returns the output."""
 
     # TODO: switch to cquery when it supports siblings and less crash-y with 
external repos.
-    query_cmd = ['bazel', 'query'] + args
+    query_cmd = [_BAZEL, 'query'] + args
     proc = subprocess.Popen(query_cmd, stdout=subprocess.PIPE)
     return proc.communicate()[0].decode('utf-8')
 
@@ -120,10 +124,8 @@
 def get_compdb_json(aspects_filepath, bazel_exec_root):
     """Returns the JSON string read from the file after necessary 
processing."""
 
-    compdb_json_str = "[\n"
     with open(aspects_filepath, 'r') as aspects_file:
-        compdb_json_str += aspects_file.read()
-    compdb_json_str += "\n]"
+        compdb_json_str = aspects_file.read()
     return re.sub('__EXEC_ROOT__', bazel_exec_root, compdb_json_str)
 
 def get_flags(filepath, compdb_json_str):
@@ -149,10 +151,9 @@
 
     return flags
 
-#pylint: disable=W0613,C0103
-def FlagsForFile(filename, **kwargs):
-    """Function that is called by YCM expecting a dict with at least a 'flags'
-    key that points to an array of strings as flags.
+def cfamily_settings(filename):
+    """Returns C-family settings as a dict with at least a 'flags' key that
+    points to an array of strings as flags.
     """
 
     bazel_info_dict = bazel_info()
@@ -190,11 +191,11 @@
     aspect_definition = 
'--aspects=@bazel_compdb//:aspects.bzl%compilation_database_aspect'
 
     bazel_aspects = [
-        'bazel',
+        _BAZEL,
         'build',
         aspect_definition,
         repository_override,
-        '--output_groups=compdb_files',
+        '--output_groups=compdb_files,header_files',
     ] + labels
     proc = subprocess.Popen(bazel_aspects, stdout=subprocess.PIPE, 
stderr=subprocess.PIPE)
     out, err = proc.communicate()
@@ -216,7 +217,16 @@
         'include_paths_relative_to_dir': bazel_exec_root,
         }
 
+#pylint: disable=C0103
+def Settings(**kwargs):
+    """Function that is called by YCM with language and filename arguments,
+    and expects a dict of language-specific settings.
+    """
+    if kwargs['language'] == 'cfamily':
+        return cfamily_settings(kwargs['filename'])
+    return {}
+
 # For testing; needs exactly one argument as path of file.
 if __name__ == '__main__':
     filename = os.path.abspath(sys.argv[1])
-    print(FlagsForFile(filename))
+    print(Settings(language='cfamily', filename=filename))
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/bazel-compilation-database-0.4.1/README.md 
new/bazel-compilation-database-0.5.2/README.md
--- old/bazel-compilation-database-0.4.1/README.md      2019-10-15 
15:53:51.000000000 +0200
+++ new/bazel-compilation-database-0.5.2/README.md      2021-09-10 
05:15:42.000000000 +0200
@@ -1,4 +1,4 @@
-Compilation database with Bazel [![Build 
Status](https://travis-ci.org/grailbio/bazel-compilation-database.svg?branch=master)](https://travis-ci.org/grailbio/bazel-compilation-database)
+Compilation database with Bazel 
[![Tests](https://github.com/grailbio/bazel-compilation-database/actions/workflows/tests.yml/badge.svg)](https://github.com/grailbio/bazel-compilation-database/actions/workflows/tests.yml)
 
[![Migration](https://github.com/grailbio/bazel-compilation-database/actions/workflows/migration.yml/badge.svg)](https://github.com/grailbio/bazel-compilation-database/actions/workflows/migration.yml)
 ===============================
 
 If you use [Bazel][bazel] and want to use libclang based editors and tools, you
@@ -13,7 +13,7 @@
 
 ### Entire repo
 
-Running generate.sh script from this project with current directory somewhere
+Running generate.py script from this project with current directory somewhere
 in your bazel workspace will generate a compile_commands.json file in the
 top-level directory of your workspace. You can even symlink the script to
 somewhere in your PATH.
@@ -21,16 +21,27 @@
 For example,
 ```sh
 INSTALL_DIR="/usr/local/bin"
-VERSION="0.4.0"
+VERSION="0.5.2"
 
 # Download and symlink.
 (
   cd "${INSTALL_DIR}" \
   && curl -L 
"https://github.com/grailbio/bazel-compilation-database/archive/${VERSION}.tar.gz";
 | tar -xz \
-  && ln -f -s 
"${INSTALL_DIR}/bazel-compilation-database-${VERSION}/generate.sh" bazel-compdb
+  && ln -f -s 
"${INSTALL_DIR}/bazel-compilation-database-${VERSION}/generate.py" bazel-compdb
 )
 
 bazel-compdb # This will generate compile_commands.json in your workspace root.
+
+# To pass additional flags to bazel, pass the flags as arguments after --
+bazel-compdb -- [additional flags for bazel]
+
+# You can tweak some behavior with flags:
+# 1. To use the source dir instead of bazel-execroot for directory in which 
clang commands are run.
+bazel-compdb -s
+bazel-compdb -s -- [additional flags for bazel]
+# 2. To consider only targets given by a specific query pattern, say 
`//cc/...`. Also see below section for another way.
+bazel-compdb -q //cc/...
+bazel-compdb -q //cc/... -- [additional flags for bazel]
 ```
 
 ### Selected targets
@@ -45,18 +56,21 @@
 
 In your WORKSPACE file:
 ```python
-# Change master to the git tag you want.
 http_archive(
     name = "com_grail_bazel_compdb",
-    strip_prefix = "bazel-compilation-database-master",
-    urls = 
["https://github.com/grailbio/bazel-compilation-database/archive/master.tar.gz";],
+    strip_prefix = "bazel-compilation-database-0.5.2",
+    urls = 
["https://github.com/grailbio/bazel-compilation-database/archive/0.5.2.tar.gz";],
 )
+
+load("@com_grail_bazel_compdb//:deps.bzl", "bazel_compdb_deps")
+bazel_compdb_deps()
 ```
 
-In your BUILD file:
+In your BUILD file located in any package:
 ```python
 ## Replace workspace_name and dir_path as per your setup.
-load("@com_grail_bazel_compdb//:aspects.bzl", "compilation_database")
+load("@com_grail_bazel_compdb//:defs.bzl", "compilation_database")
+load("@com_grail_bazel_output_base_util//:defs.bzl", "OUTPUT_BASE")
 
 compilation_database(
     name = "example_compdb",
@@ -64,11 +78,32 @@
         "//a_cc_binary_label",
         "//a_cc_library_label",
     ],
-    # ideally should be the same as `bazel info execution_root`.
-    exec_root = "/path/to/bazel/exec_root",
+    # OUTPUT_BASE is a dynamic value that will vary for each user workspace.
+    # If you would like your build outputs to be the same across users, then
+    # skip supplying this value, and substitute the default constant value
+    # "__OUTPUT_BASE__" through an external tool like `sed` or `jq` (see
+    # below shell commands for usage).
+    output_base = OUTPUT_BASE,
 )
 ```
 
+Then, in your terminal (you can wrap this in a shell script and check it in 
your repo):
+```
+# Command to generate the compilation database file.
+bazel build //path/to/pkg/dir:example_compdb
+
+# Location of the compilation database file.
+outfile="$(bazel info bazel-bin)/path/to/pkg/dir/compile_commands.json"
+
+# [Optional] Command to replace the marker for output_base in the file if you
+# did not use the dynamic value in the example above.
+output_base=$(bazel info output_base)
+sed -i.bak "s@__OUTPUT_BASE__@${output_base}@" "${outfile}"
+
+# The compilation database is now ready to use at this location.
+echo "Compilation Database: ${outfile}"
+```
+
 ### YouCompleteMe
 
 If you want to use this project solely for semantic auto completion using
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/bazel-compilation-database-0.4.1/WORKSPACE 
new/bazel-compilation-database-0.5.2/WORKSPACE
--- old/bazel-compilation-database-0.4.1/WORKSPACE      2019-10-15 
15:53:51.000000000 +0200
+++ new/bazel-compilation-database-0.5.2/WORKSPACE      2021-09-10 
05:15:42.000000000 +0200
@@ -1 +1,23 @@
-workspace(name = "bazel_compdb")
+# Copyright 2017 GRAIL, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+workspace(name = "com_grail_bazel_compdb")
+
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
+http_archive(
+    name = "rules_cc",
+    sha256 = 
"3057c13fa4d431eb0e7a9c28eea13f25987d29f869406b5ee3f2bd9c4134cb0c",
+    urls = 
["https://github.com/bazelbuild/rules_cc/archive/262ebec3c2296296526740db4aefce68c80de7fa.tar.gz";],
+)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/bazel-compilation-database-0.4.1/aspects.bzl 
new/bazel-compilation-database-0.5.2/aspects.bzl
--- old/bazel-compilation-database-0.4.1/aspects.bzl    2019-10-15 
15:53:51.000000000 +0200
+++ new/bazel-compilation-database-0.5.2/aspects.bzl    2021-09-10 
05:15:42.000000000 +0200
@@ -33,11 +33,20 @@
 
 CompilationAspect = provider()
 
+_cpp_header_extensions = [
+    "hh",
+    "hxx",
+    "ipp",
+    "hpp",
+]
+
+_c_or_cpp_header_extensions = ["h"] + _cpp_header_extensions
+
 _cpp_extensions = [
     "cc",
     "cpp",
     "cxx",
-]
+] + _cpp_header_extensions
 
 _cc_rules = [
     "cc_library",
@@ -54,40 +63,33 @@
 
 _all_rules = _cc_rules + _objc_rules
 
-def _compilation_db_json(compilation_db):
-    # Return a JSON string for the compilation db entries.
-
-    entries = [entry.to_json() for entry in compilation_db]
-    return ",\n ".join(entries)
-
 def _is_cpp_target(srcs):
+    if all([src.extension in _c_or_cpp_header_extensions for src in srcs]):
+        return True  # assume header-only lib is c++
     return any([src.extension in _cpp_extensions for src in srcs])
 
 def _is_objcpp_target(srcs):
-    for src in srcs:
-        if src.extension == "mm":
-            return True
+    return any([src.extension == "mm" for src in srcs])
 
-    return False
-
-def _sources(target, ctx):
+def _sources(ctx, target):
     srcs = []
-    if "srcs" in dir(ctx.rule.attr):
+    if hasattr(ctx.rule.attr, "srcs"):
         srcs += [f for src in ctx.rule.attr.srcs for f in src.files.to_list()]
-    if "hdrs" in dir(ctx.rule.attr):
+    if hasattr(ctx.rule.attr, "hdrs"):
         srcs += [f for src in ctx.rule.attr.hdrs for f in src.files.to_list()]
 
-    if ctx.rule.kind == "cc_proto_library":
-        srcs += [f for f in target.files.to_list() if f.extension in ["h", 
"cc"]]
-
     return srcs
 
 # Function copied from 
https://gist.github.com/oquenchil/7e2c2bd761aa1341b458cc25608da50c
-def get_compile_flags(dep):
+# TODO: Directly use create_compile_variables and 
get_memory_inefficient_command_line.
+def _get_compile_flags(dep):
     options = []
     compilation_context = dep[CcInfo].compilation_context
     for define in compilation_context.defines.to_list():
-        options.append("-D{}".format(define))
+        options.append("-D\"{}\"".format(define))
+
+    for define in compilation_context.local_defines.to_list():
+        options.append("-D\"{}\"".format(define))
 
     for system_include in compilation_context.system_includes.to_list():
         if len(system_include) == 0:
@@ -104,17 +106,47 @@
             quote_include = "."
         options.append("-iquote {}".format(quote_include))
 
+    for framework_include in compilation_context.framework_includes.to_list():
+        options.append("-F\"{}\"".format(framework_include))
+
     return options
 
-def _cc_compiler_info(ctx, target, srcs, feature_configuration, cc_toolchain):
-    compile_variables = None
-    compiler_options = None
-    compiler = None
-    compile_flags = None
-    force_language_mode_option = ""
+def _xcode_paths(ctx):
+    xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
+
+    sdk_version = 
xcode_config.sdk_version_for_platform(ctx.fragments.apple.single_arch_platform)
+    apple_env = apple_common.target_apple_env(xcode_config, 
ctx.fragments.apple.single_arch_platform)
+    sdk_platform = apple_env["APPLE_SDK_PLATFORM"]
+
+    # FIXME is there any way of getting the SDKROOT value here? The only thing 
that seems to know about it is
+    # XcodeLocalEnvProvider, but I can't seem to find a way to access that
+    platform_root = 
"/Applications/Xcode.app/Contents/Developer/Platforms/{platform}.platform".format(platform
 = sdk_platform)
+    sdk_root = 
"/Applications/Xcode.app/Contents/Developer/Platforms/{platform}.platform/Developer/SDKs/{platform}{version}.sdk".format(platform
 = sdk_platform, version = sdk_version)
+
+    return struct(
+        platform_root = platform_root,
+        sdk_root = sdk_root,
+    )
 
-    # This is useful for compiling .h headers as C++ code.
-    if _is_cpp_target(srcs):
+def _cc_compile_commands(ctx, target, feature_configuration, cc_toolchain):
+    compiler = str(
+        cc_common.get_tool_for_action(
+            feature_configuration = feature_configuration,
+            action_name = C_COMPILE_ACTION_NAME,
+        ),
+    )
+    compile_flags = _get_compile_flags(target)
+
+    srcs = _sources(ctx, target)
+    if ctx.rule.kind == "cc_proto_library":
+        srcs += [f for f in target.files.to_list() if f.extension in ["h", 
"cc"]]
+
+    # We currently recognize an entire target as C++ or C. This can probably be
+    # made better for targets that have a mix of C and C++ files.
+    is_cpp_target = _is_cpp_target(srcs)
+
+    compiler_options = None
+    if is_cpp_target:
         compile_variables = cc_common.create_compile_variables(
             feature_configuration = feature_configuration,
             cc_toolchain = cc_toolchain,
@@ -127,7 +159,7 @@
             action_name = CPP_COMPILE_ACTION_NAME,
             variables = compile_variables,
         )
-        force_language_mode_option = " -x c++"
+        compile_flags.append("-x c++")  # Force language mode for header files.
     else:
         compile_variables = cc_common.create_compile_variables(
             feature_configuration = feature_configuration,
@@ -140,34 +172,43 @@
             variables = compile_variables,
         )
 
+    compile_flags.extend(ctx.rule.attr.copts if "copts" in dir(ctx.rule.attr) 
else [])
+
+    cmdline_list = [compiler]
+    cmdline_list.extend(compiler_options)
+    cmdline_list.extend(compile_flags)
+    cmdline = " ".join(cmdline_list)
+
+    compile_commands = []
+    for src in srcs:
+        compile_commands.append(struct(
+            cmdline = cmdline + " -c " + src.path,
+            src = src,
+        ))
+    return compile_commands
+
+def _objc_compile_commands(ctx, target, feature_configuration, cc_toolchain):
     compiler = str(
         cc_common.get_tool_for_action(
             feature_configuration = feature_configuration,
-            action_name = C_COMPILE_ACTION_NAME,
+            action_name = OBJC_COMPILE_ACTION_NAME,
         ),
     )
+    compile_flags = _get_compile_flags(target)
 
-    compile_flags = (compiler_options +
-                     get_compile_flags(target) +
-                     (ctx.rule.attr.copts if "copts" in dir(ctx.rule.attr) 
else []))
+    srcs = _sources(ctx, target)
 
-    return struct(
-        compile_variables = compile_variables,
-        compiler_options = compiler_options,
-        compiler = compiler,
-        compile_flags = compile_flags,
-        force_language_mode_option = force_language_mode_option,
-    )
+    non_arc_srcs = []
+    if "non_arc_srcs" in dir(ctx.rule.attr):
+        non_arc_srcs += [f for src in ctx.rule.attr.non_arc_srcs for f in 
src.files.to_list()]
+    srcs.extend(non_arc_srcs)
+
+    # We currently recognize an entire target as objective-c++ or not. This can
+    # probably be made better for targets that have a mix of files.
+    is_objcpp_target = _is_objcpp_target(srcs)
 
-def _objc_compiler_info(ctx, target, srcs, feature_configuration, 
cc_toolchain):
-    compile_variables = None
     compiler_options = None
-    compiler = None
-    compile_flags = None
-    force_language_mode_option = ""
-
-    # This is useful for compiling .h headers as C++ code.
-    if _is_objcpp_target(srcs):
+    if is_objcpp_target:
         compile_variables = cc_common.create_compile_variables(
             feature_configuration = feature_configuration,
             cc_toolchain = cc_toolchain,
@@ -179,7 +220,7 @@
             action_name = OBJCPP_COMPILE_ACTION_NAME,
             variables = compile_variables,
         )
-        force_language_mode_option = " -x objective-c++"
+        compile_flags.append("-x objective-c++")  # Force language mode for 
header files.
     else:
         compile_variables = cc_common.create_compile_variables(
             feature_configuration = feature_configuration,
@@ -191,62 +232,71 @@
             action_name = OBJC_COMPILE_ACTION_NAME,
             variables = compile_variables,
         )
-        force_language_mode_option = " -x objective-c"
+        compile_flags.append("-x objective-c")  # Force language mode for 
header files.
 
-    compiler = str(
-        cc_common.get_tool_for_action(
-            feature_configuration = feature_configuration,
-            action_name = OBJC_COMPILE_ACTION_NAME,
-        ),
+    frameworks = (
+        ["-F {}/..".format(val) for val in 
target.objc.static_framework_paths.to_list()] +
+        ["-F {}/..".format(val) for val in 
target.objc.dynamic_framework_paths.to_list()]
     )
+    compile_flags.extend(frameworks)
 
-    defines = ["-D{}".format(val) for val in target.objc.define]
-    includes = ["-I{}".format(val) for val in target.objc.include]
-    system_includes = ["-isystem {}".format(val) for val in 
target.objc.include_system]
-    iquotes = ["-iquote {}".format(val) for val in target.objc.iquote]
-    frameworks = (["-F {}/..".format(val) for val in 
target.objc.framework_dir] +
-                  ["-F {}/..".format(val) for val in 
target.objc.dynamic_framework_dir] +
-                  ["-F {}/..".format(val) for val in 
target.objc.framework_search_path_only])
-
-    xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
-
-    sdk_version = 
xcode_config.sdk_version_for_platform(ctx.fragments.apple.single_arch_platform)
-    apple_env = apple_common.target_apple_env(xcode_config, 
ctx.fragments.apple.single_arch_platform)
-    sdk_platform = apple_env["APPLE_SDK_PLATFORM"]
+    compile_flags.extend(ctx.rule.attr.copts if "copts" in dir(ctx.rule.attr) 
else [])
 
-    # FIXME is there any way of getting the SDKROOT value here? The only thing 
that seems to know about it is
-    # XcodeLocalEnvProvider, but I can't seem to find a way to access that
-    platform_root = 
"/Applications/Xcode.app/Contents/Developer/Platforms/{platform}.platform".format(platform
 = sdk_platform)
-    sdk_root = 
"/Applications/Xcode.app/Contents/Developer/Platforms/{platform}.platform/Developer/SDKs/{platform}{version}.sdk".format(platform
 = sdk_platform, version = sdk_version)
+    xcode_paths = _xcode_paths(ctx)
+    system_flags = [
+        "-isysroot {}".format(xcode_paths.sdk_root),
+        "-F {}/System/Library/Frameworks".format(xcode_paths.sdk_root),
+        "-F {}/Developer/Library/Frameworks".format(xcode_paths.platform_root),
+    ]
 
-    compile_flags = (compiler_options +
-                     ["-isysroot {}".format(sdk_root)] +
-                     ["-F {}/System/Library/Frameworks".format(sdk_root)] +
-                     ["-F 
{}/Developer/Library/Frameworks".format(platform_root)] +
-                     # FIXME this needs to be done per-file to be fully correct
-                     ["-fobjc-arc"] +
-                     defines +
-                     includes +
-                     iquotes +
-                     system_includes +
-                     frameworks +
-                     (ctx.rule.attr.copts if "copts" in dir(ctx.rule.attr) 
else []))
+    cmdline_list = [compiler]
+    cmdline_list.extend(compiler_options)
+    cmdline_list.extend(system_flags)
+    cmdline_list.extend(compile_flags)
+    cmdline = " ".join(cmdline_list)
 
-    return struct(
-        compile_variables = compile_variables,
-        compiler_options = compiler_options,
-        compiler = compiler,
-        compile_flags = compile_flags,
-        force_language_mode_option = force_language_mode_option,
-    )
+    compile_commands = []
+    for src in srcs:
+        arc_flag = "" if src in non_arc_srcs else " -fobjc-arc"
+        compile_commands.append(struct(
+            cmdline = cmdline + arc_flag + " -c " + src.path,
+            src = src,
+        ))
+    return compile_commands
 
 def _compilation_database_aspect_impl(target, ctx):
     # Write the compile commands for this target to a file, and return
     # the commands for the transitive closure.
 
+    # Collect any aspects from all transitive dependencies.
+    # Note that this should also apply to filegroup type targets which may have
+    # cc_binary targets in their srcs attribute.
+    deps = []
+    if hasattr(ctx.rule.attr, "srcs"):
+        deps.extend(ctx.rule.attr.srcs)
+    if hasattr(ctx.rule.attr, "deps"):
+        deps.extend(ctx.rule.attr.deps)
+
+    transitive_compilation_db = []
+    all_compdb_files = []
+    all_header_files = []
+    for dep in deps:
+        if CompilationAspect not in dep:
+            continue
+        transitive_compilation_db.append(dep[CompilationAspect].compilation_db)
+        all_compdb_files.append(dep[OutputGroupInfo].compdb_files)
+        all_header_files.append(dep[OutputGroupInfo].header_files)
+
     # We support only these rule kinds.
     if ctx.rule.kind not in _all_rules:
-        return []
+        return [
+            CompilationAspect(compilation_db = depset(transitive = 
transitive_compilation_db)),
+            OutputGroupInfo(
+                compdb_files = depset(transitive = all_compdb_files),
+                header_files = depset(transitive = all_header_files),
+                direct_src_files = [],
+            ),
+        ]
 
     compilation_db = []
 
@@ -258,60 +308,49 @@
         unsupported_features = ctx.disabled_features,
     )
 
-    srcs = _sources(target, ctx)
-    if not srcs:
-        return []
-
-    compiler_info = None
-
     if ctx.rule.kind in _cc_rules:
-        compiler_info = _cc_compiler_info(ctx, target, srcs, 
feature_configuration, cc_toolchain)
+        compile_commands = _cc_compile_commands(ctx, target, 
feature_configuration, cc_toolchain)
+    elif ctx.rule.kind in _objc_rules:
+        compile_commands = _objc_compile_commands(ctx, target, 
feature_configuration, cc_toolchain)
     else:
-        compiler_info = _objc_compiler_info(ctx, target, srcs, 
feature_configuration, cc_toolchain)
-
-    compile_flags = compiler_info.compile_flags
-    compile_flags += [
-        # Use -I to indicate that we want to keep the normal position in the 
system include chain.
-        # See 
https://github.com/grailbio/bazel-compilation-database/issues/36#issuecomment-531971361.
-        "-I " + str(d)
-        for d in cc_toolchain.built_in_include_directories
-    ]
-    compile_command = compiler_info.compiler + " " + " ".join(compile_flags) + 
compiler_info.force_language_mode_option
-
-    for src in srcs:
-        command_for_file = compile_command + " -c " + src.path
+        fail("unsupported rule: " + ctx.rule.kind)
 
+    srcs = []
+    for compile_command in compile_commands:
         exec_root_marker = "__EXEC_ROOT__"
         compilation_db.append(
-            struct(command = command_for_file, directory = exec_root_marker, 
file = src.path),
+            struct(command = compile_command.cmdline, directory = 
exec_root_marker, file = compile_command.src.path),
         )
+        srcs.append(compile_command.src)
 
     # Write the commands for this target.
     compdb_file = ctx.actions.declare_file(ctx.label.name + 
".compile_commands.json")
     ctx.actions.write(
-        content = _compilation_db_json(compilation_db),
+        content = json.encode(compilation_db),
         output = compdb_file,
     )
 
-    # Collect all transitive dependencies.
-    transitive_compilation_db = []
-    all_compdb_files = []
-    for dep in ctx.rule.attr.deps:
-        if CompilationAspect not in dep:
-            continue
-        transitive_compilation_db.append(dep[CompilationAspect].compilation_db)
-        all_compdb_files.append(dep[OutputGroupInfo].compdb_files)
-
     compilation_db = depset(compilation_db, transitive = 
transitive_compilation_db)
     all_compdb_files = depset([compdb_file], transitive = all_compdb_files)
+    all_header_files.append(target[CcInfo].compilation_context.headers)
 
     return [
         CompilationAspect(compilation_db = compilation_db),
-        OutputGroupInfo(compdb_files = all_compdb_files),
+        OutputGroupInfo(
+            compdb_files = all_compdb_files,
+            header_files = depset(transitive = all_header_files),
+            # Provide direct src files of this target for people who want to
+            # run clang-tidy or similar tools with the compilation database
+            # on the source files of this target.
+            # See 
https://github.com/grailbio/bazel-compilation-database/pull/53.
+            direct_src_files = srcs,
+        ),
     ]
 
 compilation_database_aspect = aspect(
-    attr_aspects = ["deps"],
+    # Also include srcs in the attribute aspects so people can use filegroup 
targets.
+    # See https://github.com/grailbio/bazel-compilation-database/issues/84.
+    attr_aspects = ["srcs", "deps"],
     attrs = {
         "_cc_toolchain": attr.label(
             default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
@@ -319,59 +358,8 @@
         "_xcode_config": attr.label(default = 
Label("@bazel_tools//tools/osx:current_xcode_config")),
     },
     fragments = ["cpp", "objc", "apple"],
-    required_aspect_providers = [CompilationAspect],
+    provides = [CompilationAspect],
     toolchains = ["@bazel_tools//tools/cpp:toolchain_type"],
     implementation = _compilation_database_aspect_impl,
-)
-
-def _compilation_database_impl(ctx):
-    # Generates a single compile_commands.json file with the
-    # transitive depset of specified targets.
-
-    if ctx.attr.disable:
-        ctx.actions.write(output = ctx.outputs.filename, content = "[]\n")
-        return
-
-    # We make this rule a no-op on Windows because it is not supported.
-    # We use the exposed host path separator as a hack to detect Windows.
-    # The ideal solution here would be to use toolchains.
-    # https://github.com/bazelbuild/bazel/issues/2045
-    if ctx.configuration.host_path_separator != ":":
-        print("Windows is not supported in compilation_database rule")
-        ctx.actions.write(output = ctx.outputs.filename, content = "[]\n")
-        return
-
-    compilation_db = []
-    for target in ctx.attr.targets:
-        compilation_db.append(target[CompilationAspect].compilation_db)
-
-    compilation_db = depset(transitive = compilation_db)
-
-    content = "[\n" + _compilation_db_json(compilation_db.to_list()) + "\n]\n"
-    content = content.replace("__EXEC_ROOT__", ctx.attr.exec_root)
-    content = content.replace("-isysroot __BAZEL_XCODE_SDKROOT__", "")
-    ctx.actions.write(output = ctx.outputs.filename, content = content)
-
-compilation_database = rule(
-    attrs = {
-        "targets": attr.label_list(
-            aspects = [compilation_database_aspect],
-            doc = "List of all cc targets which should be included.",
-        ),
-        "exec_root": attr.string(
-            default = "__EXEC_ROOT__",
-            doc = "Execution root of Bazel as returned by 'bazel info 
execution_root'.",
-        ),
-        "disable": attr.bool(
-            default = False,
-            doc = ("Makes this operation a no-op; useful in combination with a 
'select' " +
-                   "for platforms where the internals of this rule are not 
properly " +
-                   "supported. For known unsupported platforms (e.g. Windows), 
the " +
-                   "rule is always a no-op."),
-        ),
-    },
-    outputs = {
-        "filename": "compile_commands.json",
-    },
-    implementation = _compilation_database_impl,
+    apply_to_generating_rules = True,
 )
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/bazel-compilation-database-0.4.1/defs.bzl 
new/bazel-compilation-database-0.5.2/defs.bzl
--- old/bazel-compilation-database-0.4.1/defs.bzl       1970-01-01 
01:00:00.000000000 +0100
+++ new/bazel-compilation-database-0.5.2/defs.bzl       2021-09-10 
05:15:42.000000000 +0200
@@ -0,0 +1,76 @@
+# Copyright 2021 GRAIL, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load("@com_grail_bazel_compdb//:aspects.bzl", "CompilationAspect", 
"compilation_database_aspect")
+
+def _compilation_database_impl(ctx):
+    # Generates a single compile_commands.json file with the
+    # transitive depset of specified targets.
+
+    if ctx.attr.disable:
+        ctx.actions.write(output = ctx.outputs.filename, content = "[]\n")
+        return
+
+    compilation_db = []
+    all_headers = []
+    for target in ctx.attr.targets:
+        compilation_db.append(target[CompilationAspect].compilation_db)
+        all_headers.append(target[OutputGroupInfo].header_files)
+
+    compilation_db = depset(transitive = compilation_db)
+    all_headers = depset(transitive = all_headers)
+
+    exec_root = ctx.attr.output_base + "/execroot/" + ctx.workspace_name
+
+    content = json.encode(compilation_db.to_list())
+    content = content.replace("__EXEC_ROOT__", exec_root)
+    content = content.replace("-isysroot __BAZEL_XCODE_SDKROOT__", "")
+    ctx.actions.write(output = ctx.outputs.filename, content = content)
+
+    return [
+        OutputGroupInfo(
+            default = all_headers,
+        ),
+    ]
+
+_compilation_database = rule(
+    attrs = {
+        "targets": attr.label_list(
+            aspects = [compilation_database_aspect],
+            doc = "List of all cc targets which should be included.",
+        ),
+        "output_base": attr.string(
+            default = "__OUTPUT_BASE__",
+            doc = ("Output base of Bazel as returned by 'bazel info 
output_base'. " +
+                   "The exec_root is constructed from the output_base as " +
+                   "output_base + '/execroot/' + workspace_name. "),
+        ),
+        "disable": attr.bool(
+            default = False,
+            doc = ("Makes this operation a no-op; useful in combination with a 
'select' " +
+                   "for platforms where the internals of this rule are not 
properly " +
+                   "supported."),
+        ),
+        "filename": attr.output(
+            doc = "Name of the generated compilation database.",
+        ),
+    },
+    implementation = _compilation_database_impl,
+)
+
+def compilation_database(**kwargs):
+    _compilation_database(
+        filename = kwargs.pop("filename", "compile_commands.json"),
+        **kwargs
+    )
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/bazel-compilation-database-0.4.1/deps.bzl 
new/bazel-compilation-database-0.5.2/deps.bzl
--- old/bazel-compilation-database-0.4.1/deps.bzl       1970-01-01 
01:00:00.000000000 +0100
+++ new/bazel-compilation-database-0.5.2/deps.bzl       2021-09-10 
05:15:42.000000000 +0200
@@ -0,0 +1,18 @@
+# Copyright 2021 GRAIL, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load("@com_grail_bazel_compdb//:tools.bzl", "setup_tools")
+
+def bazel_compdb_deps():
+    setup_tools()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/bazel-compilation-database-0.4.1/generate.py 
new/bazel-compilation-database-0.5.2/generate.py
--- old/bazel-compilation-database-0.4.1/generate.py    1970-01-01 
01:00:00.000000000 +0100
+++ new/bazel-compilation-database-0.5.2/generate.py    2021-09-10 
05:15:42.000000000 +0200
@@ -0,0 +1,145 @@
+#!/usr/bin/python3
+
+# Copyright 2021 GRAIL, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Generates a compile_commands.json file at $(bazel info workspace) for
+libclang based tools.
+
+This is inspired from
+https://github.com/google/kythe/blob/master/tools/cpp/generate_compilation_database.sh
+"""
+
+import argparse
+import json
+import os
+import pathlib
+import subprocess
+import tempfile
+
+
+_BAZEL = os.getenv("BAZEL_COMPDB_BAZEL_PATH") or "bazel"
+
+_OUTPUT_GROUPS = "compdb_files,header_files"
+
+
+def bazel_info():
+    """Returns a dict containing key values from bazel info."""
+
+    bazel_info_dict = dict()
+    try:
+        out = subprocess.check_output([_BAZEL, 
'info']).decode('utf-8').strip().split('\n')
+    except subprocess.CalledProcessError as err:
+        # This exit code is returned when this command is run outside of a 
bazel workspace.
+        if err.returncode == 2:
+            sys.exit(0)
+        sys.exit(err.returncode)
+
+    for line in out:
+        key_val = line.strip().partition(": ")
+        bazel_info_dict[key_val[0]] = key_val[2]
+
+    return bazel_info_dict
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser()
+    parser.add_argument("-s", "--source_dir", default=False, 
action="store_true",
+                        help="use the original source directory instead of 
bazel execroot")
+    parser.add_argument("-q", "--query_expr", default="//...",
+                        help="bazel query expr to find targets")
+    parser.add_argument('bazel_args', nargs=argparse.REMAINDER,
+                        help="")
+    args = parser.parse_args()
+
+    user_build_args = []
+    if len(args.bazel_args) > 0:
+        if args.bazel_args[0] != '--':
+            msg = "additional bazel args '%s' must start with --" % " 
".join(args.bazel_args)
+            raise Exception(msg)
+        user_build_args = args.bazel_args[1:] # Ignore the first '--'
+
+    bazel_info_dict = bazel_info()
+    bazel_exec_root = bazel_info_dict['execution_root']
+    bazel_workspace = bazel_info_dict['workspace']
+    compdb_file = os.path.join(bazel_workspace, "compile_commands.json")
+
+    os.chdir(bazel_workspace)
+
+    aspects_dir = os.path.dirname(os.path.realpath(__file__))
+
+    query = ('kind("cc_(library|binary|test|inc_library|proto_library)", 
{query_expr}) ' +
+             'union kind("objc_(library|binary|test)", {query_expr})').format(
+                 query_expr=args.query_expr)
+    query_cmd = [_BAZEL, 'query']
+    query_cmd.extend(['--noshow_progress', '--noshow_loading_progress', 
'--output=label'])
+    query_cmd.append(query)
+
+    targets_file = tempfile.NamedTemporaryFile()
+    subprocess.check_call(query_cmd, stdout=targets_file)
+
+    # Clean any previously generated files.
+    for db in pathlib.Path(bazel_exec_root).glob('**/*.compile_commands.json'):
+        os.remove(db)
+
+    build_args = [
+        '--override_repository=bazel_compdb={}'.format(aspects_dir),
+        '--aspects=@bazel_compdb//:aspects.bzl%compilation_database_aspect',
+        '--noshow_progress',
+        '--noshow_loading_progress',
+        '--output_groups={}'.format(_OUTPUT_GROUPS),
+        '--target_pattern_file={}'.format(targets_file.name),
+    ]
+    build_cmd = [_BAZEL, 'build']
+    build_cmd.extend(build_args)
+    build_cmd.extend(user_build_args)
+    subprocess.check_call(build_cmd, stdout=subprocess.DEVNULL)
+
+    targets_file.close()
+
+    db_entries = []
+    for db in pathlib.Path(bazel_exec_root).glob('**/*.compile_commands.json'):
+        with open(db, 'r') as f:
+            db_entries.extend(json.load(f))
+
+    def replace_execroot_marker(db_entry):
+        if 'directory' in db_entry and db_entry['directory'] == 
'__EXEC_ROOT__':
+            db_entry['directory'] = bazel_workspace if args.source_dir else 
bazel_exec_root
+        if 'command' in db_entry:
+            db_entry['command'] = (
+                db_entry['command'].replace('-isysroot 
__BAZEL_XCODE_SDKROOT__', ''))
+        return db_entry
+    db_entries = list(map(replace_execroot_marker, db_entries))
+
+    with open(compdb_file, 'w') as outdb:
+        json.dump(db_entries, outdb, indent=2)
+
+    if args.source_dir:
+        link_name = os.path.join(bazel_workspace, 'external')
+        try:
+            os.remove(link_name)
+        except FileNotFoundError:
+            pass
+        # This is for libclang to help find source files from external 
repositories.
+        os.symlink(os.path.join(bazel_exec_root, 'external'),
+                   link_name,
+                   target_is_directory=True)
+    else:
+        # This is for YCM to help find the DB when following generated files.
+        # The file may be deleted by bazel on the next build.
+        link_name = os.path.join(bazel_exec_root, "compile_commands.json")
+        try:
+            os.remove(link_name)
+        except FileNotFoundError:
+            pass
+        os.symlink(compdb_file, link_name)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/bazel-compilation-database-0.4.1/generate.sh 
new/bazel-compilation-database-0.5.2/generate.sh
--- old/bazel-compilation-database-0.4.1/generate.sh    2019-10-15 
15:53:51.000000000 +0200
+++ new/bazel-compilation-database-0.5.2/generate.sh    2021-09-10 
05:15:42.000000000 +0200
@@ -14,52 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Generates a compile_commands.json file at $(bazel info workspace) for
-# libclang based tools.
-
-# This is inspired from
-# 
https://github.com/google/kythe/blob/master/tools/cpp/generate_compilation_database.sh
-
-set -e
-
-readonly ASPECTS_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
-readonly OUTPUT_GROUPS="compdb_files"
-
-readonly WORKSPACE="$(bazel info workspace)"
-readonly EXEC_ROOT="$(bazel info execution_root)"
-readonly COMPDB_FILE="${WORKSPACE}/compile_commands.json"
-
-readonly QUERY_CMD=(
-  bazel query
-    --noshow_progress
-    --noshow_loading_progress
-    'kind("cc_(library|binary|test|inc_library|proto_library)", //...) union 
kind("objc_(library|binary|test)", //...)'
-)
-
-# Clean any previously generated files.
-if [[ -e "${EXEC_ROOT}" ]]; then
-  find "${EXEC_ROOT}" -name '*.compile_commands.json' -delete
-fi
-
-# shellcheck disable=SC2046
-bazel build \
-  "--override_repository=bazel_compdb=${ASPECTS_DIR}" \
-  "--aspects=@bazel_compdb//:aspects.bzl%compilation_database_aspect" \
-  "--noshow_progress" \
-  "--noshow_loading_progress" \
-  "--output_groups=${OUTPUT_GROUPS}" \
-  "$@" \
-  $("${QUERY_CMD[@]}") > /dev/null
-
-echo "[" > "${COMPDB_FILE}"
-find "${EXEC_ROOT}" -name '*.compile_commands.json' -exec bash -c 'cat "$1" && 
echo ,' _ {} \; \
-  >> "${COMPDB_FILE}"
-sed -i.bak -e '/^,$/d' -e '$s/,$//' "${COMPDB_FILE}"  # Hygiene to make valid 
json
-sed -i.bak -e "s|__EXEC_ROOT__|${EXEC_ROOT}|" "${COMPDB_FILE}"  # Replace 
exec_root marker
-sed -i.bak -e "s|-isysroot __BAZEL_XCODE_SDKROOT__||" "${COMPDB_FILE}"  # 
Replace -isysroot __BAZEL_XCODE_SDKROOT__ marker
-rm "${COMPDB_FILE}.bak"
-echo "]" >> "${COMPDB_FILE}"
-
-# This is for YCM to help find the DB when following generated files.
-# The file may be deleted by bazel on the next build.
-ln -f -s "${WORKSPACE}/${COMPDB_FILE}" "${EXEC_ROOT}/"
+>&2 echo "==="
+>&2 echo "WARNING: generate.sh is now deprecated; please use generate.py 
directly instead"
+>&2 echo "==="
+exec "$(dirname "${BASH_SOURCE[0]}")/generate.py" "$@"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/bazel-compilation-database-0.4.1/tests/.gitignore 
new/bazel-compilation-database-0.5.2/tests/.gitignore
--- old/bazel-compilation-database-0.4.1/tests/.gitignore       1970-01-01 
01:00:00.000000000 +0100
+++ new/bazel-compilation-database-0.5.2/tests/.gitignore       2021-09-10 
05:15:42.000000000 +0200
@@ -0,0 +1,2 @@
+/bazel-*
+/compile_commands.json
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/bazel-compilation-database-0.4.1/tests/BUILD 
new/bazel-compilation-database-0.5.2/tests/BUILD
--- old/bazel-compilation-database-0.4.1/tests/BUILD    2019-10-15 
15:53:51.000000000 +0200
+++ new/bazel-compilation-database-0.5.2/tests/BUILD    2021-09-10 
05:15:42.000000000 +0200
@@ -12,16 +12,24 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
+
 cc_library(
-    name = "A",
+    name = "a",
     srcs = ["a.cc"],
     hdrs = ["a.h"],
+    include_prefix = "dir_a",  # To test that we can work with 
_virtual_includes dirs.
 )
 
 cc_library(
-    name = "B",
+    name = "b",
     srcs = ["b.cc"],
-    deps = [":A"],
+    deps = [":a"],
+)
+
+cc_library(
+    name = "b_forward",
+    deps = [":b"],
 )
 
 cc_binary(
@@ -29,10 +37,17 @@
     srcs = ["stdlib.cc"],
 )
 
-load("@compdb//:aspects.bzl", "compilation_database")
+# For testing https://github.com/grailbio/bazel-compilation-database/issues/84.
+filegroup(
+    name = "b_filegrp",
+    srcs = ["b"],
+)
+
+load("@com_grail_bazel_compdb//:defs.bzl", "compilation_database")
+load("@com_grail_bazel_output_base_util//:defs.bzl", "OUTPUT_BASE")
 
 compilation_database(
     name = "compdb",
-    exec_root = "bazel-tests",
-    targets = ["B"],
+    output_base = OUTPUT_BASE,
+    targets = ["b_filegrp"],
 )
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/bazel-compilation-database-0.4.1/tests/WORKSPACE 
new/bazel-compilation-database-0.5.2/tests/WORKSPACE
--- old/bazel-compilation-database-0.4.1/tests/WORKSPACE        2019-10-15 
15:53:51.000000000 +0200
+++ new/bazel-compilation-database-0.5.2/tests/WORKSPACE        2021-09-10 
05:15:42.000000000 +0200
@@ -12,11 +12,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-workspace(name = "tests")
+workspace(name = "com_grail_bazel_compdb_tests")
 
-new_local_repository(
-    name = "compdb",
-    build_file_content = "",
+local_repository(
+    name = "com_grail_bazel_compdb",
     path = "..",
 )
 
+load("@com_grail_bazel_compdb//:deps.bzl", "bazel_compdb_deps")
+
+bazel_compdb_deps()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/bazel-compilation-database-0.4.1/tests/b.cc 
new/bazel-compilation-database-0.5.2/tests/b.cc
--- old/bazel-compilation-database-0.4.1/tests/b.cc     2019-10-15 
15:53:51.000000000 +0200
+++ new/bazel-compilation-database-0.5.2/tests/b.cc     2021-09-10 
05:15:42.000000000 +0200
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#include "a.h"
+#include "dir_a/a.h"
 
 class B : A {
  public:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/bazel-compilation-database-0.4.1/tests/bazel.sh 
new/bazel-compilation-database-0.5.2/tests/bazel.sh
--- old/bazel-compilation-database-0.4.1/tests/bazel.sh 2019-10-15 
15:53:51.000000000 +0200
+++ new/bazel-compilation-database-0.5.2/tests/bazel.sh 2021-09-10 
05:15:42.000000000 +0200
@@ -1,15 +1,19 @@
-os="$(uname -s | tr "[:upper:]" "[:lower:]")"
-readonly os
-
 # Use bazelisk to catch migration problems.
-# Value of BAZELISK_GITHUB_TOKEN is set as a secret on Travis.
-readonly 
url="https://github.com/bazelbuild/bazelisk/releases/download/v1.0/bazelisk-${os}-amd64";
-readonly bin_dir="${TMPDIR:-/tmp}/bin"
-readonly bazel="${bin_dir}/bazel"
-
-mkdir -p "${bin_dir}"
-export PATH="${bin_dir}:${PATH}"
-curl -L -sSf -o "${bazel}" "${url}"
-chmod a+x "${bazel}"
+if command -v bazelisk >/dev/null; then
+  # bazelisk is installed on Github Actions VMs.
+  bazel="$(command -v bazelisk)"
+  readonly bazel
+else
+  os="$(uname -s | tr "[:upper:]" "[:lower:]")"
+  readonly os
 
+  # Fetch bazelisk on user machines.
+  readonly 
url="https://github.com/bazelbuild/bazelisk/releases/download/v1.5.0/bazelisk-${os}-amd64";
+  readonly bin_dir="${TMPDIR:-/tmp}/bin"
+  readonly bazel="${bin_dir}/bazel"
 
+  mkdir -p "${bin_dir}"
+  export PATH="${bin_dir}:${PATH}"
+  curl -L -sSf -o "${bazel}" "${url}"
+  chmod a+x "${bazel}"
+fi
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/bazel-compilation-database-0.4.1/tests/expected_file.json 
new/bazel-compilation-database-0.5.2/tests/expected_file.json
--- old/bazel-compilation-database-0.4.1/tests/expected_file.json       
2019-10-15 15:53:51.000000000 +0200
+++ new/bazel-compilation-database-0.5.2/tests/expected_file.json       
1970-01-01 01:00:00.000000000 +0100
@@ -1,5 +0,0 @@
-[
-{"command":"/usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall 
-Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer 
-std=c++0x -fno-canonical-system-headers -Wno-builtin-macro-redefined 
-D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\" 
-iquote . -iquote bazel-out/k8-fastbuild/bin -I 
/usr/lib/gcc/x86_64-linux-gnu/5/include -I /usr/local/include -I 
/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed -I /usr/include/x86_64-linux-gnu 
-I /usr/include -I /usr/include/c++/5 -I /usr/include/x86_64-linux-gnu/c++/5 -I 
/usr/include/c++/5/backward -x c++ -c 
a.cc","directory":"bazel-tests","file":"a.cc"},
- {"command":"/usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall 
-Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer 
-std=c++0x -fno-canonical-system-headers -Wno-builtin-macro-redefined 
-D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\" 
-iquote . -iquote bazel-out/k8-fastbuild/bin -I 
/usr/lib/gcc/x86_64-linux-gnu/5/include -I /usr/local/include -I 
/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed -I /usr/include/x86_64-linux-gnu 
-I /usr/include -I /usr/include/c++/5 -I /usr/include/x86_64-linux-gnu/c++/5 -I 
/usr/include/c++/5/backward -x c++ -c 
a.h","directory":"bazel-tests","file":"a.h"},
- {"command":"/usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall 
-Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer 
-std=c++0x -fno-canonical-system-headers -Wno-builtin-macro-redefined 
-D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\" 
-iquote . -iquote bazel-out/k8-fastbuild/bin -I 
/usr/lib/gcc/x86_64-linux-gnu/5/include -I /usr/local/include -I 
/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed -I /usr/include/x86_64-linux-gnu 
-I /usr/include -I /usr/include/c++/5 -I /usr/include/x86_64-linux-gnu/c++/5 -I 
/usr/include/c++/5/backward -x c++ -c 
b.cc","directory":"bazel-tests","file":"b.cc"}
-]
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/bazel-compilation-database-0.4.1/tests/expected_macos.json 
new/bazel-compilation-database-0.5.2/tests/expected_macos.json
--- old/bazel-compilation-database-0.4.1/tests/expected_macos.json      
1970-01-01 01:00:00.000000000 +0100
+++ new/bazel-compilation-database-0.5.2/tests/expected_macos.json      
2021-09-10 05:15:42.000000000 +0200
@@ -0,0 +1,22 @@
+[
+  {
+    "command": "external/local_config_cc/cc_wrapper.sh -U_FORTIFY_SOURCE 
-fstack-protector -Wall -Wthread-safety -Wself-assign -fcolor-diagnostics 
-fno-omit-frame-pointer -std=c++0x -no-canonical-prefixes 
-Wno-builtin-macro-redefined -D__DATE__=\"redacted\" 
-D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\" -I 
bazel-out/darwin-fastbuild/bin/_virtual_includes/a -iquote . -iquote 
bazel-out/darwin-fastbuild/bin -x c++ -c b.cc",
+    "directory": "EXECROOT",
+    "file": "b.cc"
+  },
+  {
+    "command": "external/local_config_cc/cc_wrapper.sh -U_FORTIFY_SOURCE 
-fstack-protector -Wall -Wthread-safety -Wself-assign -fcolor-diagnostics 
-fno-omit-frame-pointer -std=c++0x -no-canonical-prefixes 
-Wno-builtin-macro-redefined -D__DATE__=\"redacted\" 
-D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\" -iquote . -iquote 
bazel-out/darwin-fastbuild/bin -iquote external/bazel_tools -iquote 
bazel-out/darwin-fastbuild/bin/external/bazel_tools -x c++ -c stdlib.cc",
+    "directory": "EXECROOT",
+    "file": "stdlib.cc"
+  },
+  {
+    "command": "external/local_config_cc/cc_wrapper.sh -U_FORTIFY_SOURCE 
-fstack-protector -Wall -Wthread-safety -Wself-assign -fcolor-diagnostics 
-fno-omit-frame-pointer -std=c++0x -no-canonical-prefixes 
-Wno-builtin-macro-redefined -D__DATE__=\"redacted\" 
-D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\" -I 
bazel-out/darwin-fastbuild/bin/_virtual_includes/a -iquote . -iquote 
bazel-out/darwin-fastbuild/bin -x c++ -c a.cc",
+    "directory": "EXECROOT",
+    "file": "a.cc"
+  },
+  {
+    "command": "external/local_config_cc/cc_wrapper.sh -U_FORTIFY_SOURCE 
-fstack-protector -Wall -Wthread-safety -Wself-assign -fcolor-diagnostics 
-fno-omit-frame-pointer -std=c++0x -no-canonical-prefixes 
-Wno-builtin-macro-redefined -D__DATE__=\"redacted\" 
-D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\" -I 
bazel-out/darwin-fastbuild/bin/_virtual_includes/a -iquote . -iquote 
bazel-out/darwin-fastbuild/bin -x c++ -c a.h",
+    "directory": "EXECROOT",
+    "file": "a.h"
+  }
+]
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/bazel-compilation-database-0.4.1/tests/expected_ubuntu.json 
new/bazel-compilation-database-0.5.2/tests/expected_ubuntu.json
--- old/bazel-compilation-database-0.4.1/tests/expected_ubuntu.json     
1970-01-01 01:00:00.000000000 +0100
+++ new/bazel-compilation-database-0.5.2/tests/expected_ubuntu.json     
2021-09-10 05:15:42.000000000 +0200
@@ -0,0 +1,22 @@
+[
+  {
+    "command": "/usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall 
-Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer 
-std=c++0x -fno-canonical-system-headers -Wno-builtin-macro-redefined 
-D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\" -I 
bazel-out/k8-fastbuild/bin/_virtual_includes/a -iquote . -iquote 
bazel-out/k8-fastbuild/bin -x c++ -c a.cc",
+    "directory": "EXECROOT",
+    "file": "a.cc"
+  },
+  {
+    "command": "/usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall 
-Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer 
-std=c++0x -fno-canonical-system-headers -Wno-builtin-macro-redefined 
-D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\" -I 
bazel-out/k8-fastbuild/bin/_virtual_includes/a -iquote . -iquote 
bazel-out/k8-fastbuild/bin -x c++ -c a.h",
+    "directory": "EXECROOT",
+    "file": "a.h"
+  },
+  {
+    "command": "/usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall 
-Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer 
-std=c++0x -fno-canonical-system-headers -Wno-builtin-macro-redefined 
-D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\" -I 
bazel-out/k8-fastbuild/bin/_virtual_includes/a -iquote . -iquote 
bazel-out/k8-fastbuild/bin -x c++ -c b.cc",
+    "directory": "EXECROOT",
+    "file": "b.cc"
+  },
+  {
+    "command": "/usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall 
-Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer 
-std=c++0x -fno-canonical-system-headers -Wno-builtin-macro-redefined 
-D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\" 
-iquote . -iquote bazel-out/k8-fastbuild/bin -iquote external/bazel_tools 
-iquote bazel-out/k8-fastbuild/bin/external/bazel_tools -x c++ -c stdlib.cc",
+    "directory": "EXECROOT",
+    "file": "stdlib.cc"
+  }
+]
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/bazel-compilation-database-0.4.1/tests/expected_ycm_macos.json 
new/bazel-compilation-database-0.5.2/tests/expected_ycm_macos.json
--- old/bazel-compilation-database-0.4.1/tests/expected_ycm_macos.json  
1970-01-01 01:00:00.000000000 +0100
+++ new/bazel-compilation-database-0.5.2/tests/expected_ycm_macos.json  
2021-09-10 05:15:42.000000000 +0200
@@ -0,0 +1 @@
+{'flags': ['-U_FORTIFY_SOURCE', '-fstack-protector', '-Wall', 
'-Wthread-safety', '-Wself-assign', '-fcolor-diagnostics', 
'-fno-omit-frame-pointer', '-std=c++0x', '-no-canonical-prefixes', 
'-Wno-builtin-macro-redefined', '-D__DATE__=redacted', 
'-D__TIMESTAMP__=redacted', '-D__TIME__=redacted', '-I', 
'bazel-out/darwin-fastbuild/bin/_virtual_includes/a', '-iquote', '.', 
'-iquote', 'bazel-out/darwin-fastbuild/bin', '-x', 'c++', '-c', 'a.cc', 
'-iquote', 'PWD'], 'include_paths_relative_to_dir': 'EXECROOT'}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/bazel-compilation-database-0.4.1/tests/expected_ycm_output.json 
new/bazel-compilation-database-0.5.2/tests/expected_ycm_output.json
--- old/bazel-compilation-database-0.4.1/tests/expected_ycm_output.json 
2019-10-15 15:53:51.000000000 +0200
+++ new/bazel-compilation-database-0.5.2/tests/expected_ycm_output.json 
1970-01-01 01:00:00.000000000 +0100
@@ -1 +0,0 @@
-{'include_paths_relative_to_dir': u'EXECROOT', 'flags': ['-U_FORTIFY_SOURCE', 
'-fstack-protector', '-Wall', '-Wunused-but-set-parameter', 
'-Wno-free-nonheap-object', '-fno-omit-frame-pointer', '-std=c++0x', 
'-fno-canonical-system-headers', '-Wno-builtin-macro-redefined', 
'-D__DATE__=redacted', '-D__TIMESTAMP__=redacted', '-D__TIME__=redacted', 
'-iquote', '.', '-iquote', 'bazel-out/k8-fastbuild/bin', '-I', 
'/usr/lib/gcc/x86_64-linux-gnu/5/include', '-I', '/usr/local/include', '-I', 
'/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed', '-I', 
'/usr/include/x86_64-linux-gnu', '-I', '/usr/include', '-I', 
'/usr/include/c++/5', '-I', '/usr/include/x86_64-linux-gnu/c++/5', '-I', 
'/usr/include/c++/5/backward', '-x', 'c++', '-c', 'a.cc', '-iquote', u'PWD']}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/bazel-compilation-database-0.4.1/tests/expected_ycm_ubuntu.json 
new/bazel-compilation-database-0.5.2/tests/expected_ycm_ubuntu.json
--- old/bazel-compilation-database-0.4.1/tests/expected_ycm_ubuntu.json 
1970-01-01 01:00:00.000000000 +0100
+++ new/bazel-compilation-database-0.5.2/tests/expected_ycm_ubuntu.json 
2021-09-10 05:15:42.000000000 +0200
@@ -0,0 +1 @@
+{'flags': ['-U_FORTIFY_SOURCE', '-fstack-protector', '-Wall', 
'-Wunused-but-set-parameter', '-Wno-free-nonheap-object', 
'-fno-omit-frame-pointer', '-std=c++0x', '-fno-canonical-system-headers', 
'-Wno-builtin-macro-redefined', '-D__DATE__=redacted', 
'-D__TIMESTAMP__=redacted', '-D__TIME__=redacted', '-I', 
'bazel-out/k8-fastbuild/bin/_virtual_includes/a', '-iquote', '.', '-iquote', 
'bazel-out/k8-fastbuild/bin', '-x', 'c++', '-c', 'a.cc', '-iquote', 'PWD'], 
'include_paths_relative_to_dir': 'EXECROOT'}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/bazel-compilation-database-0.4.1/tests/run_tests.sh 
new/bazel-compilation-database-0.5.2/tests/run_tests.sh
--- old/bazel-compilation-database-0.4.1/tests/run_tests.sh     2019-10-15 
15:53:51.000000000 +0200
+++ new/bazel-compilation-database-0.5.2/tests/run_tests.sh     2021-09-10 
05:15:42.000000000 +0200
@@ -1,15 +1,66 @@
 #!/bin/bash
 
-set -exuo pipefail
+set -euo pipefail
 
 cd "$(dirname "${BASH_SOURCE[0]}")"
 
 source "bazel.sh"
 
+# The expected files are generated by:
+# ../generate.py
+# jq 'map(.directory = "EXECROOT")' compile_commands.json > ${expected}
+if [[ "$(uname -s)" == "Darwin" ]]; then
+  expected="expected_macos.json"
+  expected_ycm="expected_ycm_macos.json"
+else
+  expected="expected_ubuntu.json"
+  expected_ycm="expected_ycm_ubuntu.json"
+fi
+
+execroot="$(bazel info execution_root)"
+readonly execroot
+
+check_compdb() {
+  local want="$expected"
+  local got="$1"
+  local full_compdb="$2"
+
+  jq_got_cmd='sort_by(.file)'
+  jq_want_cmd="${jq_got_cmd}"
+  jq_want_cmd+=" | map(.directory = \"${execroot}\")"
+  if ! "${full_compdb}"; then
+    # Remove the source file for the target not included in our //:compdb 
target.
+    jq_want_cmd+=" | map(. | select(.file != \"stdlib.cc\"))"
+  fi
+
+  diff --unified=100 <(jq "${jq_want_cmd}" "${want}") <(jq "${jq_got_cmd}" 
"${got}")
+  test -f bazel-bin/_virtual_includes/a/dir_a/a.h
+}
+
+# Let's keep the C++ toolchain simple by not using Xcode specific bazel 
wrappers.
+# 
https://cs.opensource.google/bazel/bazel/+/master:tools/cpp/cc_configure.bzl;l=122;drc=644b7d41748e09eff9e47cbab2be2263bb71f29a
+# Also, tell xcode-select to always use CommandLineTools, whether or not Xcode 
is installed.
+export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
+export DEVELOPER_DIR=/Library/Developer/CommandLineTools
+"${bazel}" sync --configure # Reset the cached toolchain.
+
+echo
+echo "Checking specific targets mode"
+"${bazel}" clean
 "${bazel}" build :compdb
+check_compdb bazel-bin/compile_commands.json false
+echo "SUCCESS!"
 
-diff expected_file.json bazel-bin/compile_commands.json
-
-diff \
-  <(sed -e "s@EXECROOT@$(bazel info execution_root)@" -e "s@PWD@${PWD}@" 
expected_ycm_output.json) \
-  <(python ../.ycm_extra_conf.py a.cc)
+echo
+echo "Checking full repo mode"
+"${bazel}" clean
+../generate.py
+check_compdb compile_commands.json true
+echo "SUCCESS!"
+
+echo
+echo "Checking YCM plugin"
+diff --unified=100 \
+  <(sed -e "s@EXECROOT@${execroot}@" -e "s@PWD@${PWD}@" "${expected_ycm}") \
+  <(python3 ../.ycm_extra_conf.py a.cc)
+echo "SUCCESS!"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/bazel-compilation-database-0.4.1/tools.bzl 
new/bazel-compilation-database-0.5.2/tools.bzl
--- old/bazel-compilation-database-0.4.1/tools.bzl      1970-01-01 
01:00:00.000000000 +0100
+++ new/bazel-compilation-database-0.5.2/tools.bzl      2021-09-10 
05:15:42.000000000 +0200
@@ -0,0 +1,35 @@
+# Copyright 2021 GRAIL, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+def _bazel_output_base_util_impl(rctx):
+    res = rctx.execute(["pwd"])
+    if res.return_code != 0:
+        fail("getting output base failed (%d): %s" % (res.return_code, 
res.stderr))
+
+    # Strip last two path components.
+    path_components = res.stdout.rstrip("\n").split("/")[:-2]
+    output_base = "/".join(path_components)
+
+    rctx.file("BUILD.bazel", "")
+    rctx.file("defs.bzl", "OUTPUT_BASE = '%s'" % output_base)
+
+bazel_output_base_util = repository_rule(
+    implementation = _bazel_output_base_util_impl,
+    local = True,
+)
+
+def setup_tools():
+    bazel_output_base_util(
+        name = "com_grail_bazel_output_base_util",
+    )

Reply via email to