Skip to content

Commit 5a2f357

Browse files
committed
feat: support source files with duplicate basename
This change removes the duplicate basename checks for macOS and MSVS. The macOS one is no longer necessary and the solution generator for MSVS is updated to support duplicate names by reproducing the source directory structure in the intermediate directory. Closes: nodejs#60 BREAKING CHANGE: The `--no-duplicate-basename-check` option was removed.
1 parent 4815435 commit 5a2f357

File tree

4 files changed

+9
-136
lines changed

4 files changed

+9
-136
lines changed

pylib/gyp/__init__.py

-17
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def Load(
6868
params=None,
6969
check=False,
7070
circular_check=True,
71-
duplicate_basename_check=True,
7271
):
7372
"""
7473
Loads one or more specified build files.
@@ -156,7 +155,6 @@ def Load(
156155
generator_input_info,
157156
check,
158157
circular_check,
159-
duplicate_basename_check,
160158
params["parallel"],
161159
params["root_targets"],
162160
)
@@ -431,20 +429,6 @@ def gyp_main(args):
431429
regenerate=False,
432430
help="don't check for circular relationships between files",
433431
)
434-
# --no-duplicate-basename-check disables the check for duplicate basenames
435-
# in a static_library/shared_library project. Visual C++ 2008 generator
436-
# doesn't support this configuration. Libtool on Mac also generates warnings
437-
# when duplicate basenames are passed into Make generator on Mac.
438-
# TODO(yukawa): Remove this option when these legacy generators are
439-
# deprecated.
440-
parser.add_argument(
441-
"--no-duplicate-basename-check",
442-
dest="duplicate_basename_check",
443-
action="store_false",
444-
default=True,
445-
regenerate=False,
446-
help="don't check for duplicate basenames",
447-
)
448432
parser.add_argument(
449433
"--no-parallel",
450434
action="store_true",
@@ -651,7 +635,6 @@ def gyp_main(args):
651635
params,
652636
options.check,
653637
options.circular_check,
654-
options.duplicate_basename_check,
655638
)
656639

657640
# TODO(mark): Pass |data| for now because the generator needs a list of

pylib/gyp/generator/make.py

-41
Original file line numberDiff line numberDiff line change
@@ -671,43 +671,6 @@ def SourceifyAndQuoteSpaces(path):
671671
return QuoteSpaces(Sourceify(path))
672672

673673

674-
# TODO: Avoid code duplication with _ValidateSourcesForMSVSProject in msvs.py.
675-
def _ValidateSourcesForOSX(spec, all_sources):
676-
"""Makes sure if duplicate basenames are not specified in the source list.
677-
678-
Arguments:
679-
spec: The target dictionary containing the properties of the target.
680-
"""
681-
if spec.get("type", None) != "static_library":
682-
return
683-
684-
basenames = {}
685-
for source in all_sources:
686-
name, ext = os.path.splitext(source)
687-
is_compiled_file = ext in [".c", ".cc", ".cpp", ".cxx", ".m", ".mm", ".s", ".S"]
688-
if not is_compiled_file:
689-
continue
690-
basename = os.path.basename(name) # Don't include extension.
691-
basenames.setdefault(basename, []).append(source)
692-
693-
error = ""
694-
for basename, files in basenames.items():
695-
if len(files) > 1:
696-
error += " %s: %s\n" % (basename, " ".join(files))
697-
698-
if error:
699-
print(
700-
(
701-
"static library %s has several files with the same basename:\n"
702-
% spec["target_name"]
703-
)
704-
+ error
705-
+ "libtool on OS X will generate"
706-
+ " warnings for them."
707-
)
708-
raise GypError("Duplicate basenames in sources section, see list above")
709-
710-
711674
# Map from qualified target to path to output.
712675
target_outputs = {}
713676
# Map from qualified target to any linkable output. A subset
@@ -866,10 +829,6 @@ def Write(
866829
# Sources.
867830
all_sources = spec.get("sources", []) + extra_sources
868831
if all_sources:
869-
if self.flavor == "mac":
870-
# libtool on OS X generates warnings for duplicate basenames in the same
871-
# target.
872-
_ValidateSourcesForOSX(spec, all_sources)
873832
self.WriteSources(
874833
configs,
875834
deps,

pylib/gyp/generator/msvs.py

+9-44
Original file line numberDiff line numberDiff line change
@@ -1030,45 +1030,6 @@ def _GenerateProject(project, options, version, generator_flags, spec):
10301030
return _GenerateMSVSProject(project, options, version, generator_flags)
10311031

10321032

1033-
# TODO: Avoid code duplication with _ValidateSourcesForOSX in make.py.
1034-
def _ValidateSourcesForMSVSProject(spec, version):
1035-
"""Makes sure if duplicate basenames are not specified in the source list.
1036-
1037-
Arguments:
1038-
spec: The target dictionary containing the properties of the target.
1039-
version: The VisualStudioVersion object.
1040-
"""
1041-
# This validation should not be applied to MSVC2010 and later.
1042-
assert not version.UsesVcxproj()
1043-
1044-
# TODO: Check if MSVC allows this for loadable_module targets.
1045-
if spec.get("type", None) not in ("static_library", "shared_library"):
1046-
return
1047-
sources = spec.get("sources", [])
1048-
basenames = {}
1049-
for source in sources:
1050-
name, ext = os.path.splitext(source)
1051-
is_compiled_file = ext in [".c", ".cc", ".cpp", ".cxx", ".m", ".mm", ".s", ".S"]
1052-
if not is_compiled_file:
1053-
continue
1054-
basename = os.path.basename(name) # Don't include extension.
1055-
basenames.setdefault(basename, []).append(source)
1056-
1057-
error = ""
1058-
for basename, files in basenames.items():
1059-
if len(files) > 1:
1060-
error += " %s: %s\n" % (basename, " ".join(files))
1061-
1062-
if error:
1063-
print(
1064-
"static library %s has several files with the same basename:\n"
1065-
% spec["target_name"]
1066-
+ error
1067-
+ "MSVC08 cannot handle that."
1068-
)
1069-
raise GypError("Duplicate basenames in sources section, see list above")
1070-
1071-
10721033
def _GenerateMSVSProject(project, options, version, generator_flags):
10731034
"""Generates a .vcproj file. It may create .rules and .user files too.
10741035
@@ -1095,11 +1056,6 @@ def _GenerateMSVSProject(project, options, version, generator_flags):
10951056
for config_name, config in spec["configurations"].items():
10961057
_AddConfigurationToMSVSProject(p, spec, config_type, config_name, config)
10971058

