Skip to content

Python-only build script #23038

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
84fc494
[build-script] Compatibility with Python 3
drodriguez Feb 16, 2019
58a2401
[build-script] Improve compatibility with Windows platforms.
drodriguez Feb 16, 2019
ad14c88
[build-script] Add Windows CMD for build-script. Invokes original.
drodriguez Feb 16, 2019
fc06b3c
[gyb] Support for Python 3.5 (and 2.7)
drodriguez Feb 27, 2019
fd5d42c
[utils] Improve compatibility with Python 3.
drodriguez Feb 27, 2019
5b718aa
[coverage-touch-tests] Improve compatibility with Windows.
drodriguez Feb 27, 2019
f51fbfe
[update-checkout] Improve compatibility with Python 3
drodriguez Feb 28, 2019
65af05b
[build-script][WIP] Rewrite build-script-impl in Python for Windows
drodriguez Feb 16, 2019
ba6eac4
[build-script][WIP] Support for LLDB in native Python
drodriguez Mar 2, 2019
efe8549
[build-script][WIP] Support for LibDispatch in native Python
drodriguez Mar 5, 2019
595ea4c
[build-script][WIP] Support for Foundation in native Python
drodriguez Mar 6, 2019
a2b996d
[build-script][WIP] Support for XCTest in native Python
drodriguez Mar 6, 2019
bed35e3
[test] Make some Driver test compatible with Python 3
drodriguez Mar 9, 2019
5b639d2
[test] Make binary_sub.py compatible with Python 3
drodriguez Mar 9, 2019
77a3b89
[test] Make tokens_unknown_and_invalid.swift compatible with Python 3
drodriguez Mar 9, 2019
5191119
[test] Make lit.cfg compatible with Python 3
drodriguez Mar 9, 2019
730047e
[test] Make validate_parse.py compatible with Python 3
drodriguez Mar 9, 2019
6c54372
[test] Make jobstats.py compatible with Python 3
drodriguez Mar 9, 2019
1cb670a
[test] Make line-directive compatible with Python 3
drodriguez Mar 9, 2019
678efb2
[utils] Make process-stats-dir.py compatible with Python 3
drodriguez Mar 11, 2019
6cb771e
[utils] Make remote-run compatible with Python 3
drodriguez Mar 11, 2019
c0f97a4
[test] Make round-trip-syntax-test compatible with Python 3
drodriguez Mar 11, 2019
36af35b
[test] Make scale-test compatible with Python 3
drodriguez Mar 11, 2019
6e89ae8
[test] Make update_checkout.test-sh compatible with Python 3
drodriguez Mar 11, 2019
0c6a2c3
[test] Fix FixedPointConversion tests
drodriguez Mar 11, 2019
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
3 changes: 1 addition & 2 deletions stdlib/public/core/IntegerTypes.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from SwiftIntTypes import all_integer_types, int_max_bits, should_define_truncating_bit_pattern_init
from SwiftFloatingPointTypes import getFtoIBounds

from string import maketrans, capitalize
from itertools import chain

