Skip to content

Incorrect CompilationDatabase output for project with variant dir and generated source files #4003

Closed

Description

@dphoyes

Describe the bug

For a project that specifies a variant_dir for building into and uses autogenerated .cpp files, the "file" field of the compilation database entry should point to <variant_dir>/generated.cpp, but instead points to the non-existing <local_source_dir>/generated.cpp.

Required information

Link to SCons Users thread discussing your issue.

https://discord.com/channels/571796279483564041/571796280146133047/879703913224343552

Version of SCons

SCons: v4.2.0.fcdadeef19fe5fead09fa7544a27502be65312be, Sat, 31 Jul 2021 18:12:46 -0700, by bdbaddog on ProDog2020

Version of Python

Python 3.6.1

Which python distribution if applicable (python.org, cygwin, anaconda, macports, brew,etc)

python.org

How you installed SCons

Poetry

What Platform are you on? (Linux/Windows and which version)

Ubuntu 20.04

How to reproduce your issue? Please include a small self contained reproducer. Likely a SConstruct should do for most issues.

SConstruct

SConscript('src/SConscript', variant_dir='variant')

src/SConscript

env = Environment()
env.Tool('compilation_db')

def build_function(target, source, env):
  with open(target[0].abspath, "w") as f:
    f.write(r"int main() { return 42; }")

bld = Builder(action=build_function)
env.Append(BUILDERS={"Foo": bld})

src = env.Foo(target="main.cpp", source=[])
env.Program("program", src)

env.CompilationDatabase()

How you invoke scons (The command line you're using "scons --flags some_arguments")

scons
cat variant/compile_commands.json

Expected output

[
    {
        "command": "g++ -o variant/main.o -c variant/main.cpp",
        "directory": "/home/dphoyes/devel/example-project",
        "file": "variant/main.cpp",
        "output": "variant/main.o"
    }
]

Actual output

[
    {
        "command": "g++ -o variant/main.o -c variant/main.cpp",
        "directory": "/home/dphoyes/devel/example-project",
        "file": "src/main.cpp",
        "output": "variant/main.o"
    }
]

Activity

  1. added
    Tools
    on Aug 25, 2021
  2. added this to the 4.3 milestone on Aug 29, 2021
  3. added
    clang
    on Sep 8, 2021
  4. added and removed
    clang
    on May 19, 2022
  5. added 5 commits that reference this issue on May 21, 2025
    a12ab12
    3b442fc
    8fffb74
    dd16593
    ac8f313
  6. added a commit that references this issue on May 28, 2025
  7. bdbaddog commented on Jun 1, 2025

    @bdbaddog
    Contributor

    Fixed by #4722

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Toolscompliation_dbvariantdir

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions