Skip to content

Commit 6eb40a0

Browse files
committed
build-script: support 4 version components in Clang versions
1 parent 1af0133 commit 6eb40a0

File tree

5 files changed

+42
-10
lines changed

5 files changed

+42
-10
lines changed

utils/build-script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ class BuildScriptInvocation(object):
632632
impl_args += ["--enable-ubsan"]
633633
if args.clang_compiler_version:
634634
impl_args += [
635-
"--clang-compiler-version=%s.%s.%s" % (
635+
"--clang-compiler-version=%s" % (
636636
args.clang_compiler_version)
637637
]
638638
if args.verbose_build:

utils/swift_build_support/swift_build_support/arguments.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,33 @@ def type_shell_split(string):
7373
_register(type, 'shell_split', type_shell_split)
7474

7575

76+
class CompilerVersion(object):
77+
"""A typed representation of a compiler version."""
78+
79+
def __init__(self, string_representation, components):
80+
self.string_representation = string_representation
81+
self.components = components
82+
83+
def __str__(self):
84+
return self.string_representation
85+
86+
7687
def type_clang_compiler_version(string):
7788
"""
7889
Parse version string and split into a tuple of strings
7990
(major, minor, patch)
8091
81-
Support only "MAJOR.MINOR.PATCH" format.
92+
Supports "MAJOR.MINOR.PATCH" and "MAJOR.MINOR.PATCH.PATCH" formats.
8293
"""
83-
m = re.match(r'^([0-9]+)\.([0-9]+)\.([0-9]+)$', string)
94+
m = re.match(r'^([0-9]+)\.([0-9]+)\.([0-9]+)(\.([0-9]+))?$', string)
8495
if m is not None:
85-
return m.group(1, 2, 3)
96+
return CompilerVersion(
97+
string_representation=string,
98+
components=m.group(1, 2, 3, 5))
8699
raise argparse.ArgumentTypeError(
87-
"%r is invalid version value. must be 'MAJOR.MINOR.PATCH'" % string)
100+
"%r is an invalid version value, "
101+
"must be 'MAJOR.MINOR.PATCH' or "
102+
"'MAJOR.MINOR.PATCH.PATCH'" % string)
88103

89104
_register(type, 'clang_compiler_version', type_clang_compiler_version)
90105

utils/swift_build_support/swift_build_support/cmake.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def common_options(self):
110110
"Debug;Release;MinSizeRel;RelWithDebInfo")
111111

112112
if args.clang_compiler_version:
113-
major, minor, patch = args.clang_compiler_version
113+
major, minor, patch, _ = args.clang_compiler_version.components
114114
define("LLVM_VERSION_MAJOR:STRING", major)
115115
define("LLVM_VERSION_MINOR:STRING", minor)
116116
define("LLVM_VERSION_PATCH:STRING", patch)

utils/swift_build_support/tests/test_arguments.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,20 @@ def test_shell_split(self):
4949

5050
def test_clang_compiler_version(self):
5151
self.assertEqual(
52-
argtype.clang_compiler_version('1.23.456'),
53-
("1", "23", "456"))
52+
argtype.clang_compiler_version('1.23.456').components,
53+
("1", "23", "456", None))
54+
self.assertEqual(
55+
argtype.clang_compiler_version('1.2.3').components,
56+
("1", "2", "3", None))
57+
self.assertEqual(
58+
argtype.clang_compiler_version('1.2.3.4').components,
59+
("1", "2", "3", "4"))
60+
self.assertEqual(
61+
argtype.clang_compiler_version('12.34.56').components,
62+
("12", "34", "56", None))
63+
self.assertEqual(
64+
argtype.clang_compiler_version('12.34.56.78').components,
65+
("12", "34", "56", "78"))
5466
self.assertRaises(
5567
argparse.ArgumentTypeError,
5668
argtype.clang_compiler_version,

utils/swift_build_support/tests/test_cmake.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import unittest
1313
from argparse import Namespace
1414

15+
from swift_build_support.arguments import CompilerVersion
1516
from swift_build_support.cmake import CMake, CMakeOptions
1617
from swift_build_support.toolchain import host_toolchain
1718

@@ -132,7 +133,9 @@ def test_common_options_xcode(self):
132133

133134
def test_common_options_clang_compiler_version(self):
134135
args = self.default_args()
135-
args.clang_compiler_version = ("3", "8", "0")
136+
args.clang_compiler_version = CompilerVersion(
137+
string_representation="3.8.0",
138+
components=("3", "8", "0", None))
136139
cmake = self.cmake(args)
137140
self.assertEqual(
138141
list(cmake.common_options()),
@@ -161,7 +164,9 @@ def test_common_options_full(self):
161164
args.export_compile_commands = True
162165
args.distcc = True
163166
args.cmake_generator = 'Xcode'
164-
args.clang_compiler_version = ("3", "8", "0")
167+
args.clang_compiler_version = CompilerVersion(
168+
string_representation="3.8.0",
169+
components=("3", "8", "0", None))
165170
args.build_ninja = True
166171
cmake = self.cmake(args)
167172
self.assertEqual(

0 commit comments

Comments
 (0)