9
9
import sys
10
10
import tempfile
11
11
from collections import defaultdict , deque
12
- from concurrent .futures import ProcessPoolExecutor , as_completed
13
12
from copy import deepcopy
14
13
from pathlib import Path
15
14
from shutil import which
@@ -515,114 +514,27 @@ def make_difference(reference, input_attrs):
515
514
return common_attrs
516
515
517
516
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 (
621
518
topsrcdir ,
622
519
srcdir ,
623
- all_mozbuild_results ,
520
+ non_unified_sources ,
521
+ gn_configs ,
522
+ mozilla_flags ,
624
523
write_mozbuild_variables ,
625
524
):
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
+
626
538
627
539
628
540
configs_by_dir = defaultdict (list )
@@ -633,11 +545,117 @@ def write_mozbuild_files(
633
545
configs_by_dir [d ].append ((mozbuild_args , build_data ))
634
546
635
547
mozbuilds = set ()
636
-
637
548
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 ()
641
659
642
660
643
661
dirs_mozbuild = mozpath .join (srcdir , "moz.build" )
@@ -695,25 +713,19 @@ def write_mozbuild_files(
695
713
696
714
697
715
def generate_gn_config (
698
- topsrcdir ,
699
716
build_root_dir ,
700
717
target_dir ,
701
718
gn_binary ,
702
719
input_variables ,
703
720
sandbox_variables ,
704
721
gn_target ,
705
722
moz_build_flag ,
706
- non_unified_sources ,
707
- mozilla_flags ,
708
723
):
709
724
def str_for_arg (v ):
710
725
if v in (True , False ):
711
726
return str (v ).lower ()
712
727
return '"%s"' % v
713
728
714
- build_root_dir = topsrcdir / build_root_dir
715
- srcdir = build_root_dir / target_dir
716
-
717
729
input_variables = input_variables .copy ()
718
730
input_variables .update (
719
731
{
@@ -773,14 +785,6 @@ def str_for_arg(v):
773
785
input_variables ,
774
786
gn_target ,
775
787
)
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
- )
784
788
return gn_config
785
789
786
790
@@ -829,40 +833,26 @@ def main():
829
833
vars_set .append (vars )
830
834
831
835
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" ],
840
840
config ["target_dir" ],
841
841
gn_binary ,
842
842
vars ,
843
843
config ["gn_sandbox_variables" ],
844
844
config ["gn_target" ],
845
845
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
+ )
860
848
861
849
print ("Writing moz.build files" )
862
- write_mozbuild_files (
850
+ write_mozbuild (
863
851
topsrcdir ,
864
852
topsrcdir / config ["build_root_dir" ] / config ["target_dir" ],
853
+ config ["non_unified_sources" ],
865
854
gn_configs ,
855
+ config ["mozilla_flags" ],
866
856
config ["write_mozbuild_variables" ],
867
857
)
868
858
0 commit comments