Skip to content

build-script: support 4 version components in Clang versions #3509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ class BuildScriptInvocation(object):
impl_args += ["--enable-ubsan"]
if args.clang_compiler_version:
impl_args += [
"--clang-compiler-version=%s.%s.%s" % (
"--clang-compiler-version=%s" % (
args.clang_compiler_version)
]
if args.verbose_build:
Expand Down
23 changes: 19 additions & 4 deletions utils/swift_build_support/swift_build_support/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,33 @@ def type_shell_split(string):
_register(type, 'shell_split', type_shell_split)


class CompilerVersion(object):
"""A typed representation of a compiler version."""

def __init__(self, string_representation, components):
self.string_representation = string_representation
self.components = components

def __str__(self):
return self.string_representation


def type_clang_compiler_version(string):
"""
Parse version string and split into a tuple of strings
(major, minor, patch)
Support only "MAJOR.MINOR.PATCH" format.
Supports "MAJOR.MINOR.PATCH" and "MAJOR.MINOR.PATCH.PATCH" formats.
"""
m = re.match(r'^([0-9]+)\.([0-9]+)\.([0-9]+)$', string)
m = re.match(r'^([0-9]+)\.([0-9]+)\.([0-9]+)(\.([0-9]+))?$', string)
if m is not None:
return m.group(1, 2, 3)
return CompilerVersion(
string_representation=string,
components=m.group(1, 2, 3, 5))
raise argparse.ArgumentTypeError(
"%r is invalid version value. must be 'MAJOR.MINOR.PATCH'" % string)
"%r is an invalid version value, "
"must be 'MAJOR.MINOR.PATCH' or "
"'MAJOR.MINOR.PATCH.PATCH'" % string)

_register(type, 'clang_compiler_version', type_clang_compiler_version)

Expand Down
2 changes: 1 addition & 1 deletion utils/swift_build_support/swift_build_support/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def common_options(self):
"Debug;Release;MinSizeRel;RelWithDebInfo")

if args.clang_compiler_version:
major, minor, patch = args.clang_compiler_version
major, minor, patch, _ = args.clang_compiler_version.components
define("LLVM_VERSION_MAJOR:STRING", major)
define("LLVM_VERSION_MINOR:STRING", minor)
define("LLVM_VERSION_PATCH:STRING", patch)
Expand Down
16 changes: 14 additions & 2 deletions utils/swift_build_support/tests/test_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,20 @@ def test_shell_split(self):

def test_clang_compiler_version(self):
self.assertEqual(
argtype.clang_compiler_version('1.23.456'),
("1", "23", "456"))
argtype.clang_compiler_version('1.23.456').components,
("1", "23", "456", None))
self.assertEqual(
argtype.clang_compiler_version('1.2.3').components,
("1", "2", "3", None))
self.assertEqual(
argtype.clang_compiler_version('1.2.3.4').components,
("1", "2", "3", "4"))
self.assertEqual(
argtype.clang_compiler_version('12.34.56').components,
("12", "34", "56", None))
self.assertEqual(
argtype.clang_compiler_version('12.34.56.78').components,
("12", "34", "56", "78"))
self.assertRaises(
argparse.ArgumentTypeError,
argtype.clang_compiler_version,
Expand Down
9 changes: 7 additions & 2 deletions utils/swift_build_support/tests/test_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import unittest
from argparse import Namespace

from swift_build_support.arguments import CompilerVersion
from swift_build_support.cmake import CMake, CMakeOptions
from swift_build_support.toolchain import host_toolchain

Expand Down Expand Up @@ -132,7 +133,9 @@ def test_common_options_xcode(self):

def test_common_options_clang_compiler_version(self):
args = self.default_args()
args.clang_compiler_version = ("3", "8", "0")
args.clang_compiler_version = CompilerVersion(
string_representation="3.8.0",
components=("3", "8", "0", None))
cmake = self.cmake(args)
self.assertEqual(
list(cmake.common_options()),
Expand Down Expand Up @@ -161,7 +164,9 @@ def test_common_options_full(self):
args.export_compile_commands = True
args.distcc = True
args.cmake_generator = 'Xcode'
args.clang_compiler_version = ("3", "8", "0")
args.clang_compiler_version = CompilerVersion(
string_representation="3.8.0",
components=("3", "8", "0", None))
args.build_ninja = True
cmake = self.cmake(args)
self.assertEqual(
Expand Down