Merge pull request #4383 from mwichmann/test/runtest-step
[scons.git] / site_scons / scons_local_package.py
bloba9f391b980f90ddc0af3c1ce25c7bf369dbe1238
1 # SPDX-License-Identifier: MIT
3 # Copyright The SCons Foundation
5 """Build the scons-local packages."""
7 from glob import glob
8 import os.path
9 from zip_utils import zipit, zipappit
10 from Utilities import is_windows
13 def get_local_package_file_list():
14 """Get list of all files which should be included in scons-local package"""
16 s_files = glob("SCons/**", recursive=True)
18 # import pdb; pdb.set_trace()
20 non_test = [f for f in s_files if "Tests.py" not in f]
21 non_test_non_doc = [
22 f for f in non_test if '.xml' not in f or "SCons/Tool/docbook" in f
24 filtered_list = [f for f in non_test_non_doc if 'pyc' not in f]
25 filtered_list = [f for f in filtered_list if '__pycache__' not in f]
26 filtered_list = [f for f in filtered_list if not os.path.isdir(f)]
28 return filtered_list
31 def install_local_package_files(env):
33 all_local_installed = []
34 files = get_local_package_file_list()
35 target_dir = '#/build/scons-local/scons-local-$VERSION'
36 for f in files:
37 all_local_installed.extend(
38 env.Install(os.path.join(target_dir, os.path.dirname(f)), f)
41 basedir_files = [
42 'scripts/scons.bat',
43 'scripts/scons.py',
44 'scripts/scons-configure-cache.py',
45 'scripts/sconsign.py',
46 'bin/scons-time.py',
48 for bf in basedir_files:
49 fn = os.path.basename(bf)
50 all_local_installed.append(
51 env.SCons_revision(f'#/build/scons-local/{fn}', bf)
54 # Now copy manpages into scons-local package
55 built_manpage_files = env.Glob('build/doc/man/*.1')
56 for bmp in built_manpage_files:
57 fn = os.path.basename(str(bmp))
58 all_local_installed.append(
59 env.SCons_revision(f'#/build/scons-local/{fn}', bmp)
62 rename_files = [
63 ('scons-${VERSION}.bat', 'scripts/scons.bat'),
64 ('scons-README', 'README-local'),
65 ('scons-LICENSE', 'LICENSE-local'),
67 for t, f in rename_files:
68 target_file = f"#/build/scons-local/{t}"
69 all_local_installed.append(env.SCons_revision(target_file, f))
71 return all_local_installed
74 def create_local_packages(env):
75 [env.Tool(x) for x in ['packaging', 'filesystem', 'zip']]
76 installed_files = install_local_package_files(env)
78 build_local_dir = 'build/scons-local'
79 local_zip = env.Command(
80 '#build/dist/scons-local-${VERSION}.zip',
81 installed_files,
82 zipit,
83 CD=build_local_dir,
84 PSV='.',
86 env.Alias("local-zip", local_zip)
88 # We need to descend into the versioned directory for zipapp,
89 # but we don't know the version. env.Glob lets us expand that.
90 # The action isn't going to use the sources, but including
91 # them makes sure SCons has populated the dir we're going to zip.
92 app_dir = env.Glob(f"{build_local_dir}/scons-local-*")[0]
93 zipapp = env.Command(
94 target='#build/dist/scons-local-${VERSION}.pyz',
95 source=installed_files,
96 action=zipappit,
97 CD=app_dir,
98 PSV='.',
99 entry='SCons.Script.Main:main',
101 env.Alias("local-zipapp", zipapp)
103 if is_windows():
104 # avoid problem with tar interpreting c:/ as a remote machine
105 tar_cargs = '-cz --force-local -f'
106 else:
107 tar_cargs = '-czf'
109 local_tar = env.Command(
110 '#build/dist/scons-local-${VERSION}.tar.gz',
111 installed_files,
112 "cd %s && tar %s $( ${TARGET.abspath} $) *" % (build_local_dir, tar_cargs),
114 env.Alias("local-tar-gz", local_tar)
116 print(f"Package:{local_zip}")
117 print(f"Zipapp:{zipapp}")