1098-
# MSVC08 and prior version cannot handle duplicate basenames in the same
1099-
# target.
1100-
# TODO: Take excluded sources into consideration if possible.
1101-
_ValidateSourcesForMSVSProject(spec, version)
1102-
11031059
# Prepare list of sources and excluded sources.
11041060
gyp_file = os.path.split(project.build_file)[1]
11051061
sources, excluded_sources = _PrepareListOfSources(spec, generator_flags, gyp_file)
@@ -3659,6 +3615,15 @@ def _AddSources2(
36593615
extension_to_rule_name,
36603616
_GetUniquePlatforms(spec),
36613617
)
3618+
if group == "compile":
3619+
# Always add an <ObjectFileName> value to support duplicate
3620+
# source file basenames.
3621+
file_name = source
3622+
if (file_name.startswith("..\\")):
3623+
file_name = re.sub(r"^(\.\.\\)+", "", file_name)
3624+
elif (file_name.startswith("$(")):
3625+
file_name = re.sub(r"^\$\([^)]+\)\\", "", file_name)
3626+
detail.append(["ObjectFileName", "$(IntDir)\\" + file_name])
36623627
grouped_sources[group].append([element, {"Include": source}] + detail)
36633628

36643629

pylib/gyp/input.py

-34
Original file line numberDiff line numberDiff line change
@@ -2750,36 +2750,6 @@ def ValidateTargetType(target, target_dict):
27502750
)
27512751

27522752

2753-
def ValidateSourcesInTarget(target, target_dict, build_file, duplicate_basename_check):
2754-
if not duplicate_basename_check:
2755-
return
2756-
if target_dict.get("type", None) != "static_library":
2757-
return
2758-
sources = target_dict.get("sources", [])
2759-
basenames = {}
2760-
for source in sources:
2761-
name, ext = os.path.splitext(source)
2762-
is_compiled_file = ext in [".c", ".cc", ".cpp", ".cxx", ".m", ".mm", ".s", ".S"]
2763-
if not is_compiled_file:
2764-
continue
2765-
basename = os.path.basename(name) # Don't include extension.
2766-
basenames.setdefault(basename, []).append(source)
2767-
2768-
error = ""
2769-
for basename, files in basenames.items():
2770-
if len(files) > 1:
2771-
error += " %s: %s\n" % (basename, " ".join(files))
2772-
2773-
if error:
2774-
print(
2775-
"static library %s has several files with the same basename:\n" % target
2776-
+ error
2777-
+ "libtool on Mac cannot handle that. Use "
2778-
"--no-duplicate-basename-check to disable this validation."
2779-
)
2780-
raise GypError("Duplicate basenames in sources section, see list above")
2781-
2782-
27832753
def ValidateRulesInTarget(target, target_dict, extra_sources_for_rules):
27842754
"""Ensures that the rules sections in target_dict are valid and consistent,
27852755
and determines which sources they apply to.
@@ -3021,7 +2991,6 @@ def Load(
30212991
generator_input_info,
30222992
check,
30232993
circular_check,
3024-
duplicate_basename_check,
30252994
parallel,
30262995
root_targets,
30272996
):
@@ -3167,9 +3136,6 @@ def Load(
31673136
target_dict = targets[target]
31683137
build_file = gyp.common.BuildFile(target)
31693138
ValidateTargetType(target, target_dict)
3170-
ValidateSourcesInTarget(
3171-
target, target_dict, build_file, duplicate_basename_check
3172-
)
31733139
ValidateRulesInTarget(target, target_dict, extra_sources_for_rules)
31743140
ValidateRunAsInTarget(target, target_dict, build_file)
31753141
ValidateActionsInTarget(target, target_dict, build_file)

0 commit comments

Comments
 (0)