# Number of bits in the Builtin.Word type
Expand Down Expand Up @@ -1651,7 +1650,7 @@ extension ${Self} : Hashable {
return Hasher._hash(
seed: seed,
bytes: UInt64(truncatingIfNeeded: ${U}${Self}(_value)),
count: ${bits / 8})
count: ${int(bits // 8)})
% end
}
}
Expand Down
15 changes: 8 additions & 7 deletions stdlib/public/core/SIMDVectorTypes.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,20 @@ public struct SIMD${n}<Scalar> : SIMD where Scalar: SIMDScalar {
% end
% end
% if n >= 4:
% halfN = int(n/2)
/// Creates a new vector from two half-length vectors.
@_transparent
public init(lowHalf: SIMD${n/2}<Scalar>, highHalf: SIMD${n/2}<Scalar>) {
public init(lowHalf: SIMD${halfN}<Scalar>, highHalf: SIMD${halfN}<Scalar>) {
self.init()
self.lowHalf = lowHalf
self.highHalf = highHalf
}

% for (half,indx) in [('low','i'), ('high',str(n/2)+'+i'), ('even','2*i'), ('odd','2*i+1')]:
% for (half,indx) in [('low','i'), ('high',str(halfN)+'+i'), ('even','2*i'), ('odd','2*i+1')]:
/// A half-length vector made up of the ${half} elements of the vector.
public var ${half}Half: SIMD${n/2}<Scalar> {
public var ${half}Half: SIMD${halfN}<Scalar> {
@inlinable get {
var result = SIMD${n/2}<Scalar>()
var result = SIMD${halfN}<Scalar>()
for i in result.indices { result[i] = self[${indx}] }
return result
}
Expand Down Expand Up @@ -147,7 +148,7 @@ extension SIMD${n} : CustomDebugStringConvertible {
public var debugDescription: String {
return "SIMD${n}<\(Scalar.self)>(${', '.join(map(lambda c:
'\\(self['+ str(c) + '])',
xrange(n)))})"
range(n)))})"
}
}

