Skip to content

Commit 84842be

Browse files
authored
Merge pull request #4741 from jcbrill/jbrill-wintest-tar
Testing: Update the packaging tar bz2 and xz tests on windows
2 parents c67193f + 188875b commit 84842be

7 files changed

Lines changed: 205 additions & 48 deletions

File tree

CHANGES.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
7474
- Testing: Increase the default timeout from 20 seconds to 60
7575
seconds in the testing framework wait_for method. At present, the
7676
wait_for method is only used for the interactive tests.
77+
- GitHub: Remove the packaging tar xz test from the windows ci skip file.
78+
- Testing: Update the packaging tar bz2 and xz tests on on Windows.
79+
Detect if the tar bz2 and xz formats are supported for the windows
80+
system tar executable using the reported version string. The packaging
81+
tar bz2 and xz tests should be skipped on Windows 10 and GitHub
82+
windows-2022. The packaging tar bz2 and xz tests should be run on
83+
Windows 11 and GitHub windows-2025.
7784

7885
From Edward Peek:
7986
- Fix the variant dir component being missing from generated source file

RELEASE.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ DEVELOPMENT
146146

147147
- GitHub: Enable the interactive tests on windows.
148148

149+
- GitHub: Enable the packaging tar xz test on windows.
150+
149151
- GitHub: Exclude two ninja tests that consistently fail on MacOS in
150152
the experimental tests workflow.
151153

@@ -165,6 +167,11 @@ DEVELOPMENT
165167
in the testing framework wait_for method. The timeout was increased
166168
during isolated experiments of the interactive tests on windows.
167169

170+
- Testing: Update the packaging tar bz2 and xz tests on on Windows.
171+
The packaging tar bz2 and xz tests should be skipped on Windows 10
172+
and GitHub windows-2022. The packaging tar bz2 and xz tests should
173+
be run on Windows 11 and GitHub windows-2025.
174+
168175
- Ninja: Increase the number of generated source files in the
169176
iterative speedup test from 200 to 250. Increasing the workload
170177
should reduce the likelihood that the ninja tests are slower.

test/packaging/tar/bz2_packaging.py

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,17 @@
2929
- create a tar package from the specified files
3030
"""
3131

32-
import TestSCons
32+
import TestSConsTar
3333

34-
import os
35-
import os.path
36-
import sys
37-
38-
python = TestSCons.python
39-
40-
test = TestSCons.TestSCons()
34+
test = TestSConsTar.TestSConsTar()
4135

4236
tar = test.detect('TAR', 'tar')
4337
if not tar:
4438
test.skip_test('tar not found, skipping test\n')
4539

46-
bz2 = test.where_is('bzip2')
47-
48-
if sys.platform == 'win32':
49-
# windows 10 causes fresh problems by supplying a tar, not bzip2
50-
# but if git is installed, there's a bzip2 there, but can't be used
51-
if not bz2:
52-
test.skip_test('tar found, but helper bzip2 not found, skipping test\n')
53-
bz2 = os.path.splitdrive(bz2)[1]
54-
tar = os.path.splitdrive(test.where_is('tar'))[1]
55-
if tar[:8] != bz2[:8]: # catch one in \WINDOWS, one not
56-
test.skip_test('tar found, but usable bzip2 not, skipping test\n')
57-
58-
bz2_path = os.path.dirname(bz2)
59-
40+
is_wintar, is_bz2_supported = TestSConsTar.windows_system_tar_bz2(tar)
41+
if is_wintar and not is_bz2_supported:
42+
test.skip_test('windows tar found; bz2 not supported, skipping test\n')
6043

6144
test.subdir('src')
6245

@@ -71,14 +54,11 @@
7154
Program( 'src/main.c' )
7255
env=Environment(tools=['packaging', 'filesystem', 'tar'])
7356
74-
# needed for windows to prevent picking up windows tar and thinking non-windows bzip2 would work.
75-
env.PrependENVPath('PATH', r'%s')
76-
7757
env.Package( PACKAGETYPE = 'src_tarbz2',
7858
target = 'src.tar.bz2',
7959
PACKAGEROOT = 'test',
8060
source = [ 'src/main.c', 'SConstruct' ] )
81-
"""%bz2_path)
61+
""")
8262

8363
test.run(arguments='', stderr=None)
8464

test/packaging/tar/gz.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,18 @@
2929
- create a targz package containing the specified files.
3030
"""
3131

