Skip to content

Update Python build scripts to use the print function #639

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
Dec 20, 2015
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
6 changes: 4 additions & 2 deletions docs/scripts/ns-html2rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/env python
from __future__ import print_function

import sys, re, subprocess

def run():
if len(sys.argv) > 1:
print """
print("""
ns-html2rst - Convert Cocoa HTML documentation into ReST

usage: nshtml2rst < NSString.html > NSString.rst
"""
""")
exit(0)

html = sys.stdin.read()
Expand Down
6 changes: 4 additions & 2 deletions test/Driver/Dependencies/Inputs/fake-build-for-bitcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Emulates the frontend of an -embed-bitcode job. That means we have to handle
# -emit-bc and -c actions.

from __future__ import print_function

import os
import shutil
import sys
Expand All @@ -18,8 +20,8 @@
os.utime(outputFile, None)

if '-emit-bc' in sys.argv:
print "Handled", os.path.basename(primaryFile)
print("Handled", os.path.basename(primaryFile))
elif '-c' in sys.argv:
print "Produced", os.path.basename(outputFile)
print("Produced", os.path.basename(outputFile))
else:
assert False, "unknown action"
4 changes: 3 additions & 1 deletion test/Driver/Dependencies/Inputs/fake-build-whole-module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# Emulates the frontend of a -whole-module-optimization compilation.

from __future__ import print_function

import os
import shutil
import sys
Expand All @@ -16,4 +18,4 @@
with open(outputFile, 'a'):
os.utime(outputFile, None)

print "Produced", os.path.basename(outputFile)
print("Produced", os.path.basename(outputFile))
6 changes: 4 additions & 2 deletions test/Driver/Dependencies/Inputs/modify-non-primary-files.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# modify-non-primary-files.py simulates a build where the user is modifying the
# source files during compilation.

from __future__ import print_function

import os
import shutil
import sys
Expand Down Expand Up @@ -32,6 +34,6 @@
os.utime(outputFile, None)

if primaryFile:
print "Handled", os.path.basename(primaryFile)
print("Handled", os.path.basename(primaryFile))
else:
print "Produced", os.path.basename(outputFile)
print("Produced", os.path.basename(outputFile))
4 changes: 3 additions & 1 deletion test/Driver/Dependencies/Inputs/update-dependencies-bad.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Fails if the input file is named "bad.swift"; otherwise dispatches to
# update-dependencies.py.

from __future__ import print_function

import os
import sys

Expand All @@ -11,7 +13,7 @@
primaryFile = sys.argv[sys.argv.index('-primary-file') + 1]

if os.path.basename(primaryFile) == 'bad.swift':
print "Handled", os.path.basename(primaryFile)
print("Handled", os.path.basename(primaryFile))
exit(1)

dir = os.path.dirname(os.path.abspath(__file__))
Expand Down
6 changes: 4 additions & 2 deletions test/Driver/Dependencies/Inputs/update-dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#
# If invoked in non-primary-file mode, it only creates the output file.

from __future__ import print_function

import os
import shutil
import sys
Expand All @@ -37,6 +39,6 @@
os.utime(outputFile, None)

if primaryFile:
print "Handled", os.path.basename(primaryFile)
print("Handled", os.path.basename(primaryFile))
else:
print "Produced", os.path.basename(outputFile)
print("Produced", os.path.basename(outputFile))
4 changes: 3 additions & 1 deletion test/Inputs/getmtime.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python

from __future__ import print_function

import os
import sys

print os.path.getmtime(sys.argv[1])
print(os.path.getmtime(sys.argv[1]))
5 changes: 3 additions & 2 deletions utils/apply-fixit-edits.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#
#===------------------------------------------------------------------------===#

from __future__ import print_function

import subprocess
import json
Expand All @@ -29,7 +30,7 @@ def find_remap_files(path):
def apply_edits(path):
remap_files = find_remap_files(path)
if not remap_files:
print "No remap files found"
print("No remap files found")
return 1;

edits_set = set()
Expand All @@ -53,7 +54,7 @@ def apply_edits(path):
edits_per_file[fname].append((ed[1], ed[2], ed[3]))

