-
Notifications
You must be signed in to change notification settings - Fork 5
/
SConstruct
1398 lines (1160 loc) · 50.5 KB
/
SConstruct
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
#
# SConstruct file to build scons packages during development.
#
# See the README.rst file for an overview of how SCons is built and tested.
from __future__ import print_function
copyright_years = '2001 - 2017'
# This gets inserted into the man pages to reflect the month of release.
month_year = 'September 2017'
#
# __COPYRIGHT__
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
import distutils.util
import fnmatch
import os
import os.path
import re
import stat
import sys
import tempfile
import time
import bootstrap
project = 'scons'
default_version = '3.0.0'
copyright = "Copyright (c) %s The SCons Foundation" % copyright_years
platform = distutils.util.get_platform()
def is_windows():
if platform.startswith('win'):
return True
else:
return False
SConsignFile()
#
# An internal "whereis" routine to figure out if a given program
# is available on this system.
#
def whereis(file):
exts = ['']
if is_windows():
exts += ['.exe']
for dir in os.environ['PATH'].split(os.pathsep):
f = os.path.join(dir, file)
for ext in exts:
f_ext = f + ext
if os.path.isfile(f_ext):
try:
st = os.stat(f_ext)
except:
continue
if stat.S_IMODE(st[stat.ST_MODE]) & 0o111:
return f_ext
return None
#
# We let the presence or absence of various utilities determine whether
# or not we bother to build certain pieces of things. This should allow
# people to still do SCons packaging work even if they don't have all
# of the utilities installed (e.g. RPM).
#
dh_builddeb = whereis('dh_builddeb')
fakeroot = whereis('fakeroot')
gzip = whereis('gzip')
rpmbuild = whereis('rpmbuild')
git = os.path.exists('.git') and whereis('git')
unzip = whereis('unzip')
zip = whereis('zip')
#
# Now grab the information that we "build" into the files.
#
date = ARGUMENTS.get('DATE')
if not date:
date = time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(time.time()))
# Datestring for debian
# Should look like: Mon, 03 Nov 2016 13:37:42 -0700
deb_date = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
developer = ARGUMENTS.get('DEVELOPER')
if not developer:
for variable in ['USERNAME', 'LOGNAME', 'USER']:
developer = os.environ.get(variable)
if developer:
break
build_system = ARGUMENTS.get('BUILD_SYSTEM')
if not build_system:
import socket
build_system = socket.gethostname().split('.')[0]
version = ARGUMENTS.get('VERSION', '')
if not version:
version = default_version
git_status_lines = []
if git:
cmd = "%s status 2> /dev/null" % git
git_status_lines = os.popen(cmd, "r").readlines()
revision = ARGUMENTS.get('REVISION', '')
def generate_build_id(revision):
return revision
if not revision and git:
git_hash = os.popen("%s rev-parse HEAD 2> /dev/null" % git, "r").read().strip()
def generate_build_id(revision):
result = git_hash
if [l for l in git_status_lines if 'modified' in l]:
result = result + '[MODIFIED]'
return result
revision = git_hash
checkpoint = ARGUMENTS.get('CHECKPOINT', '')
if checkpoint:
if checkpoint == 'd':
import time
checkpoint = time.strftime('%Y%m%d', time.localtime(time.time()))
elif checkpoint == 'r':
checkpoint = 'r' + revision
version = version + '.beta.' + checkpoint
build_id = ARGUMENTS.get('BUILD_ID')
if build_id is None:
if revision:
build_id = generate_build_id(revision)
else:
build_id = ''
import os.path
import distutils.command
no_winpack_templates = not os.path.exists(os.path.join(os.path.split(distutils.command.__file__)[0],'wininst-9.0.exe'))
skip_win_packages = ARGUMENTS.get('SKIP_WIN_PACKAGES',False) or no_winpack_templates
if sys.version_info[0] > 2:
# TODO: Resolve this issue. Currently fails when run on windows with
# File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/command/bdist_wininst.py", line 262, in create_exe
# cfgdata = cfgdata.encode("mbcs")
# LookupError: unknown encoding: mbcs
print("Temporary PY3: Skipping windows package builds")
skip_win_packages = True
if skip_win_packages:
print("Skipping the build of Windows packages...")
python_ver = sys.version[0:3]
#
# Adding some paths to sys.path, this is mainly needed
# for the doc toolchain.
#
addpaths = [os.path.abspath(os.path.join(os.getcwd(), 'bin')),
os.path.abspath(os.path.join(os.getcwd(), 'QMTest'))]
for a in addpaths:
if a not in sys.path:
sys.path.append(a)
# Re-exporting LD_LIBRARY_PATH is necessary if the Python version was
# built with the --enable-shared option.
ENV = { 'PATH' : os.environ['PATH'] }
for key in ['LOGNAME', 'PYTHONPATH', 'LD_LIBRARY_PATH']:
if key in os.environ:
ENV[key] = os.environ[key]
build_dir = ARGUMENTS.get('BUILDDIR', 'build')
if not os.path.isabs(build_dir):
build_dir = os.path.normpath(os.path.join(os.getcwd(), build_dir))
command_line_variables = [
("BUILDDIR=", "The directory in which to build the packages. " +
"The default is the './build' subdirectory."),
("BUILD_ID=", "An identifier for the specific build." +
"The default is the Subversion revision number."),
("BUILD_SYSTEM=", "The system on which the packages were built. " +
"The default is whatever hostname is returned " +
"by socket.gethostname()."),
("CHECKPOINT=", "The specific checkpoint release being packaged, " +
"which will be appended to the VERSION string. " +
"A value of CHECKPOINT=d will generate a string " +
"of 'd' plus today's date in the format YYYMMDD. " +
"A value of CHECKPOINT=r will generate a " +
"string of 'r' plus the Subversion revision " +
"number. Any other CHECKPOINT= string will be " +
"used as is. There is no default value."),
("DATE=", "The date string representing when the packaging " +
"build occurred. The default is the day and time " +
"the SConstruct file was invoked, in the format " +
"YYYY/MM/DD HH:MM:SS."),
("DEVELOPER=", "The developer who created the packages. " +
"The default is the first set environment " +
"variable from the list $USERNAME, $LOGNAME, $USER."),
("REVISION=", "The revision number of the source being built. " +
"The default is the git hash returned " +
"'git rev-parse HEAD', with an appended string of " +
"'[MODIFIED]' if there are any changes in the " +
"working copy."),
("VERSION=", "The SCons version being packaged. The default " +
"is the hard-coded value '%s' " % default_version +
"from this SConstruct file."),
("SKIP_WIN_PACKAGES=", "If set, skip building win32 and win64 packages."),
]
Default('.', build_dir)
packaging_flavors = [
('deb', "A .deb package. (This is currently not supported.)"),
('rpm', "A RedHat Package Manager file."),
('tar-gz', "The normal .tar.gz file for end-user installation."),
('src-tar-gz', "A .tar.gz file containing all the source " +
"(including tests and documentation)."),
('local-tar-gz', "A .tar.gz file for dropping into other software " +
"for local use."),
('zip', "The normal .zip file for end-user installation."),
('src-zip', "A .zip file containing all the source " +
"(including tests and documentation)."),
('local-zip', "A .zip file for dropping into other software " +
"for local use."),
]
test_deb_dir = os.path.join(build_dir, "test-deb")
test_rpm_dir = os.path.join(build_dir, "test-rpm")
test_tar_gz_dir = os.path.join(build_dir, "test-tar-gz")
test_src_tar_gz_dir = os.path.join(build_dir, "test-src-tar-gz")
test_local_tar_gz_dir = os.path.join(build_dir, "test-local-tar-gz")
test_zip_dir = os.path.join(build_dir, "test-zip")
test_src_zip_dir = os.path.join(build_dir, "test-src-zip")
test_local_zip_dir = os.path.join(build_dir, "test-local-zip")
unpack_tar_gz_dir = os.path.join(build_dir, "unpack-tar-gz")
unpack_zip_dir = os.path.join(build_dir, "unpack-zip")
if is_windows():
tar_hflag = ''
python_project_subinst_dir = os.path.join("Lib", "site-packages", project)
project_script_subinst_dir = 'Scripts'
else:
tar_hflag = 'h'
python_project_subinst_dir = os.path.join("lib", project)
project_script_subinst_dir = 'bin'
import textwrap
indent_fmt = ' %-26s '
Help("""\
The following aliases build packages of various types, and unpack the
contents into build/test-$PACKAGE subdirectories, which can be used by the
runtest.py -p option to run tests against what's been actually packaged:
""")
aliases = sorted(packaging_flavors + [('doc', 'The SCons documentation.')])
for alias, help_text in aliases:
tw = textwrap.TextWrapper(
width = 78,
initial_indent = indent_fmt % alias,
subsequent_indent = indent_fmt % '' + ' ',
)
Help(tw.fill(help_text) + '\n')
Help("""
The following command-line variables can be set:
""")
for variable, help_text in command_line_variables:
tw = textwrap.TextWrapper(
width = 78,
initial_indent = indent_fmt % variable,
subsequent_indent = indent_fmt % '' + ' ',
)
Help(tw.fill(help_text) + '\n')
zcat = 'gzip -d -c'
#
# Figure out if we can handle .zip files.
#
zipit = None
unzipit = None
try:
import zipfile
def zipit(env, target, source):
print("Zipping %s:" % str(target[0]))
def visit(arg, dirname, filenames):
for filename in filenames:
path = os.path.join(dirname, filename)
if os.path.isfile(path):
arg.write(path)
# default ZipFile compression is ZIP_STORED
zf = zipfile.ZipFile(str(target[0]), 'w', compression=zipfile.ZIP_DEFLATED)
olddir = os.getcwd()
os.chdir(env['CD'])
try:
for dirname, dirnames, filenames in os.walk(env['PSV']):
visit(zf, dirname, filenames)
finally:
os.chdir(olddir)
zf.close()
def unzipit(env, target, source):
print("Unzipping %s:" % str(source[0]))
zf = zipfile.ZipFile(str(source[0]), 'r')
for name in zf.namelist():
dest = os.path.join(env['UNPACK_ZIP_DIR'], name)
dir = os.path.dirname(dest)
try:
os.makedirs(dir)
except:
pass
print(dest,name)
# if the file exists, then delete it before writing
# to it so that we don't end up trying to write to a symlink:
if os.path.isfile(dest) or os.path.islink(dest):
os.unlink(dest)
if not os.path.isdir(dest):
with open(dest, 'wb') as fp:
fp.write(zf.read(name))
except ImportError:
if unzip and zip:
zipit = "cd $CD && $ZIP $ZIPFLAGS $( ${TARGET.abspath} $) $PSV"
unzipit = "$UNZIP $UNZIPFLAGS $SOURCES"
def SCons_revision(target, source, env):
"""Interpolate specific values from the environment into a file.
This is used to copy files into a tree that gets packaged up
into the source file package.
"""
t = str(target[0])
s = source[0].rstr()
try:
with open(s, 'r') as fp:
contents = fp.read()
# Note: We construct the __*__ substitution strings here
# so that they don't get replaced when this file gets
# copied into the tree for packaging.
contents = contents.replace('__BUILD' + '__', env['BUILD'])
contents = contents.replace('__BUILDSYS' + '__', env['BUILDSYS'])
contents = contents.replace('__COPYRIGHT' + '__', env['COPYRIGHT'])
contents = contents.replace('__DATE' + '__', env['DATE'])
contents = contents.replace('__DEB_DATE' + '__', env['DEB_DATE'])
contents = contents.replace('__DEVELOPER' + '__', env['DEVELOPER'])
contents = contents.replace('__FILE' + '__', str(source[0]).replace('\\', '/'))
contents = contents.replace('__MONTH_YEAR'+ '__', env['MONTH_YEAR'])
contents = contents.replace('__REVISION' + '__', env['REVISION'])
contents = contents.replace('__VERSION' + '__', env['VERSION'])
contents = contents.replace('__NULL' + '__', '')
open(t, 'w').write(contents)
except UnicodeDecodeError as e:
print("Error decoding file:%s just copying no revision edit")
with open(s, 'rb') as fp:
contents = fp.read()
open(t, 'wb').write(contents)
os.chmod(t, os.stat(s)[0])
revaction = SCons_revision
revbuilder = Builder(action = Action(SCons_revision,
varlist=['COPYRIGHT', 'VERSION']))
def soelim(target, source, env):
"""
Interpolate files included in [gnt]roff source files using the
.so directive.
This behaves somewhat like the soelim(1) wrapper around groff, but
makes us independent of whether the actual underlying implementation
includes an soelim() command or the corresponding command-line option
to groff(1). The key behavioral difference is that this doesn't
recursively include .so files from the include file. Not yet, anyway.
"""
t = str(target[0])
s = str(source[0])
dir, f = os.path.split(s)
tfp = open(t, 'w')
sfp = open(s, 'r')
for line in sfp.readlines():
if line[:4] in ['.so ', "'so "]:
sofile = os.path.join(dir, line[4:-1])
tfp.write(open(sofile, 'r').read())
else:
tfp.write(line)
sfp.close()
tfp.close()
def soscan(node, env, path):
c = node.get_text_contents()
return re.compile(r"^[\.']so\s+(\S+)", re.M).findall(c)
soelimbuilder = Builder(action = Action(soelim),
source_scanner = Scanner(soscan))
# When copying local files from a Repository (Aegis),
# just make copies, don't symlink them.
SetOption('duplicate', 'copy')
env = Environment(
ENV = ENV,
BUILD = build_id,
BUILDDIR = build_dir,
BUILDSYS = build_system,
COPYRIGHT = copyright,
DATE = date,
DEB_DATE = deb_date,
DEVELOPER = developer,
DISTDIR = os.path.join(build_dir, 'dist'),
MONTH_YEAR = month_year,
REVISION = revision,
VERSION = version,
TAR_HFLAG = tar_hflag,
ZIP = zip,
ZIPFLAGS = '-r',
UNZIP = unzip,
UNZIPFLAGS = '-o -d $UNPACK_ZIP_DIR',
ZCAT = zcat,
RPMBUILD = rpmbuild,
RPM2CPIO = 'rpm2cpio',
TEST_DEB_DIR = test_deb_dir,
TEST_RPM_DIR = test_rpm_dir,
TEST_SRC_TAR_GZ_DIR = test_src_tar_gz_dir,
TEST_SRC_ZIP_DIR = test_src_zip_dir,
TEST_TAR_GZ_DIR = test_tar_gz_dir,
TEST_ZIP_DIR = test_zip_dir,
UNPACK_TAR_GZ_DIR = unpack_tar_gz_dir,
UNPACK_ZIP_DIR = unpack_zip_dir,
BUILDERS = { 'SCons_revision' : revbuilder,
'SOElim' : soelimbuilder },
PYTHON = '"%s"' % sys.executable,
PYTHONFLAGS = '-tt',
)
Version_values = [Value(version), Value(build_id)]
#
# Define SCons packages.
#
# In the original, more complicated packaging scheme, we were going
# to have separate packages for:
#
# python-scons only the build engine
# scons-script only the script
# scons the script plus the build engine
#
# We're now only delivering a single "scons" package, but this is still
# "built" as two sub-packages (the build engine and the script), so
# the definitions remain here, even though we're not using them for
# separate packages.
#
from distutils.sysconfig import get_python_lib;
python_scons = {
'pkg' : 'python-' + project,
'src_subdir' : 'engine',
'inst_subdir' : get_python_lib(),
'rpm_dir' : '/usr/lib/scons',
'debian_deps' : [
'debian/changelog',
'debian/compat',
'debian/control',
'debian/copyright',
'debian/dirs',
'debian/docs',
'debian/postinst',
'debian/prerm',
'debian/rules',
],
'files' : [ 'LICENSE.txt',
'README.txt',
'setup.cfg',
'setup.py',
],
'filemap' : {
'LICENSE.txt' : '../LICENSE.txt'
},
'buildermap' : {},
'extra_rpm_files' : [],
'explicit_deps' : {
'SCons/__init__.py' : Version_values,
},
}
# Figure out the name of a .egg-info file that might be generated
# as part of the RPM package. There are two complicating factors.
#
# First, the RPM spec file we generate will just execute "python", not
# necessarily the one in sys.executable. If *that* version of python has
# a distutils that knows about Python eggs, then setup.py will generate a
# .egg-info file, so we have to execute any distutils logic in a subshell.
#
# Second, we can't just have the subshell check for the existence of the
# distutils.command.install_egg_info module and generate the expected
# file name by hand, the way we used to, because different systems can
# have slightly different .egg-info naming conventions. (Specifically,
# Ubuntu overrides the default behavior to remove the Python version
# string from the .egg-info file name.) The right way to do this is to
# actually call into the install_egg_info() class to have it generate
# the expected name for us.
#
# This is all complicated enough that we do it by writing an in-line
# script to a temporary file and then feeding it to a separate invocation
# of "python" to tell us the actual name of the generated .egg-info file.
print_egg_info_name = """
try:
from distutils.dist import Distribution
from distutils.command.install_egg_info import install_egg_info
except ImportError:
pass
else:
dist = Distribution({'name' : "scons", 'version' : '%s'})
i = install_egg_info(dist)
i.finalize_options()
import os.path
print(os.path.split(i.outputs[0])[1])
""" % version
try:
fd, tfname = tempfile.mkstemp()
tfp = os.fdopen(fd, "w")
tfp.write(print_egg_info_name)
tfp.close()
egg_info_file = os.popen("python %s" % tfname).read()[:-1]
if egg_info_file:
python_scons['extra_rpm_files'].append(egg_info_file)
finally:
try:
os.unlink(tfname)
except EnvironmentError:
pass
scons_script = {
'pkg' : project + '-script',
'src_subdir' : 'script',
'inst_subdir' : 'bin',
'rpm_dir' : '/usr/bin',
'debian_deps' : [
'debian/changelog',
'debian/compat',
'debian/control',
'debian/copyright',
'debian/dirs',
'debian/docs',
'debian/postinst',
'debian/prerm',
'debian/rules',
],
'files' : [
'LICENSE.txt',
'README.txt',
'setup.cfg',
'setup.py',
],
'filemap' : {
'LICENSE.txt' : '../LICENSE.txt',
'scons' : 'scons.py',
'sconsign' : 'sconsign.py',
'scons-time' : 'scons-time.py',
'scons-configure-cache' : 'scons-configure-cache.py',
},
'buildermap' : {},
'extra_rpm_files' : [
'scons-' + version,
'sconsign-' + version,
'scons-time-' + version,
'scons-configure-cache-' + version,
],
'explicit_deps' : {
'scons' : Version_values,
'sconsign' : Version_values,
},
}
scons = {
'pkg' : project,
'debian_deps' : [
'debian/changelog',
'debian/compat',
'debian/control',
'debian/copyright',
'debian/dirs',
'debian/docs',
'debian/postinst',
'debian/prerm',
'debian/rules',
],
'files' : [
'CHANGES.txt',
'LICENSE.txt',
'README.txt',
'RELEASE.txt',
'scons.1',
'sconsign.1',
'scons-time.1',
'script/scons.bat',
#'script/scons-post-install.py',
'setup.cfg',
'setup.py',
],
'filemap' : {
'scons.1' : '$BUILDDIR/doc/man/scons.1',
'sconsign.1' : '$BUILDDIR/doc/man/sconsign.1',
'scons-time.1' : '$BUILDDIR/doc/man/scons-time.1',
},
'buildermap' : {
'scons.1' : env.SOElim,
'sconsign.1' : env.SOElim,
'scons-time.1' : env.SOElim,
},
'subpkgs' : [ python_scons, scons_script ],
'subinst_dirs' : {
'python-' + project : python_project_subinst_dir,
project + '-script' : project_script_subinst_dir,
},
}
scripts = ['scons', 'sconsign', 'scons-time', 'scons-configure-cache']
src_deps = []
src_files = []
for p in [ scons ]:
#
# Initialize variables with the right directories for this package.
#
pkg = p['pkg']
pkg_version = "%s-%s" % (pkg, version)
src = 'src'
if 'src_subdir' in p:
src = os.path.join(src, p['src_subdir'])
build = os.path.join(build_dir, pkg)
tar_gz = os.path.join(build, 'dist', "%s.tar.gz" % pkg_version)
platform_tar_gz = os.path.join(build,
'dist',
"%s.%s.tar.gz" % (pkg_version, platform))
zip = os.path.join(build, 'dist', "%s.zip" % pkg_version)
platform_zip = os.path.join(build,
'dist',
"%s.%s.zip" % (pkg_version, platform))
#
# Update the environment with the relevant information
# for this package.
#
# We can get away with calling setup.py using a directory path
# like this because we put a preamble in it that will chdir()
# to the directory in which setup.py exists.
#
setup_py = os.path.join(build, 'setup.py')
env.Replace(PKG = pkg,
PKG_VERSION = pkg_version,
SETUP_PY = '"%s"' % setup_py)
Local(setup_py)
#
# Read up the list of source files from our MANIFEST.in.
# This list should *not* include LICENSE.txt, MANIFEST,
# README.txt, or setup.py. Make a copy of the list for the
# destination files.
#
manifest_in = File(os.path.join(src, 'MANIFEST.in')).rstr()
src_files = bootstrap.parseManifestLines(src, open(manifest_in).readlines())
raw_files = src_files[:]
dst_files = src_files[:]
rpm_files = []
MANIFEST_in_list = []
if 'subpkgs' in p:
#
# This package includes some sub-packages. Read up their
# MANIFEST.in files, and add them to our source and destination
# file lists, modifying them as appropriate to add the
# specified subdirs.
#
for sp in p['subpkgs']:
ssubdir = sp['src_subdir']
isubdir = p['subinst_dirs'][sp['pkg']]
MANIFEST_in = File(os.path.join(src, ssubdir, 'MANIFEST.in')).rstr()
MANIFEST_in_list.append(MANIFEST_in)
files = bootstrap.parseManifestLines(os.path.join(src, ssubdir), open(MANIFEST_in).readlines())
raw_files.extend(files)
src_files.extend([os.path.join(ssubdir, x) for x in files])
for f in files:
r = os.path.join(sp['rpm_dir'], f)
rpm_files.append(r)
if f[-3:] == ".py":
rpm_files.append(r + 'c')
for f in sp.get('extra_rpm_files', []):
r = os.path.join(sp['rpm_dir'], f)
rpm_files.append(r)
files = [os.path.join(isubdir, x) for x in files]
dst_files.extend(files)
for k, f in sp['filemap'].items():
if f:
k = os.path.join(ssubdir, k)
p['filemap'][k] = os.path.join(ssubdir, f)
for f, deps in sp['explicit_deps'].items():
f = os.path.join(build, ssubdir, f)
env.Depends(f, deps)
#
# Now that we have the "normal" source files, add those files
# that are standard for each distribution. Note that we don't
# add these to dst_files, because they don't get installed.
# And we still have the MANIFEST to add.
#
src_files.extend(p['files'])
#
# Now run everything in src_file through the sed command we
# concocted to expand __FILE__, __VERSION__, etc.
#
for b in src_files:
s = p['filemap'].get(b, b)
if not s[0] == '$' and not os.path.isabs(s):
s = os.path.join(src, s)
builder = p['buildermap'].get(b, env.SCons_revision)
x = builder(os.path.join(build, b), s)
Local(x)
#
# NOW, finally, we can create the MANIFEST, which we do
# by having Python spit out the contents of the src_files
# array we've carefully created. After we've added
# MANIFEST itself to the array, of course.
#
src_files.append("MANIFEST")
MANIFEST_in_list.append(os.path.join(src, 'MANIFEST.in'))
def write_src_files(target, source, **kw):
global src_files
src_files.sort()
f = open(str(target[0]), 'w')
for file in src_files:
f.write(file + "\n")
f.close()
return 0
env.Command(os.path.join(build, 'MANIFEST'),
MANIFEST_in_list,
write_src_files)
#
# Now go through and arrange to create whatever packages we can.
#
build_src_files = [os.path.join(build, x) for x in src_files]
Local(*build_src_files)
distutils_formats = []
distutils_targets = []
if not skip_win_packages:
win64_exe = os.path.join(build, 'dist', "%s.win-amd64.exe" % pkg_version)
win32_exe = os.path.join(build, 'dist', "%s.win32.exe" % pkg_version)
distutils_targets.extend([ win32_exe , win64_exe ])
dist_distutils_targets = []
for target in distutils_targets:
dist_target = env.Install('$DISTDIR', target)
AddPostAction(dist_target, Chmod(dist_target, 0o644))
dist_distutils_targets += dist_target
if not gzip:
print("gzip not found in %s; skipping .tar.gz package for %s." % (os.environ['PATH'], pkg))
else:
distutils_formats.append('gztar')
src_deps.append(tar_gz)
distutils_targets.extend([ tar_gz, platform_tar_gz ])
dist_tar_gz = env.Install('$DISTDIR', tar_gz)
dist_platform_tar_gz = env.Install('$DISTDIR', platform_tar_gz)
Local(dist_tar_gz, dist_platform_tar_gz)
AddPostAction(dist_tar_gz, Chmod(dist_tar_gz, 0o644))
AddPostAction(dist_platform_tar_gz, Chmod(dist_platform_tar_gz, 0o644))
#
# Unpack the tar.gz archive created by the distutils into
# build/unpack-tar-gz/scons-{version}.
#
# We'd like to replace the last three lines with the following:
#
# tar zxf $SOURCES -C $UNPACK_TAR_GZ_DIR
#
# but that gives heartburn to Cygwin's tar, so work around it
# with separate zcat-tar-rm commands.
#
unpack_tar_gz_files = [os.path.join(unpack_tar_gz_dir, pkg_version, x)
for x in src_files]
env.Command(unpack_tar_gz_files, dist_tar_gz, [
Delete(os.path.join(unpack_tar_gz_dir, pkg_version)),
"$ZCAT $SOURCES > .temp",
"tar xf .temp -C $UNPACK_TAR_GZ_DIR",
Delete(".temp"),
])
#
# Run setup.py in the unpacked subdirectory to "install" everything
# into our build/test subdirectory. The runtest.py script will set
# PYTHONPATH so that the tests only look under build/test-{package},
# and under QMTest (for the testing modules TestCmd.py, TestSCons.py,
# etc.). This makes sure that our tests pass with what
# we really packaged, not because of something hanging around in
# the development directory.
#
# We can get away with calling setup.py using a directory path
# like this because we put a preamble in it that will chdir()
# to the directory in which setup.py exists.
#
dfiles = [os.path.join(test_tar_gz_dir, x) for x in dst_files]
env.Command(dfiles, unpack_tar_gz_files, [
Delete(os.path.join(unpack_tar_gz_dir, pkg_version, 'build')),
Delete("$TEST_TAR_GZ_DIR"),
'$PYTHON $PYTHONFLAGS "%s" install "--prefix=$TEST_TAR_GZ_DIR" --standalone-lib' % \
os.path.join(unpack_tar_gz_dir, pkg_version, 'setup.py'),
])
#
# Generate portage files for submission to Gentoo Linux.
#
gentoo = os.path.join(build, 'gentoo')
ebuild = os.path.join(gentoo, 'scons-%s.ebuild' % version)
digest = os.path.join(gentoo, 'files', 'digest-scons-%s' % version)
env.Command(ebuild, os.path.join('gentoo', 'scons.ebuild.in'), SCons_revision)
def Digestify(target, source, env):
import hashlib
src = source[0].rfile()
contents = open(str(src),'rb').read()
m = hashlib.md5()
m.update(contents)
sig = m.hexdigest()
bytes = os.stat(str(src))[6]
open(str(target[0]), 'w').write("MD5 %s %s %d\n" % (sig,
src.name,
bytes))
env.Command(digest, tar_gz, Digestify)
if not zipit:
print("zip not found; skipping .zip package for %s." % pkg)
else:
distutils_formats.append('zip')
src_deps.append(zip)
distutils_targets.extend([ zip, platform_zip ])
dist_zip = env.Install('$DISTDIR', zip)
dist_platform_zip = env.Install('$DISTDIR', platform_zip)
Local(dist_zip, dist_platform_zip)
AddPostAction(dist_zip, Chmod(dist_zip, 0o644))
AddPostAction(dist_platform_zip, Chmod(dist_platform_zip, 0o644))
#
# Unpack the zip archive created by the distutils into
# build/unpack-zip/scons-{version}.
#
unpack_zip_files = [os.path.join(unpack_zip_dir, pkg_version, x)
for x in src_files]
env.Command(unpack_zip_files, dist_zip, [
Delete(os.path.join(unpack_zip_dir, pkg_version)),
unzipit,
])
#
# Run setup.py in the unpacked subdirectory to "install" everything
# into our build/test subdirectory. The runtest.py script will set
# PYTHONPATH so that the tests only look under build/test-{package},
# and under QMTest (for the testing modules TestCmd.py, TestSCons.py,
# etc.). This makes sure that our tests pass with what
# we really packaged, not because of something hanging around in
# the development directory.
#
# We can get away with calling setup.py using a directory path
# like this because we put a preamble in it that will chdir()
# to the directory in which setup.py exists.
#
dfiles = [os.path.join(test_zip_dir, x) for x in dst_files]
env.Command(dfiles, unpack_zip_files, [
Delete(os.path.join(unpack_zip_dir, pkg_version, 'build')),
Delete("$TEST_ZIP_DIR"),
'$PYTHON $PYTHONFLAGS "%s" install "--prefix=$TEST_ZIP_DIR" --standalone-lib' % \
os.path.join(unpack_zip_dir, pkg_version, 'setup.py'),
])
if not rpmbuild:
msg = "@echo \"Warning: Can not build 'rpm': no rpmbuild utility found\""
AlwaysBuild(Alias('rpm', [], msg))
else:
topdir = os.path.join(build, 'build',
'bdist.' + platform, 'rpm')
buildroot = os.path.join(build_dir, 'rpm-buildroot')