forked from SCons/scons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
234 lines (202 loc) · 7.64 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
# MIT License
#
# Copyright The SCons Foundation
#
# 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.
"""SConstruct file to build scons packages during development/release."""
# See the README.rst file for an overview of how SCons is built and tested.
import os.path
import sys
import textwrap
from time import strftime
copyright_years = strftime('2001 - %Y')
# This gets inserted into the man pages to reflect the month of release.
month_year = strftime('%B %Y')
project = 'scons'
default_version = '4.8.2'
copyright = f"Copyright (c) {copyright_years} The SCons Foundation"
# 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
print(f"git :{git}")
print(f"gzip :{gzip}")
print(f"unzip :{unzip}")
print(f"zip :{zip_path}")
#
# 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(), 'testing/framework')),
]
for a in addpaths:
if a not in sys.path:
sys.path.append(a)
# Use site_scons logic to process command line arguments
command_line = BuildCommandLine(default_version)
command_line.process_command_line_vars()
Default('.', command_line.build_dir)
# Just make copies, don't symlink them.
SetOption('duplicate', 'copy')
packaging_flavors = [
(
'wheel',
"The Python wheel file for pip installations."
),
(
'tar-gz',
"The normal .tar.gz file for end-user installation."
),
(
'local-tar-gz',
"A .tar.gz file for dropping into other software for local use.",
),
(
'zip',
"The normal .zip file for end-user installation."),
(
'local-zip',
"A .zip file for dropping into other software for local use."
),
(
'src-tar-gz',
"A .tar.gz file containing all the source (including tests and documentation).",
),
(
'src-zip',
"A .zip file containing all the source (including tests and documentation).",
),
(
'local-zipapp',
"A .pyz local zipapp. Like local-zip without need to unpack.",
)
]
test_tar_gz_dir = os.path.join(command_line.build_dir, "test-tar-gz")
test_src_tar_gz_dir = os.path.join(command_line.build_dir, "test-src-tar-gz")
test_local_tar_gz_dir = os.path.join(command_line.build_dir, "test-local-tar-gz")
test_zip_dir = os.path.join(command_line.build_dir, "test-zip")
test_src_zip_dir = os.path.join(command_line.build_dir, "test-src-zip")
test_local_zip_dir = os.path.join(command_line.build_dir, "test-local-zip")
unpack_tar_gz_dir = os.path.join(command_line.build_dir, "unpack-tar-gz")
unpack_zip_dir = os.path.join(command_line.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'
indent_fmt = ' %-14s '
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.command_line_variables:
tw = textwrap.TextWrapper(
width=78,
initial_indent=indent_fmt % variable,
subsequent_indent=indent_fmt % '' + ' ',
)
Help(tw.fill(help_text) + '\n')
revaction = SCons_revision
revbuilder = Builder(action=Action(SCons_revision, varlist=['COPYRIGHT', 'VERSION']))
env = Environment(
ENV=command_line.ENV,
BUILD=command_line.build_id,
BUILDDIR=command_line.build_dir,
BUILDSYS=command_line.build_system,
COPYRIGHT_YEARS=copyright_years,
COPYRIGHT=copyright,
DATE=command_line.date,
DEB_DATE=deb_date,
DEVELOPER=command_line.developer,
DISTDIR=os.path.join(command_line.build_dir, 'dist'),
MONTH_YEAR=month_year,
REVISION=command_line.revision,
VERSION=command_line.version,
TAR_HFLAG=tar_hflag,
ZIP=zip_path,
ZIPFLAGS='-r',
UNZIP=unzip,
UNZIPFLAGS='-o -d $UNPACK_ZIP_DIR',
# ZCAT=zcat,
# ZIPID=zipit,
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=f'"{sys.executable}"',
PYTHONFLAGS='-tt',
)
Version_values = [Value(command_line.version), Value(command_line.build_id)]
installed_local_files = create_local_packages(env)
update_init_file(env)
# Documentation
Export('command_line', 'env', 'whereis', 'revaction')
SConscript('doc/SConscript')
# Copy manpages into base dir for inclusion in pypi packages
man_pages = env.Install("#/", Glob("#/build/doc/man/*.1"))
# Build packages for pypi. 'build' makes sdist (tgz) + whl
wheel = env.Command(
target=[
'$DISTDIR/SCons-${VERSION}-py3-none-any.whl',
'$DISTDIR/SCons-${VERSION}.tar.gz',
],
source=['pyproject.toml', 'setup.py', 'SCons/__init__.py'] + man_pages,
action='$PYTHON -m build --outdir $DISTDIR',
)
env.Alias("wheel", wheel[0])
env.Alias("tar-gz", wheel[1])
# TODO: this is built the old way, because "build" doesn't make zipfiles,
# and it deletes its isolated env so we can't just zip that one up.
zip_file = env.Command(
target='$DISTDIR/SCons-${VERSION}.zip',
source=['pyproject.toml', 'setup.py', 'SCons/__init__.py'] + man_pages,
action='$PYTHON setup.py sdist --format=zip',
)
env.Alias("zip", zip_file)
# Now set depends so the above run in a particular order
# NOTE: 'build' with default options builds sdist, then whl from sdist,
# so it's already ordered.
# env.Depends(tgz_file, [zip_file, wheel])
# NOTE: Commenting this out as the manpages are expected to be in the base directory when manually
# running setup.py from the base of the repo.
# NOTE: This used by distro package maintainers.
# env.AddPostAction(tgz_file, Delete(man_pages))
# TODO add auto copyright date to README.rst, LICENSE
# TODO build API DOCS