for fname, edits in edits_per_file.iteritems():
print 'Updating', fname
print('Updating', fname)
edits.sort(reverse=True)
file_data = open(fname).read()
for ed in edits:
Expand Down
32 changes: 17 additions & 15 deletions utils/cmpcodesize/cmpcodesize/compare.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import re
import os
import subprocess
Expand Down Expand Up @@ -145,7 +147,7 @@ def compareSizes(oldSizes, newSizes, nameKey, title):
perc = "%.1f%%" % ((1.0 - float(newSize) / float(oldSize)) * 100.0)
else:
perc = "- "
print "%-26s%16s: %8d %8d %6s" % (title, nameKey, oldSize, newSize, perc)
print("%-26s%16s: %8d %8d %6s" % (title, nameKey, oldSize, newSize, perc))


def compareSizesOfFile(oldFiles, newFiles, allSections, listCategories):
Expand Down Expand Up @@ -226,21 +228,21 @@ def compareFunctionSizes(oldFiles, newFiles):
onlyInFile2Size += newSize

if onlyInFile1:
print "Only in old file(s)"
print listFunctionSizes(onlyInFile1)
print "Total size of functions only in old file: {}".format(onlyInFile1Size)
print
print("Only in old file(s)")
print(listFunctionSizes(onlyInFile1))
print("Total size of functions only in old file: {}".format(onlyInFile1Size))
print()

if onlyInFile2:
print "Only in new files(s)"
print listFunctionSizes(onlyInFile2)
print "Total size of functions only in new file: {}".format(onlyInFile2Size)
print
print("Only in new files(s)")
print(listFunctionSizes(onlyInFile2))
print("Total size of functions only in new file: {}".format(onlyInFile2Size))
print()

if inBoth:
sizeIncrease = 0
sizeDecrease = 0
print "%8s %8s %8s" % ("old", "new", "diff")
print("%8s %8s %8s" % ("old", "new", "diff"))
for triple in sorted(inBoth, key=lambda tup: (tup[2] - tup[1], tup[1])):
func = triple[0]
oldSize = triple[1]
Expand All @@ -252,8 +254,8 @@ def compareFunctionSizes(oldFiles, newFiles):
sizeDecrease -= diff
if diff == 0:
inBothSize += newSize
print "%8d %8d %8d %s" %(oldSize, newSize, newSize - oldSize, func)
print "Total size of functions with the same size in both files: {}".format(inBothSize)
print "Total size of functions that got smaller: {}".format(sizeDecrease)
print "Total size of functions that got bigger: {}".format(sizeIncrease)
print "Total size change of functions present in both files: {}".format(sizeIncrease - sizeDecrease)
print("%8d %8d %8d %s" %(oldSize, newSize, newSize - oldSize, func))
print("Total size of functions with the same size in both files: {}".format(inBothSize))
print("Total size of functions that got smaller: {}".format(sizeDecrease))
print("Total size of functions that got bigger: {}".format(sizeIncrease))
print("Total size change of functions present in both files: {}".format(sizeIncrease - sizeDecrease))
10 changes: 6 additions & 4 deletions utils/cmpcodesize/cmpcodesize/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python

from __future__ import print_function

import argparse
import sys
import os
Expand Down Expand Up @@ -132,7 +134,7 @@ def main():
'$SWIFT_NEW_BUILDDIR environment variables set.\n' + \
'$SWIFT_OLD_BUILDDIR = {0}\n$SWIFT_NEW_BUILDDIR = {1}'.format(
oldBuildDir, newBuildDir)
oldFileArgs = SHORTCUTS.keys()
oldFileArgs = list(SHORTCUTS.keys())

oldFiles = []
newFiles = []
Expand All @@ -150,7 +152,7 @@ def main():
numExpanded += 1