Expand Down Expand Up @@ -184,7 +185,7 @@ extension ${Self} : SIMDScalar {
public typealias SIMDMaskScalar = ${Mask}

% for n in storagescalarCounts:
% bytes = n * self_type.bits / 8
% bytes = int(n * self_type.bits / 8)
/// Storage for a vector of ${spelledNumbers[n]} integers.
@_fixed_layout
@_alignment(${bytes if bytes <= 16 else 16})
Expand Down Expand Up @@ -229,7 +230,7 @@ extension ${Self} : SIMDScalar {
public typealias SIMDMaskScalar = Int${bits}

% for n in storagescalarCounts:
% bytes = n * bits / 8
% bytes = int(n * bits / 8)
/// Storage for a vector of ${spelledNumbers[n]} floating-point values.
@_fixed_layout
@_alignment(${bytes if bytes <= 16 else 16})
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Tuple.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public func >=(lhs: (), rhs: ()) -> Bool {
% equatableTypeParams = ", ".join(["{} : Equatable".format(c) for c in typeParams])

% originalTuple = "(\"a\", {})".format(", ".join(map(str, range(1, arity))))
% greaterTuple = "(\"a\", {})".format(", ".join(map(str, range(1, arity - 1) + [arity])))
% greaterTuple = "(\"a\", {})".format(", ".join(map(str, list(range(1, arity - 1)) + [arity])))

/// Returns a Boolean value indicating whether the corresponding components of
/// two tuples are equal.
Expand Down
2 changes: 1 addition & 1 deletion test/Driver/response-file-merge-modules.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %{python} -c 'for i in range(500001): print "-DTEST_" + str(i)' > %t.resp
// RUN: %{python} -c 'for i in range(500001): print("-DTEST_" + str(i))' > %t.resp
// RUN: %swiftc_driver -driver-print-jobs -module-name merge -emit-module %S/Inputs/main.swift %S/Inputs/lib.swift @%t.resp 2>&1 > %t.jobs.txt
// RUN: %FileCheck %s < %t.jobs.txt -check-prefix=MERGE

Expand Down
4 changes: 2 additions & 2 deletions test/Driver/response-file.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %target-build-swift -typecheck @%t.0.resp %s 2>&1 | %FileCheck %s -check-prefix=SHORT
// SHORT: warning: result of call to 'abs' is unused

// RUN: %{python} -c 'for a in ["A", "B", "C", "D"]: print "-DTEST1" + a' > %t.1.resp
// RUN: %{python} -c 'for a in ["A", "B", "C", "D"]: print("-DTEST1" + a)' > %t.1.resp
// RUN: %target-build-swift -typecheck @%t.1.resp %s 2>&1 | %FileCheck %s -check-prefix=MULTIPLE
// MULTIPLE: warning: result of call to 'abs' is unused

Expand All @@ -24,7 +24,7 @@
// RUN: %target-build-swift -typecheck @%t.4B.resp 2>&1 | %FileCheck %s -check-prefix=RECURSIVE
// RECURSIVE: warning: result of call to 'abs' is unused

// RUN: %{python} -c 'for i in range(500001): print "-DTEST5_" + str(i)' > %t.5.resp
// RUN: %{python} -c 'for i in range(500001): print("-DTEST5_" + str(i))' > %t.5.resp
// RUN: %target-build-swift -typecheck @%t.5.resp %s 2>&1 | %FileCheck %s -check-prefix=LONG
// LONG: warning: result of call to 'abs' is unused
// RUN: %empty-directory(%t/tmp)
Expand Down
13 changes: 11 additions & 2 deletions test/Serialization/Inputs/binary_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,14 @@
(_, old, new) = sys.argv
assert(len(old) == len(new))

data = sys.stdin.read()
sys.stdout.write(data.replace(old, new))
if sys.version_info[0] == 2:
stdin = sys.stdin
stdout = sys.stdout
else:
stdin = sys.stdin.buffer
stdout = sys.stdout.buffer
old = old.encode()
new = new.encode()

data = stdin.read()
stdout.write(data.replace(old, new))
2 changes: 1 addition & 1 deletion test/Syntax/tokens_unknown_and_invalid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// marker is also represented in escape sequence.

// RUN: cat %s | sed -f %S/Inputs/invalid.sed > %t
// RUN: %{python} -c "import sys; t = open(sys.argv[1], 'rb').read().replace('\r\n', '\n'); open(sys.argv[1], 'wb').write(t)" %t
// RUN: %{python} -c "import sys; t = open(sys.argv[1], 'rb').read().replace('\r\n'.encode(), '\n'.encode()); open(sys.argv[1], 'wb').write(t)" %t
// RUN: %swift-syntax-test -input-source-filename %t -dump-full-tokens 2>&1 | %FileCheck %t
// RUN: %round-trip-syntax-test --swift-syntax-test %swift-syntax-test --file %t

Expand Down
2 changes: 1 addition & 1 deletion test/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ source_compiler_rt_libs(compiler_rt_dir)

def check_runtime_libs(features_to_check):
for lib in config.compiler_rt_libs:
for (libname, feature) in features_to_check.iteritems():
for (libname, feature) in features_to_check.items():
if lib.startswith("libclang_rt." + libname + "_"):
config.available_features.add(feature)

Expand Down
39 changes: 22 additions & 17 deletions test/stdlib/Inputs/FixedPointConversion.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ int_to_int_conversion_template = gyb.parse_template("int_to_int_conversion",
"""
%{
from SwiftIntTypes import all_integer_types, int_max, int_min
from SwiftFloatingPointTypes import all_floating_point_types
from SwiftFloatingPointTypes import all_floating_point_types, getFtoIBounds

from decimal import Decimal


}%
% for self_ty in all_integer_types(word_bits):
Expand Down Expand Up @@ -105,51 +108,53 @@ FixedPointConversionFailure.test("${Other}To${Self}Conversion/dest=${testValue}"
% Other = "Float" + str(other_type.bits)
% otherMin = -int_max(bits=other_type.explicit_significand_bits, signed=False)
% otherMax = int_max(bits=other_type.explicit_significand_bits, signed=False)
% (selfFtoIMin, selfFtoIMax) = getFtoIBounds(other_type.bits, selfBits, selfSigned)

% if Other == 'Float80':
#if !os(Windows) && (arch(i386) || arch(x86_64))
% end

% for testValue in [repr(value) for value in [selfMin, selfMax, selfMin - 0.1, selfMax + 0.1, otherMin, otherMax, 0.0, -0.0, 0.1, -0.1]]:
% for testValue in [Decimal(selfMin), Decimal(selfMax), Decimal(selfFtoIMin) - Decimal('0.1'), Decimal(selfFtoIMax) + Decimal('0.1'), Decimal(otherMin), Decimal(otherMax), Decimal('0.0'), Decimal('-0.0'), Decimal('0.1'), Decimal('-0.1')]:
% testValueStr = str(testValue)

% if testValue < otherMin or testValue > otherMax:
% # Can't construct `other` value to test from, do nothing and continue.

% elif testValue >= selfMin and testValue <= selfMax and testValue % 1 == 0 and testValue != -0.0:
% elif testValue >= selfFtoIMin and testValue <= selfFtoIMax and (testValue % 1).is_zero():

FloatingPointConversionTruncations.test("${Other}To${Self}Conversion/dest=${testValue}") {
let input = get${Other}(${testValue})
FloatingPointConversionTruncations.test("${Other}To${Self}Conversion/dest=${testValueStr}") {
let input = get${Other}(${testValueStr})
let result = ${Self}(input)
var resultConvertedBack = ${Other}(result)
expectEqual(${testValue}, resultConvertedBack)
expectEqual(${testValueStr}, resultConvertedBack)
}

FloatingPointConversionFailures.test("${Other}To${Self}FailableConversion/dest=${testValue}") {
let input = get${Other}(${testValue})
expectNil(${Self}(exactly: input))
FloatingPointConversionFailures.test("${Other}To${Self}FailableConversion/dest=${testValueStr}") {
let input = get${Other}(${testValueStr})
expectNotNil(${Self}(exactly: input))
}

% else:

% if testValue > selfMax:
FloatingPointConversionTraps.test("${Other}To${Self}Conversion/dest=${testValue}")
% if testValue > selfFtoIMax:
FloatingPointConversionTraps.test("${Other}To${Self}Conversion/dest=${testValueStr}")
.crashOutputMatches(getTooLargeMessage()).code {
expectCrashLater()
% elif testValue < selfMin:
FloatingPointConversionTraps.test("${Other}To${Self}Conversion/dest=${testValue}")
% elif testValue < selfFtoIMin:
FloatingPointConversionTraps.test("${Other}To${Self}Conversion/dest=${testValueStr}")
.crashOutputMatches(getTooSmallMessage()).code {
expectCrashLater()
% else:
FloatingPointConversionTruncations.test("${Other}To${Self}Conversion/dest=${testValue}") {
FloatingPointConversionTruncations.test("${Other}To${Self}Conversion/dest=${testValueStr}") {
% end
let input = get${Other}(${testValue})
let input = get${Other}(${testValueStr})
var result = ${Self}(input)
var resultConvertedBack = ${Other}(result)
expectNotEqual(input, resultConvertedBack)
}

FloatingPointConversionFailures.test("${Other}To${Self}Conversion/dest=${testValue}") {
let input = get${Other}(${testValue})
FloatingPointConversionFailures.test("${Other}To${Self}Conversion/dest=${testValueStr}") {
let input = get${Other}(${testValueStr})
expectNil(${Self}(exactly: input))
}
% end
Expand Down
2 changes: 1 addition & 1 deletion test/stdlib/NumericParsing.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Note: the third parameter, zero, is not for user consumption.
else:
r = n % radix
digit = chr((ord('0') + r) if r < 10 else (ord('a') + r - 10))
return inRadix(radix, int(n / radix), '') + digit
return inRadix(radix, int(n // radix), '') + digit

# The maximal legal radix
max_radix = ord('z') - ord('a') + 1 + 10
Expand Down
5 changes: 3 additions & 2 deletions utils/PathSanitizingFileCheck
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import argparse
import subprocess
import sys

is_py2 = sys.version_info[0] == 2

def main():
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -44,10 +45,10 @@ constants.""")

args, unknown_args = parser.parse_known_args()

stdin = sys.stdin.read()
stdin = sys.stdin.read() if is_py2 else sys.stdin.buffer.read()
for s in args.sanitize_strings:
replacement, pattern = s.split('=', 1)
stdin = stdin.replace(pattern, replacement)
stdin = stdin.replace(pattern.encode(), replacement.encode())

p = subprocess.Popen(
[args.file_check_path] + unknown_args, stdin=subprocess.PIPE)
Expand Down
Loading