Skip to content

Commit bbfcc62

Browse files
authored
Merge pull request #32127 from compnerd/python-is-dead-long-live-python
build: switch gyb to Python3
2 parents 43fd786 + 4240a90 commit bbfcc62

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function(_swift_gyb_target_sources target scope)
2323

2424
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${generated}
2525
COMMAND
26-
$<TARGET_FILE:Python2::Interpreter> ${SWIFT_SOURCE_DIR}/utils/gyb -D CMAKE_SIZEOF_VOID_P=${CMAKE_SIZEOF_VOID_P} ${SWIFT_GYB_FLAGS} -o ${CMAKE_CURRENT_BINARY_DIR}/${generated}.tmp ${absolute}
26+
$<TARGET_FILE:Python3::Interpreter> ${SWIFT_SOURCE_DIR}/utils/gyb -D CMAKE_SIZEOF_VOID_P=${CMAKE_SIZEOF_VOID_P} ${SWIFT_GYB_FLAGS} -o ${CMAKE_CURRENT_BINARY_DIR}/${generated}.tmp ${absolute}
2727
COMMAND
2828
${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/${generated}.tmp ${CMAKE_CURRENT_BINARY_DIR}/${generated}
2929
COMMAND

cmake/modules/SwiftHandleGybSources.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
include(SwiftAddCustomCommandTarget)
22
include(SwiftSetIfArchBitness)
33

4-
find_package(Python2 COMPONENTS Interpreter REQUIRED)
5-
64
# Create a target to process single gyb source with the 'gyb' tool.
75
#
86
# handle_gyb_source_single(
@@ -60,7 +58,7 @@ function(handle_gyb_source_single dependency_out_var_name)
6058
COMMAND
6159
"${CMAKE_COMMAND}" -E make_directory "${dir}"
6260
COMMAND
63-
"$<TARGET_FILE:Python2::Interpreter>" "${gyb_tool}" ${SWIFT_GYB_FLAGS} ${GYB_SINGLE_FLAGS} -o "${GYB_SINGLE_OUTPUT}.tmp" "${GYB_SINGLE_SOURCE}"
61+
"$<TARGET_FILE:Python3::Interpreter>" "${gyb_tool}" ${SWIFT_GYB_FLAGS} ${GYB_SINGLE_FLAGS} -o "${GYB_SINGLE_OUTPUT}.tmp" "${GYB_SINGLE_SOURCE}"
6462
COMMAND
6563
"${CMAKE_COMMAND}" -E copy_if_different "${GYB_SINGLE_OUTPUT}.tmp" "${GYB_SINGLE_OUTPUT}"
6664
COMMAND

utils/gyb_syntax_support/__init__.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -144,34 +144,36 @@ def dedented_lines(description):
144144
return textwrap.dedent(description).split('\n')
145145

146146

147-
def digest_syntax_node(digest, node):
148-
# Hash into the syntax name and serialization code
149-
digest.update(node.name)
150-
digest.update(str(get_serialization_code(node.syntax_kind)))
151-
for child in node.children:
152-
# Hash into the expected child syntax
153-
digest.update(child.syntax_kind)
154-
# Hash into the child name
155-
digest.update(child.name)
156-
# Hash into whether the child is optional
157-
digest.update(str(child.is_optional))
158-
159-
160-
def digest_syntax_token(digest, token):
161-
# Hash into the token name and serialization code
162-
digest.update(token.name)
163-
digest.update(str(token.serialization_code))
164-
165-
166-
def digest_trivia(digest, trivia):
167-
digest.update(trivia.name)
168-
digest.update(str(trivia.serialization_code))
169-
digest.update(str(trivia.characters))
170-
171-
172147
def calculate_node_hash():
173148
digest = hashlib.sha1()
174-
map(lambda node: digest_syntax_node(digest, node), SYNTAX_NODES)
175-
map(lambda token: digest_syntax_token(digest, token), SYNTAX_TOKENS)
176-
map(lambda trivia: digest_trivia(digest, trivia), TRIVIAS)
149+
150+
def _digest_syntax_node(node):
151+
# Hash into the syntax name and serialization code
152+
digest.update(node.name.encode("utf-8"))
153+
digest.update(str(get_serialization_code(node.syntax_kind)).encode("utf-8"))
154+
for child in node.children:
155+
# Hash into the expected child syntax
156+
digest.update(child.syntax_kind.encode("utf-8"))
157+
# Hash into the child name
158+
digest.update(child.name.encode("utf-8"))
159+
# Hash into whether the child is optional
160+
digest.update(str(child.is_optional).encode("utf-8"))
161+
162+
def _digest_syntax_token(token):
163+
# Hash into the token name and serialization code
164+
digest.update(token.name.encode("utf-8"))
165+
digest.update(str(token.serialization_code).encode("utf-8"))
166+
167+
def _digest_trivia(trivia):
168+
digest.update(trivia.name.encode("utf-8"))
169+
digest.update(str(trivia.serialization_code).encode("utf-8"))
170+
digest.update(str(trivia.characters).encode("utf-8"))
171+
172+
for node in SYNTAX_NODES:
173+
_digest_syntax_node(node)
174+
for token in SYNTAX_TOKENS:
175+
_digest_syntax_token(token)
176+
for trivia in TRIVIAS:
177+
_digest_trivia(trivia)
178+
177179
return digest.hexdigest()

0 commit comments

Comments
 (0)