32-
import TestSCons
32+
import TestSConsTar
3333

34-
python = TestSCons.python
35-
36-
test = TestSCons.TestSCons()
34+
test = TestSConsTar.TestSConsTar()
3735

3836
tar = test.detect('TAR', 'tar')
3937
if not tar:
4038
test.skip_test('tar not found, skipping test\n')
4139

40+
is_wintar, is_gz_supported = TestSConsTar.windows_system_tar_gz(tar)
41+
if is_wintar and not is_gz_supported:
42+
test.skip_test('windows tar found; gz not supported, skipping test\n')
43+
4244
test.subdir('src')
4345

4446
test.write(['src', 'main.c'], r"""

test/packaging/tar/xz_packaging.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,16 @@
2828
This tests the SRC xz packager, which does the following:
2929
- create a tar package from the specified files
3030
"""
31-
import os.path
32-
import TestSCons
31+
import TestSConsTar
3332

34-
python = TestSCons.python
35-
36-
test = TestSCons.TestSCons()
33+
test = TestSConsTar.TestSConsTar()
3734
tar = test.detect('TAR', 'tar')
3835
if not tar:
3936
test.skip_test('tar not found, skipping test\n')
4037

41-
# Windows 10 now supplies tar, but doesn't support xz compression
42-
# assume it's just okay to check for an xz command, because don't
43-
# want to probe the command itself to see what it supports
44-
xz = test.where_is('xz')
45-
if not xz:
46-
test.skip_test('tar found, but helper xz not found, skipping test\n')
47-
48-
xz_path = os.path.dirname(xz)
38+
is_wintar, is_xz_supported = TestSConsTar.windows_system_tar_xz(tar)
39+
if is_wintar and not is_xz_supported:
40+
test.skip_test('windows tar found; xz not supported, skipping test\n')
4941

5042
test.subdir('src')
5143

@@ -60,14 +52,11 @@
6052
Program( 'src/main.c' )
6153
env=Environment(tools=['packaging', 'filesystem', 'tar'])
6254
63-
# needed for windows to prevent picking up windows tar and thinking non-windows bzip2 would work.
64-
env.PrependENVPath('PATH', r'%s')
65-
6655
env.Package( PACKAGETYPE = 'src_tarxz',
6756
target = 'src.tar.xz',
6857
PACKAGEROOT = 'test',
6958
source = [ 'src/main.c', 'SConstruct' ] )
70-
"""%xz_path)
59+
""")
7160

7261
test.run(arguments='', stderr=None)
7362

testing/ci/windows_ci_skip.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ test/CPPDEFINES/pkg-config.py
33
test/packaging/msi/explicit-target.py
44
test/packaging/msi/file-placement.py
55
test/packaging/msi/package.py
6-
test/packaging/tar/xz_packaging.py
76
test/scons-time/run/config/python.py
87
test/scons-time/run/option/python.py
98
test/sconsign/script/no-SConsignFile.py

