Skip to content

Commit 8791092

Browse files
committed
Refactor Setup.local define logic to avoid supplemental makefile
1 parent 735ded8 commit 8791092

File tree

4 files changed

+14
-47
lines changed

4 files changed

+14
-47
lines changed

cpython-unix/build-cpython.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ SETUPTOOLS_WHEEL="${ROOT}/setuptools-${SETUPTOOLS_VERSION}-py3-none-any.whl"
5454
cat Setup.local
5555
mv Setup.local Python-${PYTHON_VERSION}/Modules/Setup.local
5656

57-
cat Makefile.extra
58-
5957
pushd Python-${PYTHON_VERSION}
6058

6159
# configure doesn't support cross-compiling on Apple. Teach it.
@@ -649,9 +647,6 @@ fi
649647
CFLAGS=$CFLAGS CPPFLAGS=$CFLAGS CFLAGS_JIT=$CFLAGS_JIT LDFLAGS=$LDFLAGS \
650648
./configure ${CONFIGURE_FLAGS}
651649

652-
# Supplement produced Makefile with our modifications.
653-
cat ../Makefile.extra >> Makefile
654-
655650
make -j ${NUM_CPUS}
656651
make -j ${NUM_CPUS} sharedinstall DESTDIR=${ROOT}/out/python
657652
make -j ${NUM_CPUS} install DESTDIR=${ROOT}/out/python

cpython-unix/build.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,6 @@ def build_cpython(
728728

729729
enabled_extensions = setup["extensions"]
730730
setup_local_content = setup["setup_local"]
731-
extra_make_content = setup["make_data"]
732731

733732
with build_environment(client, image) as build_env:
734733
if settings.get("needs_toolchain"):
@@ -781,13 +780,6 @@ def build_cpython(
781780

782781
build_env.copy_file(fh.name, dest_name="Setup.local")
783782

784-
with tempfile.NamedTemporaryFile("wb") as fh:
785-
os.chmod(fh.name, 0o644)
786-
fh.write(extra_make_content)
787-
fh.flush()
788-
789-
build_env.copy_file(fh.name, dest_name="Makefile.extra")
790-
791783
env = {
792784
"PIP_VERSION": DOWNLOADS["pip"]["version"],
793785
"PYTHON_VERSION": python_version,

cpython-unix/extension-modules.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ _sqlite3:
546546
- define: SQLITE_OMIT_LOAD_EXTENSION=1
547547
targets:
548548
- .*-ios
549-
- define: "MODULE_NAME=\\\"sqlite3\\\""
549+
- define: "MODULE_NAME='\"sqlite3\"'"
550550
maximum-python-version: "3.9"
551551
links:
552552
- sqlite3

pythonbuild/cpython.py

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,6 @@ def derive_setup_local(
446446
# agrees fully with the distribution's knowledge of extensions. So we can
447447
# treat our metadata as canonical.
448448

449-
RE_DEFINE = re.compile(rb"-D[^=]+=[^\s]+")
450-
451449
# Translate our YAML metadata into Setup lines.
452450

453451
section_lines = {
@@ -456,12 +454,6 @@ def derive_setup_local(
456454
"static": [],
457455
}
458456

459-
# makesetup parses lines with = as extra config options. There appears
460-
# to be no easy way to define e.g. -Dfoo=bar in Setup.local. We hack
461-
# around this by producing a Makefile supplement that overrides the build
462-
# rules for certain targets to include these missing values.
463-
extra_cflags = {}
464-
465457
enabled_extensions = {}
466458

467459
for name, info in sorted(extension_modules.items()):
@@ -520,6 +512,10 @@ def derive_setup_local(
520512

521513
line = name
522514

515+
# Keep track of defines separately to work around makesetup's treatment of = signs
516+
defines = set()
517+
def_name = name.upper() + "DEFS"
518+
523519
for source in info.get("sources", []):
524520
line += " %s" % source
525521

@@ -553,7 +549,7 @@ def derive_setup_local(
553549
line += f" {source}"
554550

555551
for define in info.get("defines", []):
556-
line += f" -D{define}"
552+
defines.add(f"-D{define}")
557553

558554
for entry in info.get("defines-conditional", []):
559555
if targets := entry.get("targets", []):
@@ -569,7 +565,10 @@ def derive_setup_local(
569565
)
570566

571567
if target_match and (python_min_match and python_max_match):
572-
line += f" -D{entry['define']}"
568+
defines.add(f"-D{entry['define']}")
569+
570+
if defines:
571+
line += f" $({def_name})"
573572

574573
for path in info.get("includes", []):
575574
line += f" -I{path}"
@@ -638,23 +637,15 @@ def derive_setup_local(
638637
if not parsed:
639638
raise Exception("we should always parse a setup line we generated")
640639

641-
# makesetup parses lines with = as extra config options. There appears
642-
# to be no easy way to define e.g. -Dfoo=bar in Setup.local. We hack
643-
# around this by detecting the syntax we'd like to support and move the
644-
# variable defines to a Makefile supplement that overrides variables for
645-
# specific targets.
646-
for m in RE_DEFINE.finditer(parsed["line"]):
647-
for obj_path in sorted(parsed["posix_obj_paths"]):
648-
extra_cflags.setdefault(bytes(obj_path), []).append(m.group(0))
649-
650-
line = RE_DEFINE.sub(b"", line)
651-
652640
if b"=" in line:
653641
raise Exception(
654642
"= appears in EXTRA_MODULES line; will confuse "
655643
"makesetup: %s" % line.decode("utf-8")
656644
)
657645

646+
if defines:
647+
defines_str = " ".join(sorted(defines))
648+
section_lines[section].append(f"{def_name}={defines_str}".encode("ascii"))
658649
section_lines[section].append(line)
659650
enabled_extensions[name]["setup_line"] = line
660651

@@ -669,18 +660,7 @@ def derive_setup_local(
669660

670661
dest_lines.append(b"")
671662

672-
make_lines = []
673-
674-
for target in sorted(extra_cflags):
675-
make_lines.append(
676-
b"%s: PY_STDMODULE_CFLAGS += %s" % (target, b" ".join(extra_cflags[target]))
677-
)
678-
679-
return {
680-
"extensions": enabled_extensions,
681-
"setup_local": b"\n".join(dest_lines),
682-
"make_data": b"\n".join(make_lines),
683-
}
663+
return {"extensions": enabled_extensions, "setup_local": b"\n".join(dest_lines)}
684664

685665

686666
RE_INITTAB_ENTRY = re.compile(r'\{"([^"]+)", ([^\}]+)\},')

0 commit comments

Comments
 (0)