Skip to content

Commit 8640b74

Browse files
committed
Merge tag 'kbuild-fixes-6.19-1' of git://git.kernel.org/pub/scm/linux/kernel/git/kbuild/linux
Pull Kbuild fixes from Nicolas Schier: - Revert commit "scripts/clang-tools: Handle included .c files in gen_compile_commands" which is reported to cause false entries for some files. - Fix compilation of dtb specified on command-line without make rule - mcb: Add missing modpost build support * tag 'kbuild-fixes-6.19-1' of git://git.kernel.org/pub/scm/linux/kernel/git/kbuild/linux: mcb: Add missing modpost build support kbuild: fix compilation of dtb specified on command-line without make rule Revert "scripts/clang-tools: Handle included .c files in gen_compile_commands"
2 parents 0b34fd0 + 1f4ea48 commit 8640b74

4 files changed

Lines changed: 33 additions & 140 deletions

File tree

scripts/Makefile.build

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -527,18 +527,6 @@ ifneq ($(userprogs),)
527527
include $(srctree)/scripts/Makefile.userprogs
528528
endif
529529

530-
ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %.dtb.o %.dtbo.o,$(targets)),)
531-
include $(srctree)/scripts/Makefile.dtbs
532-
endif
533-
534-
# Build
535-
# ---------------------------------------------------------------------------
536-
537-
$(obj)/: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \
538-
$(if $(KBUILD_MODULES), $(targets-for-modules)) \
539-
$(subdir-ym) $(always-y)
540-
@:
541-
542530
# Single targets
543531
# ---------------------------------------------------------------------------
544532

@@ -568,6 +556,20 @@ FORCE:
568556
targets += $(filter-out $(single-subdir-goals), $(MAKECMDGOALS))
569557
targets := $(filter-out $(PHONY), $(targets))
570558

559+
# Now that targets is fully known, include dtb rules if needed
560+
ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %.dtb.o %.dtbo.o,$(targets)),)
561+
include $(srctree)/scripts/Makefile.dtbs
562+
endif
563+
564+
# Build
565+
# Needs to be after the include of Makefile.dtbs, which updates always-y
566+
# ---------------------------------------------------------------------------
567+
568+
$(obj)/: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \
569+
$(if $(KBUILD_MODULES), $(targets-for-modules)) \
570+
$(subdir-ym) $(always-y)
571+
@:
572+
571573
# Read all saved command lines and dependencies for the $(targets) we
572574
# may be building above, using $(if_changed{,_dep}). As an
573575
# optimization, we don't need to read them if the target does not

scripts/clang-tools/gen_compile_commands.py

