forked from KLayout/klayout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build4mac.py
executable file
·1831 lines (1673 loc) · 84.4 KB
/
build4mac.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#===============================================================================
# File: "macbuild/build4mac.py"
#
# The top Python script for building KLayout (http://www.klayout.de/index.php)
# version 0.26.1 or later on different Apple Mac OSX platforms.
#===============================================================================
import sys
import os
import codecs
import shutil
import glob
import platform
import optparse
import subprocess
import pprint
#-------------------------------------------------------------------------------
## To import global dictionaries of different modules and utility functions
#-------------------------------------------------------------------------------
mydir = os.path.dirname(os.path.abspath(__file__))
sys.path.append( mydir + "/macbuild" )
from build4mac_env import *
from build4mac_util import *
#-------------------------------------------------------------------------------
## To generate the OS-wise usage strings and the default module set
#
# @param[in] platform platform name
#
# @return (usage, moduleset)-tuple
#-------------------------------------------------------------------------------
def GenerateUsage(platform):
if platform.upper() in [ "VENTURA", "MONTEREY", "BIGSUR" ]: # with Xcode [13.1 .. ]
myQt56 = "qt5brew"
myRuby = "hb32"
myPython = "hb39"
moduleset = ('qt5Brew', 'HB32', 'HB39')
else: # with Xcode [ .. 12.4]; 'sys' for Python has been restored in 0.28.3
myQt56 = "qt5macports"
myRuby = "sys"
myPython = "sys"
moduleset = ('qt5MP', 'Sys', 'Sys')
usage = "\n"
usage += "---------------------------------------------------------------------------------------------------------\n"
usage += "<< Usage of 'build4mac.py' >>\n"
usage += " for building KLayout 0.28.6 or later on different Apple macOS / Mac OSX platforms.\n"
usage += "\n"
usage += "$ [python] ./build4mac.py\n"
usage += " option & argument : descriptions (refer to 'macbuild/build4mac_env.py' for details)| default value\n"
usage += " --------------------------------------------------------------------------------------+---------------\n"
usage += " [-q|--qt <type>] : case-insensitive type=['Qt5MacPorts', 'Qt5Brew', 'Qt5Ana3', | %s \n" % myQt56
usage += " : 'Qt6MacPorts', 'Qt6Brew'] | \n"
usage += " : Qt5MacPorts: use Qt5 from MacPorts | \n"
usage += " : Qt5Brew: use Qt5 from Homebrew | \n"
usage += " : Qt5Ana3: use Qt5 from Anaconda3 | \n"
usage += " : Qt6MacPorts: use Qt6 from MacPorts (*) | \n"
usage += " : Qt6Brew: use Qt6 from Homebrew (*) | \n"
usage += " : (*) migration to Qt6 is ongoing | \n"
usage += " [-r|--ruby <type>] : case-insensitive type=['nil', 'Sys', 'MP31', 'HB31', 'Ana3', | %s \n" % myRuby
usage += " : 'MP32', HB32'] | \n"
usage += " : nil: don't bind Ruby | \n"
usage += " : Sys: use OS-bundled Ruby [2.0 - 2.6] depending on OS | \n"
usage += " : MP31: use Ruby 3.1 from MacPorts | \n"
usage += " : HB31: use Ruby 3.1 from Homebrew | \n"
usage += " : Ana3: use Ruby 3.1 from Anaconda3 | \n"
usage += " : MP32: use Ruby 3.2 from MacPorts | \n"
usage += " : HB32: use Ruby 3.2 from Homebrew | \n"
usage += " [-p|--python <type>] : case-insensitive type=['nil', 'Sys', 'MP38', 'HB38', 'Ana3', | %s \n" % myPython
usage += " : 'MP39', HB39', 'HBAuto'] | \n"
usage += " : nil: don't bind Python | \n"
usage += " : Sys: use OS-bundled Python 2.7 up to Catalina | \n"
usage += " : MP38: use Python 3.8 from MacPorts | \n"
usage += " : HB38: use Python 3.8 from Homebrew | \n"
usage += " : Ana3: use Python 3.9 from Anaconda3 | \n"
usage += " : MP39: use Python 3.9 from MacPorts | \n"
usage += " : HB39: use Python 3.9 from Homebrew | \n"
usage += " : HBAuto: use the latest Python 3.x auto-detected from Homebrew | \n"
usage += " [-P|--buildPymod] : build and deploy Pymod (*.whl and *.egg) for LW-*.dmg | disabled\n"
usage += " [-n|--noqtbinding] : don't create Qt bindings for ruby scripts | disabled\n"
usage += " [-u|--noqtuitools] : don't include uitools in Qt binding | disabled\n"
usage += " [-m|--make <option>] : option passed to 'make' | '--jobs=4'\n"
usage += " [-d|--debug] : enable debug mode build | disabled\n"
usage += " [-c|--checkcom] : check command-line and exit without building | disabled\n"
usage += " [-y|--deploy] : deploy executables and dylibs, including Qt's Frameworks | disabled\n"
usage += " [-Y|--DEPLOY] : deploy executables and dylibs for those who built KLayout | disabled\n"
usage += " : from the source code and use the tools in the same machine | \n"
usage += " : ! After confirmation of the successful build of 'klayout.app', | \n"
usage += " : rerun this script with BOTH: | \n"
usage += " : 1) the same options used for building AND | \n"
usage += " : 2) <-y|--deploy> OR <-Y|--DEPLOY> | \n"
usage += " : optionally with [-v|--verbose <0-3>] | \n"
usage += " [-v|--verbose <0-3>] : verbose level of `macdeployqt' (effective with -y only) | 1\n"
usage += " : 0 = no output, 1 = error/warning (default), | \n"
usage += " : 2 = normal, 3 = debug | \n"
usage += " [-?|--?] : print this usage and exit; in zsh, quote like '-?' or '--?' | disabled\n"
usage += "-----------------------------------------------------------------------------------------+---------------\n"
return (usage, moduleset)
#-------------------------------------------------------------------------------
## To get the default configurations
#
# @return a dictionary containing the default configuration for the macOS build
#-------------------------------------------------------------------------------
def Get_Default_Config():
ProjectDir = os.getcwd()
BuildBash = "./build.sh"
(System, Node, Release, MacVersion, Machine, Processor) = platform.uname()
if not System == "Darwin":
print("")
print( "!!! Sorry. Your system <%s> looks like non-Mac" % System, file=sys.stderr )
print( GenerateUsage("")[0] )
sys.exit(1)
release = int( Release.split(".")[0] ) # take the first of ['19', '0', '0']
if release == 22:
Platform = "Ventura"
elif release == 21:
Platform = "Monterey"
elif release == 20:
Platform = "BigSur"
elif release == 19:
Platform = "Catalina"
elif release == 18:
Platform = "Mojave"
elif release == 17:
Platform = "HighSierra"
elif release == 16:
Platform = "Sierra"
elif release == 15:
Platform = "ElCapitan"
else:
Platform = ""
print("")
print( "!!! Sorry. Unsupported major OS release <%d>" % release, file=sys.stderr )
print( GenerateUsage("")[0] )
sys.exit(1)
if not Machine == "x86_64":
if Machine == "arm64" and Platform in ["Ventura", "Monterey", "BigSur"]: # with an Apple Silicon Chip
print("")
print( "### Your Mac equips an Apple Silicon Chip ###" )
print("")
else:
print("")
print( "!!! Sorry. Only x86_64/arm64 architecture machine is supported but found <%s>" % Machine, file=sys.stderr )
print( GenerateUsage("")[0] )
sys.exit(1)
# Set the OS-wise usage and module set
Usage, ModuleSet = GenerateUsage(Platform)
# Set the default modules
if Platform == "Ventura":
ModuleQt = "Qt5Brew"
ModuleRuby = "Ruby32Brew"
ModulePython = "Python39Brew"
elif Platform == "Monterey":
ModuleQt = "Qt5Brew"
ModuleRuby = "Ruby32Brew"
ModulePython = "Python39Brew"
elif Platform == "BigSur":
ModuleQt = "Qt5Brew"
ModuleRuby = "Ruby32Brew"
ModulePython = "Python39Brew"
elif Platform == "Catalina":
ModuleQt = "Qt5MacPorts"
ModuleRuby = "RubyCatalina"
ModulePython = "PythonCatalina"
elif Platform == "Mojave":
ModuleQt = "Qt5MacPorts"
ModuleRuby = "RubyMojave"
ModulePython = "PythonMojave"
elif Platform == "HighSierra":
ModuleQt = "Qt5MacPorts"
ModuleRuby = "RubyHighSierra"
ModulePython = "PythonHighSierra"
elif Platform == "Sierra":
ModuleQt = "Qt5MacPorts"
ModuleRuby = "RubySierra"
ModulePython = "PythonSierra"
elif Platform == "ElCapitan":
ModuleQt = "Qt5MacPorts"
ModuleRuby = "RubyElCapitan"
ModulePython = "PythonElCapitan"
else:
ModuleQt = "Qt5MacPorts"
ModuleRuby = "nil"
ModulePython = "nil"
BuildPymod = False
NonOSStdLang = False
NoQtBindings = False
NoQtUiTools = False
MakeOptions = "--jobs=4"
DebugMode = False
CheckComOnly = False
DeploymentF = False
DeploymentP = False
PackagePrefix = ""
DeployVerbose = 1
Version = GetKLayoutVersionFrom( "./version.sh" )
config = dict()
config['ProjectDir'] = ProjectDir # project directory where "build.sh" exists
config['Usage'] = Usage # string on usage
config['BuildBash'] = BuildBash # the main build Bash script
config['Platform'] = Platform # platform
config['ModuleQt'] = ModuleQt # Qt module to be used
config['ModuleRuby'] = ModuleRuby # Ruby module to be used
config['ModulePython'] = ModulePython # Python module to be used
config['BuildPymod'] = BuildPymod # True to build and deploy "Pymod"
config['NonOSStdLang'] = NonOSStdLang # True if non-OS-standard language is chosen
config['NoQtBindings'] = NoQtBindings # True if not creating Qt bindings for Ruby scripts
config['NoQtUiTools'] = NoQtUiTools # True if not to include QtUiTools in Qt binding
config['MakeOptions'] = MakeOptions # options passed to `make`
config['DebugMode'] = DebugMode # True if debug mode build
config['CheckComOnly'] = CheckComOnly # True if only for checking the command line parameters to "build.sh"
config['DeploymentF'] = DeploymentF # True if fully (including Qt's Frameworks) deploy the binaries for bundles
config['DeploymentP'] = DeploymentP # True if partially deploy the binaries excluding Qt's Frameworks
config['PackagePrefix'] = PackagePrefix # the package prefix: 'ST-', 'LW-', 'HW-', or 'EX-'
config['DeployVerbose'] = DeployVerbose # -verbose=<0-3> level passed to 'macdeployqt' tool
config['Version'] = Version # KLayout's version
config['ModuleSet'] = ModuleSet # (Qt, Ruby, Python)-tuple
# auxiliary variables on platform
config['System'] = System # 6-tuple from platform.uname()
config['Node'] = Node # - do -
config['Release'] = Release # - do -
config['MacVersion'] = MacVersion # - do -
config['Machine'] = Machine # - do -
config['Processor'] = Processor # - do -
return config
#------------------------------------------------------------------------------
## To apply a workaround patch to "./src/klayout.pri" to work with Ruby 3.x.
#
# @param[in] config dictionary containing the default configuration
#
# @return void
#------------------------------------------------------------------------------
def ApplyPatch2KLayoutQtPri4Ruby3(config):
#----------------------------------------------------------------
# [1] Check if the previous patch exists
#----------------------------------------------------------------
priMaster = "./src/klayout.pri"
priOriginal = "./src/klayout.pri.org"
if os.path.exists(priOriginal):
shutil.copy2( priOriginal, priMaster )
os.remove( priOriginal )
#----------------------------------------------------------------
# [2] Not using Ruby?
#----------------------------------------------------------------
ModuleRuby = config['ModuleRuby']
if ModuleRuby == 'nil':
return;
#----------------------------------------------------------------
# [3] Get the Ruby version code as done in "build.sh"
#----------------------------------------------------------------
rubyExe = RubyDictionary[ModuleRuby]['exe']
oneline = "puts (RbConfig::CONFIG['MAJOR'] || 0).to_i*10000+(RbConfig::CONFIG['MINOR'] || 0).to_i*100+(RbConfig::CONFIG['TEENY'] || 0).to_i"
command = [ '%s' % rubyExe, '-rrbconfig', '-e', '%s' % oneline ]
verCode = subprocess.check_output( command, encoding='utf-8' ).strip() # like 3.1.2 => "30102"
verInt = int(verCode)
verMajor = verInt // 10000
verMinor = (verInt - verMajor * 10000) // 100
verTeeny = (verInt - verMajor * 10000) - (verMinor * 100)
# print( verMajor, verMinor, verTeeny )
# quit()
if verMajor < 3:
return;
#-----------------------------------------------------------------------------------------------
# [4] The two buggy Apple compilers below flag errors like:
#
# /Applications/anaconda3/include/ruby-3.1.0/ruby/internal/intern/vm.h:383:1: error: \
# '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to \
# enable support for __declspec attributes RBIMPL_ATTR_NORETURN()
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Problematic in <Catalina> with
# Apple clang version 12.0.0 (clang-1200.0.32.29)
# Target: x86_64-apple-darwin19.6.0
# Thread model: posix
#
# Problematic in <Big Sur> with
# Apple clang version 13.0.0 (clang-1300.0.29.30)
# Target: x86_64-apple-darwin20.6.0
# Thread model: posix
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Non-problematic in <Monterey> with
# Apple clang version 13.1.6 (clang-1316.0.21.2.5)
# Target: x86_64-apple-darwin21.6.0
# Thread model: posix
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Refer to https://github.com/nginx/unit/issues/653
# https://github.com/nginx/unit/issues/653#issuecomment-1062129080
#
# Pass "-fdeclspec" option to the QMAKE_CXXFLAGS macro via the "./src/klayout.pri" file like:
"""
# <build4mac.py> applied this patch for Mac to work with Ruby 3.x
mac {
QMAKE_CXXFLAGS += -fdeclspec
}
# <build4mac.py> applied this patch for Mac to work with Ruby 3.x
"""
#-----------------------------------------------------------------------------------------------
#----------------------------------------------------------------
# (A) Check Platform
#----------------------------------------------------------------
Platform = config['Platform']
if Platform in [ "Ventura", "Monterey" ]:
return
elif Platform in [ "BigSur", "Catalina" ]: # take care
pass
else:
return # the results are not tested and unknown
#----------------------------------------------------------------
# (B) Check ./src/klayout.pri and apply the patch if necessary
#----------------------------------------------------------------
keystring = "<build4mac.py> applied this patch for Mac to work with Ruby 3.x"
patPatch = r"(^#)([ ]*)(%s)([ ]*$)" % keystring
regPatch = re.compile(patPatch)
foundKey1 = False
foundKey2 = False
with codecs.open( priMaster, "r", "utf-8" ) as file:
allLines = file.readlines()
file.close()
for line in allLines:
if regPatch.match( line.strip() ):
if not foundKey1:
foundKey1 = True
continue
elif not foundKey2:
foundKey2 = True
break
if foundKey1 and foundKey2:
return
shutil.copy2( priMaster, priOriginal )
with codecs.open( priMaster, "a", "utf-8" ) as file:
file.write( "# %s\n" % keystring )
file.write( "mac {\n" )
file.write( " QMAKE_CXXFLAGS += -fdeclspec\n" )
file.write( "}\n" )
file.write( "# %s\n" % keystring )
return
#------------------------------------------------------------------------------
## To parse the command line parameters
#
# @param[in] config dictionary containing the default configuration
#
# @return the configuration dictionary updated with the CLI parameters
#------------------------------------------------------------------------------
def Parse_CLI_Args(config):
#-----------------------------------------------------
# [1] Retrieve the configuration
#-----------------------------------------------------
Usage = config['Usage']
Platform = config['Platform']
Release = config['Release']
Machine = config['Machine']
ModuleQt = config['ModuleQt']
ModuleRuby = config['ModuleRuby']
ModulePython = config['ModulePython']
BuildPymod = config['BuildPymod']
NonOSStdLang = config['NonOSStdLang']
NoQtBindings = config['NoQtBindings']
NoQtUiTools = config['NoQtUiTools']
MakeOptions = config['MakeOptions']
DebugMode = config['DebugMode']
CheckComOnly = config['CheckComOnly']
DeploymentF = config['DeploymentF']
DeploymentP = config['DeploymentP']
PackagePrefix = config['PackagePrefix']
DeployVerbose = config['DeployVerbose']
ModuleSet = config['ModuleSet']
#-----------------------------------------------------
# [2] Parse the CLI arguments
#-----------------------------------------------------
p = optparse.OptionParser(usage=Usage)
p.add_option( '-q', '--qt',
dest='type_qt',
help="Qt type=['Qt5MacPorts', 'Qt5Brew', 'Qt5Ana3', 'Qt6MacPorts', 'Qt6Brew']" )
p.add_option( '-r', '--ruby',
dest='type_ruby',
help="Ruby type=['nil', 'Sys', 'MP31', 'HB31', 'Ana3', 'MP32', 'HB32']" )
p.add_option( '-p', '--python',
dest='type_python',
help="Python type=['nil', 'Sys', 'MP38', 'HB38', 'Ana3', 'MP39', 'HB39', 'HBAuto']" )
p.add_option( '-P', '--buildPymod',
action='store_true',
dest='build_pymod',
default=False,
help="build and deploy <Pymod> (disabled)" )
p.add_option( '-n', '--noqtbinding',
action='store_true',
dest='no_qt_binding',
default=False,
help="do not create Qt bindings for Ruby scripts" )
p.add_option( '-u', '--noqtuitools',
action='store_true',
dest='no_qt_uitools',
default=False,
help="don't include uitools in Qt binding" )
p.add_option( '-m', '--make',
dest='make_option',
help="options passed to `make`" )
p.add_option( '-d', '--debug',
action='store_true',
dest='debug_build',
default=False,
help="enable debug mode build" )
p.add_option( '-c', '--checkcom',
action='store_true',
dest='check_command',
default=False,
help="check command line and exit without building" )
p.add_option( '-y', '--deploy',
action='store_true',
dest='deploy_full',
default=False,
help="fully deploy built binaries" )
p.add_option( '-Y', '--DEPLOY',
action='store_true',
dest='deploy_partial',
default=False,
help="deploy built binaries when non-OS-standard script language is chosen" )
p.add_option( '-v', '--verbose',
dest='deploy_verbose',
help="verbose level of `macdeployqt` tool" )
p.add_option( '-?', '--??',
action='store_true',
dest='checkusage',
default=False,
help='check usage' )
if Platform.upper() in [ "VENTURA", "MONTEREY", "BIGSUR" ]: # with Xcode [13.1 .. ]
p.set_defaults( type_qt = "qt5brew",
type_ruby = "hb32",
type_python = "hb39",
build_pymod = False,
no_qt_binding = False,
no_qt_uitools = False,
make_option = "--jobs=4",
debug_build = False,
check_command = False,
deploy_full = False,
deploy_partial = False,
deploy_verbose = "1",
checkusage = False )
else: # with Xcode [ .. 12.4]
p.set_defaults( type_qt = "qt5macports",
type_ruby = "sys",
type_python = "sys",
build_pymod = False,
no_qt_binding = False,
no_qt_uitools = False,
make_option = "--jobs=4",
debug_build = False,
check_command = False,
deploy_full = False,
deploy_partial = False,
deploy_verbose = "1",
checkusage = False )
opt, args = p.parse_args()
if (opt.checkusage):
print(Usage)
sys.exit(0)
# (A) Determine the Qt type
candidates = dict()
candidates['QT5MACPORTS'] = 'Qt5MacPorts'
candidates['QT5BREW'] = 'Qt5Brew'
candidates['QT5ANA3'] = 'Qt5Ana3'
candidates['QT6MACPORTS'] = 'Qt6MacPorts'
candidates['QT6BREW'] = 'Qt6Brew'
try:
ModuleQt = candidates[ opt.type_qt.upper() ]
except KeyError:
ModuleQt = ''
pass
if ModuleQt == '':
print("")
print( "!!! Unknown Qt type <%s>. Case-insensitive candidates: %s" % \
(opt.type_qt, list(candidates.keys())), file=sys.stderr )
print(Usage)
sys.exit(1)
elif ModuleQt == "Qt5MacPorts":
choiceQt56 = 'qt5MP'
elif ModuleQt == "Qt5Brew":
choiceQt56 = 'qt5Brew'
elif ModuleQt == "Qt5Ana3":
choiceQt56 = 'qt5Ana3'
elif ModuleQt == "Qt6MacPorts":
choiceQt56 = 'qt6MP'
elif ModuleQt == "Qt6Brew":
choiceQt56 = 'qt6Brew'
# By default, OS-standard (-bundled) script languages (Ruby and Python) are used
NonOSStdLang = False
# (B) Determine the Ruby type
candidates = dict()
candidates['NIL'] = 'nil'
candidates['SYS'] = 'Sys'
candidates['MP31'] = 'MP31'
candidates['HB31'] = 'HB31'
candidates['ANA3'] = 'Ana3'
candidates['MP32'] = 'MP32'
candidates['HB32'] = 'HB32'
try:
choiceRuby = candidates[ opt.type_ruby.upper() ]
except KeyError:
ModuleRuby = ''
pass
else:
ModuleRuby = ''
if choiceRuby == "nil":
ModuleRuby = 'nil'
elif choiceRuby == "Sys":
choiceRuby = "Sys"
if Platform == "Ventura":
ModuleRuby = 'RubyVentura'
elif Platform == "Monterey":
ModuleRuby = 'RubyMonterey'
elif Platform == "BigSur":
ModuleRuby = 'RubyBigSur'
elif Platform == "Catalina":
ModuleRuby = 'RubyCatalina'
elif Platform == "Mojave":
ModuleRuby = 'RubyMojave'
elif Platform == "HighSierra":
ModuleRuby = 'RubyHighSierra'
elif Platform == "Sierra":
ModuleRuby = 'RubySierra'
elif Platform == "ElCapitan":
ModuleRuby = 'RubyElCapitan'
elif choiceRuby == "MP31":
ModuleRuby = 'Ruby31MacPorts'
NonOSStdLang = True
elif choiceRuby == "HB31":
ModuleRuby = 'Ruby31Brew'
NonOSStdLang = True
elif choiceRuby == "Ana3":
ModuleRuby = 'RubyAnaconda3'
NonOSStdLang = True
elif choiceRuby == "MP32":
ModuleRuby = 'Ruby32MacPorts'
NonOSStdLang = True
elif choiceRuby == "HB32":
ModuleRuby = 'Ruby32Brew'
NonOSStdLang = True
if ModuleRuby == '':
print("")
print( "!!! Unknown Ruby type <%s>. Case-insensitive candidates: %s" % \
(opt.type_ruby, list(candidates.keys())), file=sys.stderr )
print(Usage)
sys.exit(1)
# (C) Determine the Python type
candidates = dict()
candidates['NIL'] = 'nil'
candidates['SYS'] = 'Sys' # has been restored in 0.28.3
candidates['MP38'] = 'MP38'
candidates['HB38'] = 'HB38'
candidates['ANA3'] = 'Ana3'
candidates['MP39'] = 'MP39'
candidates['HB39'] = 'HB39'
candidates['HBAUTO'] = 'HBAuto'
try:
choicePython = candidates[ opt.type_python.upper() ]
except KeyError:
ModulePython = ''
pass
else:
ModulePython = ''
if choicePython == "nil":
ModulePython = 'nil'
elif choicePython == "Sys":
if Platform in [ "Ventura", "Monterey", "BigSur" ]:
raise Exception( "! Cannot choose the 'sys' Python on <%s>" % Platform )
elif Platform == "Catalina":
ModulePython = 'PythonCatalina'
elif Platform == "Mojave":
ModulePython = 'PythonMojave'
elif Platform == "HighSierra":
ModulePython = 'PythonHighSierra'
elif Platform == "Sierra":
ModulePython = 'PythonSierra'
elif Platform == "ElCapitan":
ModulePython = 'PythonElCapitan'
elif choicePython == "MP38":
ModulePython = 'Python38MacPorts'
NonOSStdLang = True
elif choicePython == "HB38":
ModulePython = 'Python38Brew'
NonOSStdLang = True
elif choicePython == "Ana3":
ModulePython = 'PythonAnaconda3'
NonOSStdLang = True
elif choicePython == "MP39":
ModulePython = 'Python39MacPorts'
elif choicePython == "HB39":
ModulePython = 'Python39Brew'
NonOSStdLang = True
elif choicePython == "HBAuto":
ModulePython = 'PythonAutoBrew'
NonOSStdLang = True
if ModulePython == '':
print("")
print( "!!! Unknown Python type <%s>. Case-insensitive candidates: %s" % \
(opt.type_python, list(candidates.keys())), file=sys.stderr )
print(Usage)
sys.exit(1)
# (D) Set of modules chosen
ModuleSet = ( choiceQt56, choiceRuby, choicePython )
# (E) Set other parameters
BuildPymod = opt.build_pymod
NoQtBindings = opt.no_qt_binding
NoQtUiTools = opt.no_qt_uitools
MakeOptions = opt.make_option
DebugMode = opt.debug_build
CheckComOnly = opt.check_command
DeploymentF = opt.deploy_full
DeploymentP = opt.deploy_partial
if DeploymentF and DeploymentP:
print("")
print( "!!! Choose either [-y|--deploy] or [-Y|--DEPLOY]", file=sys.stderr )
print(Usage)
sys.exit(1)
DeployVerbose = int(opt.deploy_verbose)
if not DeployVerbose in [0, 1, 2, 3]:
print("")
print( "!!! Unsupported verbose level passed to `macdeployqt` tool", file=sys.stderr )
print(Usage)
sys.exit(1)
if not DeploymentF and not DeploymentP:
target = "%s %s %s" % (Platform, Release, Machine)
modules = "Qt=%s, Ruby=%s, Python=%s" % (ModuleQt, ModuleRuby, ModulePython)
if BuildPymod:
pymodbuild = "enabled"
else:
pymodbuild = "disabled"
message = "### You are going to build KLayout\n for <%s>\n with <%s>\n with Pymod <%s>...\n"
print("")
print( message % (target, modules, pymodbuild) )
else:
message = "### You are going to make "
if DeploymentP:
PackagePrefix = "LW-"
if not BuildPymod:
message += "a lightweight (LW-) package excluding Qt5, Ruby, and Python..."
else:
message += "a lightweight (LW-) package with Pymod excluding Qt5, Ruby, and Python..."
elif DeploymentF:
if (ModuleRuby in RubySys) and (ModulePython in PythonSys):
PackagePrefix = "ST-"
message += "a standard (ST-) package including Qt[5|6] and using OS-bundled Ruby and Python..."
elif ModulePython in ['Python38Brew', 'Python39Brew', 'PythonAutoBrew']:
PackagePrefix = "HW-"
message += "a heavyweight (HW-) package including Qt[5|6] and Python3.8~ from Homebrew..."
else:
PackagePrefix = "EX-"
message += "a package with exceptional (EX-) combinations of different modules..."
print( "" )
print( message )
print( "" )
if CheckComOnly:
sys.exit(0)
#-----------------------------------------------------
# [3] Update the configuration to return
#-----------------------------------------------------
config['Usage'] = Usage
config['Platform'] = Platform
config['ModuleQt'] = ModuleQt
config['ModuleRuby'] = ModuleRuby
config['ModulePython'] = ModulePython
config['BuildPymod'] = BuildPymod
config['NonOSStdLang'] = NonOSStdLang
config['NoQtBindings'] = NoQtBindings
config['NoQtUiTools'] = NoQtUiTools
config['MakeOptions'] = MakeOptions
config['DebugMode'] = DebugMode
config['CheckComOnly'] = CheckComOnly
config['DeploymentF'] = DeploymentF
config['DeploymentP'] = DeploymentP
config['PackagePrefix'] = PackagePrefix
config['DeployVerbose'] = DeployVerbose
config['ModuleSet'] = ModuleSet
if CheckComOnly:
pp = pprint.PrettyPrinter( indent=4, width=140 )
parameters = Get_Build_Parameters(config)
Build_pymod(parameters)
pp.pprint(parameters)
sys.exit(0)
else:
return config
#------------------------------------------------------------------------------
## To run the main Bash script "build.sh" with appropriate options
#
# @param[in] config dictionary containing the build configuration
# @return a dictionary containing the build parameters
#------------------------------------------------------------------------------
def Get_Build_Parameters(config):
#-----------------------------------------------------
# [1] Retrieve the configuration
#-----------------------------------------------------
ProjectDir = config['ProjectDir']
Platform = config['Platform']
BuildBash = config['BuildBash']
ModuleQt = config['ModuleQt']
ModuleRuby = config['ModuleRuby']
ModulePython = config['ModulePython']
BuildPymod = config['BuildPymod']
ModuleSet = config['ModuleSet']
NoQtBindings = config['NoQtBindings']
NoQtUiTools = config['NoQtUiTools']
MakeOptions = config['MakeOptions']
DebugMode = config['DebugMode']
CheckComOnly = config['CheckComOnly']
DeploymentF = config['DeploymentF']
DeploymentP = config['DeploymentP']
PackagePrefix = config['PackagePrefix']
#-----------------------------------------------------
# [2] Set parameters passed to the main Bash script
#-----------------------------------------------------
parameters = dict()
parameters['build_cmd'] = BuildBash
parameters['check_cmd_only'] = CheckComOnly
# (A) debug or release
parameters['debug_mode'] = DebugMode # True if debug, False if release
if parameters["debug_mode"]:
mode = "debug"
else:
mode = "release"
# (B) Modules
(qt, ruby, python) = ModuleSet # ( 'qt6Brew', 'Sys', 'Sys' )
ruby_python = "R%sP%s" % ( ruby.lower(), python.lower() )
# (C) Target directories and files
MacPkgDir = "%s%s.pkg.macos-%s-%s-%s" % (PackagePrefix, qt, Platform, mode, ruby_python)
MacBinDir = "%s.bin.macos-%s-%s-%s" % ( qt, Platform, mode, ruby_python)
MacBuildDir = "%s.build.macos-%s-%s-%s" % ( qt, Platform, mode, ruby_python)
MacBuildLog = "%s.build.macos-%s-%s-%s.log" % ( qt, Platform, mode, ruby_python)
MacBuildDirQAT = MacBuildDir + ".macQAT"
parameters['logfile'] = MacBuildLog
# (D) Qt5|6
if ModuleQt == 'Qt5MacPorts':
parameters['qmake'] = Qt5MacPorts['qmake']
parameters['deploy_tool'] = Qt5MacPorts['deploy']
elif ModuleQt == 'Qt5Brew':
parameters['qmake'] = Qt5Brew['qmake']
parameters['deploy_tool'] = Qt5Brew['deploy']
elif ModuleQt == 'Qt5Ana3':
parameters['qmake'] = Qt5Ana3['qmake']
parameters['deploy_tool'] = Qt5Ana3['deploy']
elif ModuleQt == 'Qt6MacPorts':
parameters['qmake'] = Qt6MacPorts['qmake']
parameters['deploy_tool'] = Qt6MacPorts['deploy']
elif ModuleQt == 'Qt6Brew':
parameters['qmake'] = Qt6Brew['qmake']
parameters['deploy_tool'] = Qt6Brew['deploy']
parameters['bin'] = MacBinDir
parameters['build'] = MacBuildDir
parameters['rpath'] = "@executable_path/../Frameworks"
# (E) want Qt bindings with Ruby scripts?
parameters['no_qt_bindings'] = NoQtBindings
# (F) want QtUiTools?
parameters['no_qt_uitools'] = NoQtUiTools
# (G) options to `make` tool
if not MakeOptions == "":
parameters['make_options'] = MakeOptions
try:
jobopt, number = MakeOptions.split('=') # like '--jobs=4' ?
pnum = int(number)
except Exception:
parameters['num_parallel'] = 4 # default
else:
parameters['num_parallel'] = pnum
# (H) about Ruby
if ModuleRuby != "nil":
ApplyPatch2KLayoutQtPri4Ruby3( config )
parameters['ruby'] = RubyDictionary[ModuleRuby]['exe']
parameters['rbinc'] = RubyDictionary[ModuleRuby]['inc']
parameters['rblib'] = RubyDictionary[ModuleRuby]['lib']
if 'inc2' in RubyDictionary[ModuleRuby]:
parameters['rbinc2'] = RubyDictionary[ModuleRuby]['inc2']
# (I) about Python
if ModulePython != "nil":
parameters['python'] = PythonDictionary[ModulePython]['exe']
parameters['pyinc'] = PythonDictionary[ModulePython]['inc']
parameters['pylib'] = PythonDictionary[ModulePython]['lib']
config['MacPkgDir'] = MacPkgDir # relative path to package directory
config['MacBinDir'] = MacBinDir # relative path to binary directory
config['MacBuildDir'] = MacBuildDir # relative path to build directory
config['MacBuildDirQAT'] = MacBuildDirQAT # relative path to build directory for QATest
config['MacBuildLog'] = MacBuildLog # relative path to build log file
# (J) Extra parameters needed for deployment
parameters['project_dir'] = ProjectDir
# (K) Extra parameters needed for <pymod>
# <pymod> will be built if:
# BuildPymod = True
# Platform = [ 'Monterey', 'BigSur', 'Catalina' ]
# ModuleRuby = [ 'Ruby31MacPorts', 'Ruby31Brew', 'RubyAnaconda3' ]
# ModulePython = [ 'Python38MacPorts', 'Python38Brew', 'Python39Brew',
# 'PythonAnaconda3', 'PythonAutoBrew' ]
parameters['BuildPymod'] = BuildPymod
parameters['Platform'] = Platform
parameters['ModuleRuby'] = ModuleRuby
parameters['ModulePython'] = ModulePython
PymodDistDir = dict()
if Platform in [ 'Ventura', 'Monterey', 'BigSur', 'Catalina' ]:
if ModuleRuby in [ 'Ruby31MacPorts', 'Ruby31Brew', 'RubyAnaconda3', 'Ruby32MacPorts', 'Ruby32Brew' ]:
if ModulePython in [ 'Python38MacPorts', 'Python39MacPorts' ]:
PymodDistDir[ModulePython] = 'dist-MP3'
elif ModulePython in [ 'Python38Brew', 'Python39Brew', 'PythonAutoBrew' ]:
PymodDistDir[ModulePython] = 'dist-HB3'
elif ModulePython in [ 'PythonAnaconda3' ]:
PymodDistDir[ModulePython] = 'dist-ana3'
parameters['pymod_dist'] = PymodDistDir
return parameters
#------------------------------------------------------------------------------
## To run the "setup.py" script with appropriate options for building
# the klayout Python Module "pymod".
#
# @param[in] parameters dictionary containing the build parameters
#
# @return 0 on success; non-zero (1), otherwise
#------------------------------------------------------------------------------
def Build_pymod(parameters):
#---------------------------------------------------------------------------
# [1] <pymod> will be built if:
# BuildPymod = True
# Platform = [ 'Ventura', 'Monterey', 'BigSur', 'Catalina' ]
# ModuleRuby = [ 'Ruby31MacPorts', 'Ruby31Brew', 'RubyAnaconda3',
# 'Ruby32MacPorts', 'Ruby32Brew' ]
# ModulePython = [ 'Python38MacPorts', 'Python38Brew', 'PythonAnaconda3',
# 'Python39MacPorts', 'Python39Brew', 'PythonAutoBrew' ]
#---------------------------------------------------------------------------
BuildPymod = parameters['BuildPymod']
Platform = parameters['Platform']
ModuleRuby = parameters['ModuleRuby']
ModulePython = parameters['ModulePython']
if not BuildPymod:
return 0
if not Platform in [ 'Ventura', 'Monterey', 'BigSur', 'Catalina' ]:
return 0
elif not ModuleRuby in [ 'Ruby31MacPorts', 'Ruby31Brew', 'RubyAnaconda3', 'Ruby32MacPorts', 'Ruby32Brew' ]:
return 0
elif not ModulePython in [ 'Python38MacPorts', 'Python38Brew', 'PythonAnaconda3', \
'Python39MacPorts', 'Python39Brew', 'PythonAutoBrew' ]:
return 0
#--------------------------------------------------------------------
# [2] Get the new directory names (dictionary) for "dist" and
# set the CPATH environment variable for including <png.h>
# required to build the pymod of 0.28 or later
#--------------------------------------------------------------------
PymodDistDir = parameters['pymod_dist']
# Using MacPorts
if PymodDistDir[ModulePython] == 'dist-MP3':
addBinPath = "/opt/local/bin"
addIncPath = "/opt/local/include"
addLibPath = "/opt/local/lib"
# Using Homebrew
elif PymodDistDir[ModulePython] == 'dist-HB3':
addBinPath = "%s/bin" % DefaultHomebrewRoot # defined in "build4mac_env.py"
addIncPath = "%s/include" % DefaultHomebrewRoot # -- ditto --
addLibPath = "%s/lib" % DefaultHomebrewRoot # -- ditto --
elif PymodDistDir[ModulePython] == 'dist-ana3':
addBinPath = "/Applications/anaconda3/bin"
addIncPath = "/Applications/anaconda3/include"
addLibPath = "/Applications/anaconda3/lib"
else:
addBinPath = ""
addIncPath = ""
addLibPath = ""
if not addBinPath == "":
try:
bpath = os.environ['PATH']
except KeyError:
os.environ['PATH'] = addBinPath
else:
os.environ['PATH'] = "%s:%s" % (addBinPath, bpath)
if not addIncPath == "":
try:
cpath = os.environ['CPATH']
except KeyError:
os.environ['CPATH'] = addIncPath
else:
os.environ['CPATH'] = "%s:%s" % (addIncPath, cpath)
if not addLibPath == "":
try:
ldpath = os.environ['LDFLAGS']
except KeyError:
os.environ['LDFLAGS'] = '-L%s' % addLibPath
else:
os.environ['LDFLAGS'] = '-L%s %s' % (addLibPath, ldpath)
#--------------------------------------------------------------------
# [3] Set different command line parameters for building <pymod>
#--------------------------------------------------------------------
cmd1_args = " -m setup build \\\n"
cmd2_args = " -m setup bdist_wheel \\\n"
deloc_cmd = " delocate-wheel --ignore-missing-dependencies"
cmd3_args = " <wheel file> \\\n"
cmd4_args = " -m setup clean --all \\\n"
#--------------------------------------------------------------------
# [4] Make the consolidated command lines
#--------------------------------------------------------------------
command1 = "time"
command1 += " \\\n %s \\\n" % parameters['python']
command1 += cmd1_args
command1 += " 2>&1 | tee -a %s; \\\n" % parameters['logfile']
command1 += " test ${PIPESTATUS[0]} -eq 0" # tee always exits with 0
command2 = "time"
command2 += " \\\n %s \\\n" % parameters['python']
command2 += cmd2_args
command2 += " 2>&1 | tee -a %s; \\\n" % parameters['logfile']
command2 += " test ${PIPESTATUS[0]} -eq 0" # tee always exits with 0
command3 = "time"
command3 += " \\\n %s \\\n" % deloc_cmd
command3 += cmd3_args
command3 += " 2>&1 | tee -a %s; \\\n" % parameters['logfile']
command3 += " test ${PIPESTATUS[0]} -eq 0" # tee always exits with 0
command4 = "time"
command4 += " \\\n %s \\\n" % parameters['python']
command4 += cmd4_args
command4 += " 2>&1 | tee -a %s; \\\n" % parameters['logfile']
command4 += " test ${PIPESTATUS[0]} -eq 0" # tee always exits with 0
print( "" )
print( "### You are going to build <pymod> with the following four stages." )
print( "<Stage-1>")
print( " ", command1 )
print( "" )
print( "<Stage-2>")
print( " ", command2 )
print( "" )
print( "<Stage-3>")
print( " ", command3 )
print( "" )
print( "<Stage-4>")
print( " ", command4 )