Skip to content

Commit 3f6f2de

Browse files
committed
Revert "Bug 1967834 - moved process_gn_config call to generate_gn_config. r=ng" for causing bc and xpcshell failures.
This reverts commit fbd34bb1de2004c8c80a2973d148828efc3774b0. Revert "Bug 1967834 - run calls to generate_gn_config in parallel. r=ng DONTBUILD" This reverts commit 16cb199df30f675fc1c772e4f12b75d0fb03895e. Revert "Bug 1967834 - move writing individual moz.build file to separate function for clarity. r=ng DONTBUILD" This reverts commit f940c62b9a3cd42df337b9a61b030b14babb1569. UltraBlame original commit: c57c3fe02179b71e541c8cd280df74a0df3ac1c3
1 parent 3362e20 commit 3f6f2de

File tree

1 file changed

+136
-146
lines changed

1 file changed

+136
-146
lines changed

build/gn_processor.py

Lines changed: 136 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import sys
1010
import tempfile
1111
from collections import defaultdict, deque
12-
from concurrent.futures import ProcessPoolExecutor, as_completed
1312
from copy import deepcopy
1413
from pathlib import Path
1514
from shutil import which
@@ -515,114 +514,27 @@ def make_difference(reference, input_attrs):
515514
return common_attrs
516515

517516