if numExpanded != 0 and numExpanded != len(oldFileArgs):
sys.exit("mix of expanded/not-expanded arguments")
sys.exit("mix of expanded/not-expanded arguments")
if numExpanded == 0:
if len(oldFileArgs) > 2:
sys.exit("too many arguments")
Expand All @@ -166,11 +168,11 @@ def main():
sizes = collections.defaultdict(int)
for file in oldFiles:
readSizes(sizes, file, True, False)
print listFunctionSizes(sizes.items())
print(listFunctionSizes(sizes.items()))
else:
compareFunctionSizes(oldFiles, newFiles)
else:
print "%-26s%16s %8s %8s %s" % ("", "Section", "Old", "New", "Percent")
print("%-26s%16s %8s %8s %s" % ("", "Section", "Old", "New", "Percent"))
if parsed_arguments.sum_sizes:
compareSizesOfFile(oldFiles, newFiles,
parsed_arguments.all_sections,
Expand Down
10 changes: 6 additions & 4 deletions utils/demo-tool
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python

from __future__ import print_function

import json
import optparse
import subprocess
Expand Down Expand Up @@ -115,10 +117,10 @@ for example::
def prompterPrint(string):
if hasColor:
attr = [ '32', '1' ]
print '\x1b[%sm%s\x1b[0m' % (';'.join(attr), string)
print('\x1b[%sm%s\x1b[0m' % (';'.join(attr), string))
else:
print string

print(string)
def send(*args, **kwargs):
return send_to_screen(opts.screen_name, *args, **kwargs)
parser.add_option("-S", "--screen-name", dest="screen_name", metavar="NAME",
Expand Down Expand Up @@ -162,7 +164,7 @@ for example::

if command:
# Send the command slowly, as if it was typed.
print "sending command: %r" % (command.replace('\n', '<cr>'),)
print("sending command: %r" % (command.replace('\n', '<cr>'),))
for c in command:
send(c)
if c == "\n":
Expand All @@ -179,7 +181,7 @@ for example::
raw_input('press enter to continue to next command...')
# Send the command slowly, as if it was typed.
if shouldClear:
print "clearing screen"
print("clearing screen")
send(command="clear")
send('\n')

Expand Down
4 changes: 3 additions & 1 deletion utils/gyb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# GYB: Generate Your Boilerplate (improved names welcome; at least
# this one's short). See -h output for instructions

from __future__ import print_function

import re
from cStringIO import StringIO
import tokenize
Expand Down Expand Up @@ -1051,8 +1053,8 @@ def succ(a):
bindings = dict( x.split('=', 1) for x in args.defines )
ast = parseTemplate(args.file.name, args.file.read())
if args.dump:
print ast

print(ast)
# Allow the template to import .py files from its own directory
sys.path = [os.path.split(args.file.name)[0] or '.'] + sys.path

Expand Down
14 changes: 8 additions & 6 deletions utils/omit-needless-words.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# heuristics that omit 'needless' words from APIs imported from Clang
# into Swift.

from __future__ import print_function

import argparse
import subprocess

Expand Down Expand Up @@ -52,32 +54,32 @@ def main():

swift_ide_test_cmd = [args.swift_ide_test, '-print-module', '-source-filename', source_filename, '-sdk', sdkroot, '-target', args.target, '-module-print-skip-overlay', '-skip-unavailable', '-module-print-submodules', '-skip-imports', '-module-to-print=%s' % (args.module)]
omit_needless_words_args = ['-enable-omit-needless-words', '-enable-infer-default-arguments']

# Determine the output files.
# No good way with argparse to set default value based on depenency of other arg.
if not args.before_file:
args.before_file = '%s.before.txt' % (args.module)
if not args.after_file:
args.after_file = '%s.after.txt' % (args.module)

# Create a .swift file we can feed into swift-ide-test
subprocess.call(['touch', source_filename])

if not args.only_after:
# Print the interface without omitting needless words
if not args.quiet:
print('Writing %s...' % args.before_file)
output_command_result_to_file(swift_ide_test_cmd, args.before_file)

if not args.only_before:
# Print the interface omitting needless words
if not args.quiet:
print('Writing %s...' % args.after_file)
output_command_result_to_file(swift_ide_test_cmd + omit_needless_words_args, args.after_file)

# Remove the .swift file we fed into swift-ide-test
subprocess.call(['rm', '-f', source_filename])

# Diff them
subprocess.call([args.diff_tool, args.before_file, args.after_file])

Expand Down
Loading