testing/framework/TestSConsTar.py

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# MIT License
2+
#
3+
# Copyright The SCons Foundation
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining
6+
# a copy of this software and associated documentation files (the
7+
# "Software"), to deal in the Software without restriction, including
8+
# without limitation the rights to use, copy, modify, merge, publish,
9+
# distribute, sublicense, and/or sell copies of the Software, and to
10+
# permit persons to whom the Software is furnished to do so, subject to
11+
# the following conditions:
12+
#
13+
# The above copyright notice and this permission notice shall be included
14+
# in all copies or substantial portions of the Software.
15+
#
16+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17+
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
24+
"""
25+
A testing framework for the SCons software construction tool.
26+
27+
A TestSConsTar environment object is created via the usual invocation:
28+
29+
test = TestSConsTar()
30+
31+
TestSConsTar is a subsclass of TestSCons, which is in turn a subclass
32+
of TestCommon, which is in turn is a subclass of TestCmd), and hence
33+
has available all of the methods and attributes from those classes,
34+
as well as any overridden or additional methods or attributes defined
35+
in this subclass.
36+
"""
37+
38+
import os
39+
import os.path
40+
import subprocess
41+
import sys
42+
43+
from TestSCons import *
44+
from TestSCons import __all__
45+
46+
__all__.extend([
47+
'TestSConsTar',
48+
'windows_system_tar_gz',
49+
'windows_system_tar_bz2',
50+
'windows_system_tar_xz',
51+
'windows_system_tar_lzma',
52+
])
53+
54+
if sys.platform == 'win32':
55+
56+
# Windows 10 and later supplies windows/system32/tar.exe (bsdtar).
57+
# Not all versions support all compression types. Check the version
58+
# string for library support.
59+
60+
# windows tar.exe:
61+
# %systemroot%/system32/tar.exe
62+
63+
# tar.exe --version (Windows 10, GH windows-2022):
64+
# bsdtar 3.5.2 - libarchive 3.5.2 zlib/1.2.5.f-ipp
65+
66+
# tar.exe --version (Windows 11):
67+
# bsdtar 3.7.7 - libarchive 3.7.7 zlib/1.2.5.f-ipp liblzma/5.4.3 bz2lib/1.0.8 libzstd/1.5.4
68+
69+
# tar.exe --version (GH windows-2025):
70+
# bsdtar 3.7.7 - libarchive 3.7.7 zlib/1.2.13.1-motley liblzma/5.4.3 bz2lib/1.0.8 libzstd/1.5.5
71+
72+
def _is_windows_system_tar(tar):
73+
74+
if not tar:
75+
return False
76+
77+
tar = os.path.normcase(os.path.abspath(tar))
78+
if not os.path.exists(tar):
79+
return False
80+
81+
if not tar.endswith('tar.exe'):
82+
return False
83+
84+
windir = os.environ.get("SystemRoot")
85+
if not windir:
86+
windir = os.environ.get("windir")
87+
88+
if not windir:
89+
windir = os.path.join(os.environ.get("SystemDrive", "C:") + os.path.sep, "Windows")
90+
91+
windows_tar = os.path.normcase(os.path.abspath(os.path.join(windir, "System32", "tar.exe")))
92+
rval = bool(tar == windows_tar)
93+
94+
return rval
95+
96+
def _windows_system_tar_have_library(tar, libname):
97+
98+
is_wintar = _is_windows_system_tar(tar)
99+
if not is_wintar:
100+
return is_wintar, None
101+
102+
try:
103+
result = subprocess.run([f"{tar}", "--version"], capture_output=True, text=True, check=True)
104+
version_str = result.stdout.strip()
105+
except:
106+
version_str = None
107+
108+
if not version_str:
109+
return is_wintar, None
110+
111+
# print(f"{tar} --version => {version_str!r}")
112+
113+
version_comps = version_str.split()
114+
if len(version_comps) < 5:
115+
return is_wintar, None
116+
117+
for indx, expected in [
118+
(0, "bsdtar"), (2, "-"), (3, "libarchive"),
119+
]:
120+
if version_comps[indx].lower() != expected:
121+
return is_wintar, None
122+
123+
# bsdtar_version = version_comps[1]
124+
# libarchive_version = version_comps[4]
125+
126+
kind = libname + "/"
127+
128+
have_library = False
129+
for component in version_comps[5:]:
130+
if component.lower().startswith(kind):
131+
have_library = True
132+
break
133+
134+
return is_wintar, have_library
135+
136+
def windows_system_tar_gz(tar):
137+
is_wintar, have_library = _windows_system_tar_have_library(tar, 'zlib')
138+
return is_wintar, have_library
139+
140+
def windows_system_tar_bz2(tar):
141+
is_wintar, have_library = _windows_system_tar_have_library(tar, 'bz2lib')
142+
return is_wintar, have_library
143+
144+
def windows_system_tar_xz(tar):
145+
is_wintar, have_library = _windows_system_tar_have_library(tar, 'liblzma')
146+
return is_wintar, have_library
147+
148+
def windows_system_tar_lzma(tar):
149+
is_wintar, have_library = _windows_system_tar_have_library(tar, 'liblzma')
150+
return is_wintar, have_library
151+
152+
else:
153+
154+
def windows_system_tar_gz(tar):
155+
return False, None
156+
157+
def windows_system_tar_bz2(tar):
158+
return False, None
159+
160+
def windows_system_tar_xz(tar):
161+
return False, None
162+
163+
def windows_system_tar_lzma(tar):
164+
return False, None
165+
166+
class TestSConsTar(TestSCons):
167+
pass
168+
169+
# Local Variables:
170+
# tab-width:4
171+
# indent-tabs-mode:nil
172+
# End:
173+
# vim: set expandtab tabstop=4 shiftwidth=4:

0 commit comments

Comments
 (0)