518-
def write_mozbuild(topsrcdir, write_mozbuild_variables, relsrcdir, configs):
519-
target_srcdir = mozpath.join(topsrcdir, relsrcdir)
520-
mkdir(target_srcdir)
521-
522-
target_mozbuild = mozpath.join(target_srcdir, "moz.build")
523-
with open(target_mozbuild, "w") as fh:
524-
mb = MozbuildWriter(fh)
525-
mb.write(license_header)
526-
mb.write("\n")
527-
mb.write(generated_header)
528-
529-
try:
530-
if relsrcdir in write_mozbuild_variables["INCLUDE_TK_CFLAGS_DIRS"]:
531-
mb.write('if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk":\n')
532-
mb.write(' CXXFLAGS += CONFIG["MOZ_GTK3_CFLAGS"]\n')
533-
except KeyError:
534-
pass
535-
try:
536-
if relsrcdir in write_mozbuild_variables["INCLUDE_SYSTEM_GBM_HANDLING"]:
537-
mb.write('CXXFLAGS += CONFIG["MOZ_GBM_CFLAGS"]\n')
538-
mb.write('if not CONFIG["MOZ_SYSTEM_GBM"]:\n')
539-
mb.write(' LOCAL_INCLUDES += [ "/third_party/gbm/gbm/" ]\n')
540-
except KeyError:
541-
pass
542-
try:
543-
if relsrcdir in write_mozbuild_variables["INCLUDE_SYSTEM_LIBDRM_HANDLING"]:
544-
mb.write('CXXFLAGS += CONFIG["MOZ_LIBDRM_CFLAGS"]\n')
545-
mb.write('if not CONFIG["MOZ_SYSTEM_LIBDRM"]:\n')
546-
mb.write(' LOCAL_INCLUDES += [ "/third_party/drm/drm/",\n')
547-
mb.write(' "/third_party/drm/drm/include/",\n')
548-
mb.write(
549-
' "/third_party/drm/drm/include/libdrm" ]\n'
550-
)
551-
except KeyError:
552-
pass
553-
try:
554-
if (
555-
relsrcdir
556-
in write_mozbuild_variables["INCLUDE_SYSTEM_PIPEWIRE_HANDLING"]
557-
):
558-
mb.write('CXXFLAGS += CONFIG["MOZ_PIPEWIRE_CFLAGS"]\n')
559-
mb.write('if not CONFIG["MOZ_SYSTEM_PIPEWIRE"]:\n')
560-
mb.write(' LOCAL_INCLUDES += [ "/third_party/pipewire/" ]\n')
561-
except KeyError:
562-
pass
563-
try:
564-
if relsrcdir in write_mozbuild_variables["INCLUDE_SYSTEM_LIBVPX_HANDLING"]:
565-
mb.write('if not CONFIG["MOZ_SYSTEM_LIBVPX"]:\n')
566-
mb.write(' LOCAL_INCLUDES += [ "/media/libvpx/libvpx/" ]\n')
567-
mb.write(' CXXFLAGS += CONFIG["MOZ_LIBVPX_CFLAGS"]\n')
568-
except KeyError:
569-
pass
570-
try:
571-
if relsrcdir in write_mozbuild_variables["INCLUDE_SYSTEM_DAV1D_HANDLING"]:
572-
mb.write('if CONFIG["MOZ_SYSTEM_AV1"]:\n')
573-
mb.write(' CXXFLAGS += CONFIG["MOZ_SYSTEM_DAV1D_CFLAGS"]\n')
574-
mb.write(' CXXFLAGS += CONFIG["MOZ_SYSTEM_LIBAOM_CFLAGS"]\n')
575-
except KeyError:
576-
pass
577-
578-
all_args = [args for args, _ in configs]
579-
580-
581-
582-
583-
584-
for attrs in (
585-
(),
586-
("MOZ_DEBUG",),
587-
("OS_TARGET",),
588-
("TARGET_CPU",),
589-
("MOZ_DEBUG", "OS_TARGET"),
590-
("OS_TARGET", "MOZ_X11"),
591-
("OS_TARGET", "TARGET_CPU"),
592-
("OS_TARGET", "TARGET_CPU", "MOZ_X11"),
593-
("OS_TARGET", "TARGET_CPU", "MOZ_DEBUG"),
594-
("OS_TARGET", "TARGET_CPU", "MOZ_DEBUG", "MOZ_X11"),
595-
):
596-
conditions = set()
597-
for args in all_args:
598-
cond = tuple((k, args.get(k) or "") for k in attrs)
599-
conditions.add(cond)
600-
601-
for cond in sorted(conditions):
602-
common_attrs = find_common_attrs(
603-
[
604-
attrs
605-
for args, attrs in configs
606-
if all((args.get(k) or "") == v for k, v in cond)
607-
]
608-
)
609-
if any(common_attrs.values()):
610-
if cond:
611-
mb.write_condition(dict(cond))
612-
mb.write_attrs(common_attrs)
613-
if cond:
614-
mb.terminate_condition()
615-
616-
mb.finalize()
617-
return target_mozbuild
618-
619-
620-
def write_mozbuild_files(
517+
def write_mozbuild(
621518
topsrcdir,
622519
srcdir,
623-
all_mozbuild_results,
520+
non_unified_sources,
521+
gn_configs,
522+
mozilla_flags,
624523
write_mozbuild_variables,
625524
):
525+
all_mozbuild_results = []
526+
527+
for gn_config in gn_configs:
528+
mozbuild_attrs = process_gn_config(
529+
gn_config,
530+
topsrcdir,
531+
srcdir,
532+
non_unified_sources,
533+
gn_config["sandbox_vars"],
534+
mozilla_flags,
535+
)
536+
all_mozbuild_results.append(mozbuild_attrs)
537+
626538

627539

628540
configs_by_dir = defaultdict(list)
@@ -633,11 +545,117 @@ def write_mozbuild_files(
633545
configs_by_dir[d].append((mozbuild_args, build_data))
634546

635547
mozbuilds = set()
636-
637548
for relsrcdir, configs in sorted(configs_by_dir.items()):
638-
mozbuilds.add(
639-
write_mozbuild(topsrcdir, write_mozbuild_variables, relsrcdir, configs)
640-
)
549+
target_srcdir = mozpath.join(topsrcdir, relsrcdir)
550+
mkdir(target_srcdir)
551+
552+
target_mozbuild = mozpath.join(target_srcdir, "moz.build")
553+
mozbuilds.add(target_mozbuild)
554+
with open(target_mozbuild, "w") as fh:
555+
mb = MozbuildWriter(fh)
556+
mb.write(license_header)
557+
mb.write("\n")
558+
mb.write(generated_header)
559+
560+
try:
561+
if relsrcdir in write_mozbuild_variables["INCLUDE_TK_CFLAGS_DIRS"]:
562+
mb.write('if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk":\n')
563+
mb.write(' CXXFLAGS += CONFIG["MOZ_GTK3_CFLAGS"]\n')
564+
except KeyError:
565+
pass
566+
try:
567+
if relsrcdir in write_mozbuild_variables["INCLUDE_SYSTEM_GBM_HANDLING"]:
568+
mb.write('CXXFLAGS += CONFIG["MOZ_GBM_CFLAGS"]\n')
569+
mb.write('if not CONFIG["MOZ_SYSTEM_GBM"]:\n')
570+
mb.write(' LOCAL_INCLUDES += [ "/third_party/gbm/gbm/" ]\n')
571+
except KeyError:
572+
pass
573+
try:
574+
if (
575+
relsrcdir
576+
in write_mozbuild_variables["INCLUDE_SYSTEM_LIBDRM_HANDLING"]
577+
):
578+
mb.write('CXXFLAGS += CONFIG["MOZ_LIBDRM_CFLAGS"]\n')
579+
mb.write('if not CONFIG["MOZ_SYSTEM_LIBDRM"]:\n')
580+
mb.write(' LOCAL_INCLUDES += [ "/third_party/drm/drm/",\n')
581+
mb.write(
582+
' "/third_party/drm/drm/include/",\n'
583+
)
584+
mb.write(
585+
' "/third_party/drm/drm/include/libdrm" ]\n'
586+
)
587+
except KeyError:
588+
pass
589+
try:
590+
if (
591+
relsrcdir
592+
in write_mozbuild_variables["INCLUDE_SYSTEM_PIPEWIRE_HANDLING"]
593+
):
594+
mb.write('CXXFLAGS += CONFIG["MOZ_PIPEWIRE_CFLAGS"]\n')
595+
mb.write('if not CONFIG["MOZ_SYSTEM_PIPEWIRE"]:\n')
596+
mb.write(' LOCAL_INCLUDES += [ "/third_party/pipewire/" ]\n')
597+
except KeyError:
598+
pass
599+
try:
600+
if (
601+
relsrcdir
602+
in write_mozbuild_variables["INCLUDE_SYSTEM_LIBVPX_HANDLING"]
603+
):
604+
mb.write('if not CONFIG["MOZ_SYSTEM_LIBVPX"]:\n')
605+
mb.write(' LOCAL_INCLUDES += [ "/media/libvpx/libvpx/" ]\n')
606+
mb.write(' CXXFLAGS += CONFIG["MOZ_LIBVPX_CFLAGS"]\n')
607+
except KeyError:
608+
pass
609+
try:
610+
if (
611+
relsrcdir
612+
in write_mozbuild_variables["INCLUDE_SYSTEM_DAV1D_HANDLING"]
613+
):
614+
mb.write('if CONFIG["MOZ_SYSTEM_AV1"]:\n')
615+
mb.write(' CXXFLAGS += CONFIG["MOZ_SYSTEM_DAV1D_CFLAGS"]\n')
616+
mb.write(' CXXFLAGS += CONFIG["MOZ_SYSTEM_LIBAOM_CFLAGS"]\n')
617+
except KeyError:
618+
pass
619+
620+
all_args = [args for args, _ in configs]
621+
622+
623+
624+
625+
626+
for attrs in (
627+
(),
628+
("MOZ_DEBUG",),
629+
("OS_TARGET",),
630+
("TARGET_CPU",),
631+
("MOZ_DEBUG", "OS_TARGET"),
632+
("OS_TARGET", "MOZ_X11"),
633+
("OS_TARGET", "TARGET_CPU"),
634+
("OS_TARGET", "TARGET_CPU", "MOZ_X11"),
635+
("OS_TARGET", "TARGET_CPU", "MOZ_DEBUG"),
636+
("OS_TARGET", "TARGET_CPU", "MOZ_DEBUG", "MOZ_X11"),
637+
):
638+
conditions = set()
639+
for args in all_args:
640+
cond = tuple((k, args.get(k) or "") for k in attrs)
641+
conditions.add(cond)
642+
643+
for cond in sorted(conditions):
644+
common_attrs = find_common_attrs(
645+
[
646+
attrs
647+
for args, attrs in configs
648+
if all((args.get(k) or "") == v for k, v in cond)
649+
]
650+
)
651+
if any(common_attrs.values()):
652+
if cond:
653+
mb.write_condition(dict(cond))
654+
mb.write_attrs(common_attrs)
655+
if cond:
656+
mb.terminate_condition()
657+
658+
mb.finalize()
641659

642660

643661
dirs_mozbuild = mozpath.join(srcdir, "moz.build")
@@ -695,25 +713,19 @@ def write_mozbuild_files(
695713

696714

697715
def generate_gn_config(
698-
topsrcdir,
699716
build_root_dir,
700717
target_dir,
701718
gn_binary,
702719
input_variables,
703720
sandbox_variables,
704721
gn_target,
705722
moz_build_flag,
706-
non_unified_sources,
707-
mozilla_flags,
708723
):
709724
def str_for_arg(v):
710725
if v in (True, False):
711726
return str(v).lower()
712727
return '"%s"' % v
713728

714-
build_root_dir = topsrcdir / build_root_dir
715-
srcdir = build_root_dir / target_dir
716-
717729
input_variables = input_variables.copy()
718730
input_variables.update(
719731
{
@@ -773,14 +785,6 @@ def str_for_arg(v):
773785
input_variables,
774786
gn_target,
775787
)
776-
gn_config = process_gn_config(
777-
gn_config,
778-
topsrcdir,
779-
srcdir,
780-
non_unified_sources,
781-
gn_config["sandbox_vars"],
782-
mozilla_flags,
783-
)
784788
return gn_config
785789

786790

@@ -829,40 +833,26 @@ def main():
829833
vars_set.append(vars)
830834

831835
gn_configs = []
832-
NUM_WORKERS = 5
833-
with ProcessPoolExecutor(max_workers=NUM_WORKERS) as executor:
834-
835-
futures = {
836-
executor.submit(
837-
generate_gn_config,
838-
topsrcdir,
839-
config["build_root_dir"],
836+
for vars in vars_set:
837+
gn_configs.append(
838+
generate_gn_config(
839+
topsrcdir / config["build_root_dir"],
840840
config["target_dir"],
841841
gn_binary,
842842
vars,
843843
config["gn_sandbox_variables"],
844844
config["gn_target"],
845845
config["moz_build_flag"],
846-
config["non_unified_sources"],
847-
config["mozilla_flags"],
848-
): vars
849-
for vars in vars_set
850-
}
851-
852-
853-
for future in as_completed(futures):
854-
try:
855-
gn_configs.append(future.result())
856-
except Exception as e:
857-
print(f"[Task] Task failed with exception: {e}")
858-
859-
print("All generation tasks have been processed.")
846+
)
847+
)
860848

861849
print("Writing moz.build files")
862-
write_mozbuild_files(
850+
write_mozbuild(
863851
topsrcdir,
864852
topsrcdir / config["build_root_dir"] / config["target_dir"],
853+
config["non_unified_sources"],
865854
gn_configs,
855+
config["mozilla_flags"],
866856
config["write_mozbuild_variables"],
867857
)
868858

0 commit comments

Comments
 (0)