Lines changed: 7 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
_FILENAME_PATTERN = r'^\..*\.cmd$'
2222
_LINE_PATTERN = r'^(saved)?cmd_[^ ]*\.o := (?P<command_prefix>.* )(?P<file_path>[^ ]*\.[cS]) *(;|$)'
2323
_VALID_LOG_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
24-
25-
# Pre-compiled regexes for better performance
26-
_INCLUDE_PATTERN = re.compile(r'^\s*#\s*include\s*[<"]([^>"]*)[>"]')
27-
_C_INCLUDE_PATTERN = re.compile(r'^\s*#\s*include\s*"([^"]*\.c)"\s*$')
28-
_FILENAME_MATCHER = re.compile(_FILENAME_PATTERN)
29-
3024
# The tools/ directory adopts a different build system, and produces .cmd
3125
# files in a different format. Do not support it.
3226
_EXCLUDE_DIRS = ['.git', 'Documentation', 'include', 'tools']
@@ -88,6 +82,7 @@ def cmdfiles_in_dir(directory):
8882
The path to a .cmd file.
8983
"""
9084

85+
filename_matcher = re.compile(_FILENAME_PATTERN)
9186
exclude_dirs = [ os.path.join(directory, d) for d in _EXCLUDE_DIRS ]
9287

9388
for dirpath, dirnames, filenames in os.walk(directory, topdown=True):
@@ -97,7 +92,7 @@ def cmdfiles_in_dir(directory):
9792
continue
9893

9994
for filename in filenames:
100-
if _FILENAME_MATCHER.match(filename):
95+
if filename_matcher.match(filename):
10196
yield os.path.join(dirpath, filename)
10297

10398

@@ -154,87 +149,8 @@ def cmdfiles_for_modorder(modorder):
154149
yield to_cmdfile(mod_line.rstrip())
155150

156151

157-
def extract_includes_from_file(source_file, root_directory):
158-
"""Extract #include statements from a C file.
159-
160-
Args:
161-
source_file: Path to the source .c file to analyze
162-
root_directory: Root directory for resolving relative paths
163-
164-
Returns:
165-
List of header files that should be included (without quotes/brackets)
166-
"""
167-
includes = []
168-
if not os.path.exists(source_file):
169-
return includes
170-
171-
try:
172-
with open(source_file, 'r') as f:
173-
for line in f:
174-
line = line.strip()
175-
# Look for #include statements.
176-
# Match both #include "header.h" and #include <header.h>.
177-
match = _INCLUDE_PATTERN.match(line)
178-
if match:
179-
header = match.group(1)
180-
# Skip including other .c files to avoid circular includes.
181-
if not header.endswith('.c'):
182-
# For relative includes (quoted), resolve path relative to source file.
183-
if '"' in line:
184-
src_dir = os.path.dirname(source_file)
185-
header_path = os.path.join(src_dir, header)
186-
if os.path.exists(header_path):
187-
rel_header = os.path.relpath(header_path, root_directory)
188-
includes.append(rel_header)
189-
else:
190-
includes.append(header)
191-
else:
192-
# System include like <linux/sched.h>.
193-
includes.append(header)
194-
except IOError:
195-
pass
196-
197-
return includes
198-
199-
200-
def find_included_c_files(source_file, root_directory):
201-
"""Find .c files that are included by the given source file.
202-
203-
Args:
204-
source_file: Path to the source .c file
205-
root_directory: Root directory for resolving relative paths
206-
207-
Yields:
208-
Full paths to included .c files
209-
"""
210-
if not os.path.exists(source_file):
211-
return
212-
213-
try:
214-
with open(source_file, 'r') as f:
215-
for line in f:
216-
line = line.strip()
217-
# Look for #include "*.c" patterns.
218-
match = _C_INCLUDE_PATTERN.match(line)
219-
if match:
220-
included_file = match.group(1)
221-
# Handle relative paths.
222-
if not os.path.isabs(included_file):
223-
src_dir = os.path.dirname(source_file)
224-
included_file = os.path.join(src_dir, included_file)
225-
226-
# Normalize the path.
227-
included_file = os.path.normpath(included_file)
228-
229-
# Check if the file exists.
230-
if os.path.exists(included_file):
231-
yield included_file
232-
except IOError:
233-
pass
234-
235-
236152
def process_line(root_directory, command_prefix, file_path):
237-
"""Extracts information from a .cmd line and creates entries from it.
153+
"""Extracts information from a .cmd line and creates an entry from it.
238154
239155
Args:
240156
root_directory: The directory that was searched for .cmd files. Usually
@@ -244,8 +160,7 @@ def process_line(root_directory, command_prefix, file_path):
244160
Usually relative to root_directory, but sometimes absolute.
245161
246162
Returns:
247-
A list of entries to append to compile_commands (may include multiple
248-
entries if the source file includes other .c files).
163+
An entry to append to compile_commands.
249164
250165
Raises:
251166
ValueError: Could not find the extracted file based on file_path and
@@ -261,47 +176,11 @@ def process_line(root_directory, command_prefix, file_path):
261176
abs_path = os.path.realpath(os.path.join(root_directory, file_path))
262177
if not os.path.exists(abs_path):
263178
raise ValueError('File %s not found' % abs_path)
264-
265-
entries = []
266-
267-
# Create entry for the main source file.
268-
main_entry = {
179+
return {
269180
'directory': root_directory,
270181
'file': abs_path,
271182
'command': prefix + file_path,
272183
}
273-
entries.append(main_entry)
274-
275-
# Find and create entries for included .c files.
276-
for included_c_file in find_included_c_files(abs_path, root_directory):
277-
# For included .c files, create a compilation command that:
278-
# 1. Uses the same compilation flags as the parent file
279-
# 2. But compiles the included file directly (not the parent)
280-
# 3. Includes necessary headers from the parent file for proper macro resolution
281-
282-
# Convert absolute path to relative for the command.
283-
rel_path = os.path.relpath(included_c_file, root_directory)
284-
285-
# Extract includes from the parent file to provide proper compilation context.
286-
extra_includes = ''
287-
try:
288-
parent_includes = extract_includes_from_file(abs_path, root_directory)
289-
if parent_includes:
290-
extra_includes = ' ' + ' '.join('-include ' + inc for inc in parent_includes)
291-
except IOError:
292-
pass
293-
294-
included_entry = {
295-
'directory': root_directory,
296-
'file': included_c_file,
297-
# Use the same compilation prefix but target the included file directly.
298-
# Add extra headers for proper macro resolution.
299-
'command': prefix + extra_includes + ' ' + rel_path,
300-
}
301-
entries.append(included_entry)
302-
logging.debug('Added entry for included file: %s', included_c_file)
303-
304-
return entries
305184

306185

307186
def main():
@@ -334,9 +213,9 @@ def main():
334213
result = line_matcher.match(f.readline())
335214
if result:
336215
try:
337-
entries = process_line(directory, result.group('command_prefix'),
216+
entry = process_line(directory, result.group('command_prefix'),
338217
result.group('file_path'))
339-
compile_commands.extend(entries)
218+
compile_commands.append(entry)
340219
except ValueError as err:
341220
logging.info('Could not add line from %s: %s',
342221
cmdfile, err)

scripts/mod/devicetable-offsets.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ int main(void)
199199
DEVID(cpu_feature);
200200
DEVID_FIELD(cpu_feature, feature);
201201

202+
DEVID(mcb_device_id);
203+
DEVID_FIELD(mcb_device_id, device);
204+
202205
DEVID(mei_cl_device_id);
203206
DEVID_FIELD(mei_cl_device_id, name);
204207
DEVID_FIELD(mei_cl_device_id, uuid);

scripts/mod/file2alias.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,14 @@ static void do_cpu_entry(struct module *mod, void *symval)
11101110
module_alias_printf(mod, false, "cpu:type:*:feature:*%04X*", feature);
11111111
}
11121112

1113+
/* Looks like: mcb:16zN */
1114+
static void do_mcb_entry(struct module *mod, void *symval)
1115+
{
1116+
DEF_FIELD(symval, mcb_device_id, device);
1117+
1118+
module_alias_printf(mod, false, "mcb:16z%03d", device);
1119+
}
1120+
11131121
/* Looks like: mei:S:uuid:N:* */
11141122
static void do_mei_entry(struct module *mod, void *symval)
11151123
{
@@ -1444,6 +1452,7 @@ static const struct devtable devtable[] = {
14441452
{"mipscdmm", SIZE_mips_cdmm_device_id, do_mips_cdmm_entry},
14451453
{"x86cpu", SIZE_x86_cpu_id, do_x86cpu_entry},
14461454
{"cpu", SIZE_cpu_feature, do_cpu_entry},
1455+
{"mcb", SIZE_mcb_device_id, do_mcb_entry},
14471456
{"mei", SIZE_mei_cl_device_id, do_mei_entry},
14481457
{"rapidio", SIZE_rio_device_id, do_rio_entry},
14491458
{"ulpi", SIZE_ulpi_device_id, do_ulpi_entry},

0 commit comments

Comments
 (0)