Skip to content

Commit ac8f313

Browse files
fix issue #4003 to emit variant dir for built sources
1 parent f3071eb commit ac8f313

5 files changed

Lines changed: 35 additions & 4 deletions

File tree

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
6969
and the code adjusted. All internal usage, including tests,
7070
was dont boolean-style anyway ("if Virtualenv():").
7171

72+
From Edward Peek:
73+
- Fix the variant dir component being missing from generated source file
74+
paths with CompilationDatabase() builder (Fixes #4003).
75+
7276

7377
RELEASE 4.9.1 - Thu, 27 Mar 2025 11:40:20 -0700
7478

RELEASE.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ FIXES
4646
setting against both enable & disable strings. (Fixes #4702)
4747
- MSVS: Fix significant slowdown initializing MSVC tools when vcpkg has
4848
been installed on the system.
49+
- Fix the variant dir component being missing from generated source file
50+
paths with CompilationDatabase() builder (Fixes #4003).
4951

5052
IMPROVEMENTS
5153
------------

SCons/Tool/compilation_db.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,14 @@ def write_compilation_db(target, source, env) -> None:
156156
source_file = entry['file']
157157
output_file = entry['output']
158158

159+
if not source_file.is_derived():
160+
source_file = source_file.srcnode()
161+
159162
if use_abspath:
160-
source_file = source_file.srcnode().abspath
163+
source_file = source_file.abspath
161164
output_file = output_file.abspath
162165
else:
163-
source_file = source_file.srcnode().path
166+
source_file = source_file.path
164167
output_file = output_file.path
165168

166169
if use_path_filter and not fnmatch.fnmatch(output_file, use_path_filter):

test/CompilationDatabase/fixture/SConstruct_variant

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ env.Program('build/main', 'build/test_main.c')
4646
env.VariantDir('build2','src', duplicate=0)
4747
env.Program('build2/main', 'build2/test_main.c')
4848

49+
env.VariantDir('build3','src', duplicate=0)
50+
env.InstallAs('build3/test_main_copy.c', 'src/test_main.c')
51+
env.Program('build3/main', 'build3/test_main_copy.c')

test/CompilationDatabase/variant_dir.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,22 @@
7878
"directory": "%(workdir)s",
7979
"file": "%(src_file)s",
8080
"output": "%(output2_file)s"
81+
},
82+
{
83+
"command": "%(exe)s mygcc.py cc -o %(output3_file)s -c %(variant3_src_file)s",
84+
"directory": "%(workdir)s",
85+
"file": "%(variant3_src_file)s",
86+
"output": "%(output3_file)s"
8187
}
8288
]
8389
""" % {'exe': sys.executable,
8490
'workdir': test.workdir,
8591
'src_file': os.path.join('src', 'test_main.c'),
8692
'output_file': os.path.join('build', 'test_main.o'),
8793
'output2_file': os.path.join('build2', 'test_main.o'),
88-
'variant_src_file': os.path.join('build', 'test_main.c')
94+
'output3_file': os.path.join('build3', 'test_main_copy.o'),
95+
'variant_src_file': os.path.join('build', 'test_main.c'),
96+
'variant3_src_file': os.path.join('build3', 'test_main_copy.c')
8997
}
9098

9199
if sys.platform == 'win32':
@@ -108,6 +116,12 @@
108116
"directory": "%(workdir)s",
109117
"file": "%(abs_src_file)s",
110118
"output": "%(abs_output2_file)s"
119+
},
120+
{
121+
"command": "%(exe)s mygcc.py cc -o %(output3_file)s -c %(variant3_src_file)s",
122+
"directory": "%(workdir)s",
123+
"file": "%(abs_variant3_src_file)s",
124+
"output": "%(abs_output3_file)s"
111125
}
112126
]
113127
""" % {'exe': sys.executable,
@@ -116,9 +130,14 @@
116130
'abs_src_file': os.path.join(test.workdir, 'src', 'test_main.c'),
117131
'abs_output_file': os.path.join(test.workdir, 'build', 'test_main.o'),
118132
'abs_output2_file': os.path.join(test.workdir, 'build2', 'test_main.o'),
133+
'abs_output3_file': os.path.join(test.workdir, 'build3', 'test_main_copy.o'),
119134
'output_file': os.path.join('build', 'test_main.o'),
120135
'output2_file': os.path.join('build2', 'test_main.o'),
121-
'variant_src_file': os.path.join('build', 'test_main.c')}
136+
'output3_file': os.path.join('build3', 'test_main_copy.o'),
137+
'abs_variant3_src_file': os.path.join(test.workdir, 'build3', 'test_main_copy.c'),
138+
'variant_src_file': os.path.join('build', 'test_main.c'),
139+
'variant3_src_file': os.path.join('build3', 'test_main_copy.c')
140+
}
122141

123142
if sys.platform == 'win32':
124143
example_abs_file = example_abs_file.replace('\\', '\\\\')

0 commit comments

Comments
 (0)