diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-23 19:13:44 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-23 19:13:44 +0000 |
commit | 3f09d180c4d21f9c74689d23d796aed490661182 (patch) | |
tree | 9afdc2584b229bba954fc4fc307d20599005ef7f /build | |
parent | f44725cf38e0f25a54a5cdeef699c11c9562b2d9 (diff) | |
download | chromium_src-3f09d180c4d21f9c74689d23d796aed490661182.zip chromium_src-3f09d180c4d21f9c74689d23d796aed490661182.tar.gz chromium_src-3f09d180c4d21f9c74689d23d796aed490661182.tar.bz2 |
Fix python scripts in src/build/
Make sure that:
- shebang is only present for executable files
- shebang is #!/usr/bin/env python
- __main__ is only present for executable files
- file's executable bit is coherent
Also fix EOF LF to be only one.
TBR=michaelbai@chromium.org
BUG=105108
TEST=
Review URL: http://codereview.chromium.org/8667008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111385 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build')
24 files changed, 122 insertions, 119 deletions
diff --git a/build/android/android_commands.py b/build/android/android_commands.py index 27c1c3d..af1a6b8 100755 --- a/build/android/android_commands.py +++ b/build/android/android_commands.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/build/android/base_test_runner.py b/build/android/base_test_runner.py index 95d7e4f..bb0316b 100644 --- a/build/android/base_test_runner.py +++ b/build/android/base_test_runner.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/build/android/cmd_helper.py b/build/android/cmd_helper.py index bedab94..901cbe9a 100644 --- a/build/android/cmd_helper.py +++ b/build/android/cmd_helper.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/build/android/debug_info.py b/build/android/debug_info.py index f4df79c..9a836e3 100644 --- a/build/android/debug_info.py +++ b/build/android/debug_info.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/build/android/emulator.py b/build/android/emulator.py index a42564a..8e7031c 100755 --- a/build/android/emulator.py +++ b/build/android/emulator.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/build/android/flag_changer.py b/build/android/flag_changer.py index 636022b..2c3da49 100644 --- a/build/android/flag_changer.py +++ b/build/android/flag_changer.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/build/android/lighttpd_server.py b/build/android/lighttpd_server.py index 45bfcd0..ffe985b 100755 --- a/build/android/lighttpd_server.py +++ b/build/android/lighttpd_server.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/build/android/perf_tests_helper.py b/build/android/perf_tests_helper.py index 39bf587..740c455 100644 --- a/build/android/perf_tests_helper.py +++ b/build/android/perf_tests_helper.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/build/android/run_tests.py b/build/android/run_tests.py index aa25e154..b1b6a1d 100755 --- a/build/android/run_tests.py +++ b/build/android/run_tests.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/build/android/run_tests_helper.py b/build/android/run_tests_helper.py index dcdc8b2..45e3afd 100644 --- a/build/android/run_tests_helper.py +++ b/build/android/run_tests_helper.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/build/android/single_test_runner.py b/build/android/single_test_runner.py index c238f5d..8ec9501 100755 --- a/build/android/single_test_runner.py +++ b/build/android/single_test_runner.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/build/android/test_package.py b/build/android/test_package.py index d81f0fc..433e7f1 100644 --- a/build/android/test_package.py +++ b/build/android/test_package.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/build/android/test_package_executable.py b/build/android/test_package_executable.py index 6390735..badea4a 100644 --- a/build/android/test_package_executable.py +++ b/build/android/test_package_executable.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/build/android/test_result.py b/build/android/test_result.py index e5b0dc1..eb468f3 100644 --- a/build/android/test_result.py +++ b/build/android/test_result.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/build/android/valgrind_tools.py b/build/android/valgrind_tools.py index bd008dd..bc917e6 100644 --- a/build/android/valgrind_tools.py +++ b/build/android/valgrind_tools.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/build/compiler_version.py b/build/compiler_version.py index 69f0a50..9132261 100755 --- a/build/compiler_version.py +++ b/build/compiler_version.py @@ -1,6 +1,5 @@ -#!/usr/bin/python - -# Copyright (c) 2009 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/build/dir_exists.py b/build/dir_exists.py index d1c194f..0a89bc8 100644..100755 --- a/build/dir_exists.py +++ b/build/dir_exists.py @@ -1,10 +1,15 @@ #!/usr/bin/env python -# Copyright (c) 2009 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +"""Writes True if the argument is a directory.""" import os.path import sys -sys.stdout.write(str(os.path.isdir(sys.argv[1]))) -sys.exit(0) +def main(): + sys.stdout.write(str(os.path.isdir(sys.argv[1]))) + return 0 + +if __name__ == '__main__': + sys.exit(main()) diff --git a/build/download_nacl_toolchains.py b/build/download_nacl_toolchains.py index 1768d80..f988891 100755 --- a/build/download_nacl_toolchains.py +++ b/build/download_nacl_toolchains.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -36,7 +36,8 @@ def Main(args): sys.path.insert(0, nacl_build_dir) import download_toolchains download_toolchains.Main(args) + return 0 if __name__ == '__main__': - Main(sys.argv[1:]) + sys.exit(Main(sys.argv[1:])) diff --git a/build/escape_unicode.py b/build/escape_unicode.py index 5d4410e..859ba5d 100755 --- a/build/escape_unicode.py +++ b/build/escape_unicode.py @@ -1,5 +1,4 @@ -#!/usr/bin/python - +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -11,6 +10,7 @@ import optparse import os import sys + def main(argv): parser = optparse.OptionParser() usage = 'Usage: %prog -o <output_dir> <input_file>' @@ -37,6 +37,7 @@ def main(argv): os.path.splitext(in_filename)[0])) WriteEscapedFile(in_filename, out_filename) + return 0 def WriteEscapedFile(in_filename, out_filename): @@ -52,4 +53,4 @@ def WriteEscapedFile(in_filename, out_filename): if __name__ == '__main__': - exit(main(sys.argv)) + sys.exit(main(sys.argv)) diff --git a/build/extract_from_cab.py b/build/extract_from_cab.py index fd99184..9320462 100644..100755 --- a/build/extract_from_cab.py +++ b/build/extract_from_cab.py @@ -1,27 +1,35 @@ #!/usr/bin/env python -# Copyright (c) 2009 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# Extracts a single file from a CAB archive. +"""Extracts a single file from a CAB archive.""" import os import subprocess import sys -if len(sys.argv) != 4: - print 'Usage: extract_from_cab.py cab_path archived_file output_dir' - sys.exit(1) -[cab_path, archived_file, output_dir] = sys.argv[1:] +def main(): + if len(sys.argv) != 4: + print 'Usage: extract_from_cab.py cab_path archived_file output_dir' + return 1 -# Invoke the Windows expand utility to extract the file. -level = subprocess.call(['expand', cab_path, '-F:' + archived_file, output_dir]) -if level != 0: - sys.exit(level) + [cab_path, archived_file, output_dir] = sys.argv[1:] -# The expand utility preserves the modification date and time of the archived -# file. Touch the extracted file. This helps build systems that compare the -# modification times of input and output files to determine whether to do an -# action. -os.utime(os.path.join(output_dir, archived_file), None) + # Invoke the Windows expand utility to extract the file. + level = subprocess.call( + ['expand', cab_path, '-F:' + archived_file, output_dir]) + if level != 0: + return level + + # The expand utility preserves the modification date and time of the archived + # file. Touch the extracted file. This helps build systems that compare the + # modification times of input and output files to determine whether to do an + # action. + os.utime(os.path.join(output_dir, archived_file), None) + return 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/build/linux/rewrite_dirs.py b/build/linux/rewrite_dirs.py index 9e166d0..30f22f0 100755 --- a/build/linux/rewrite_dirs.py +++ b/build/linux/rewrite_dirs.py @@ -1,5 +1,5 @@ -#!/usr/bin/python -# Copyright (c) 2009 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -31,6 +31,7 @@ def RewritePath(path, opts): else: return path + def RewriteLine(line, opts): """Rewrites all the paths in recognized options.""" args = line.split() @@ -53,6 +54,7 @@ def RewriteLine(line, opts): return ' '.join(args) + def main(argv): parser = optparse.OptionParser() parser.add_option('-s', '--sysroot', default='/', help='sysroot to prepend') @@ -64,5 +66,6 @@ def main(argv): print line return 0 + if __name__ == '__main__': sys.exit(main(sys.argv)) diff --git a/build/mac/change_mach_o_flags.py b/build/mac/change_mach_o_flags.py index 1dfe07f..c2aeaec 100755 --- a/build/mac/change_mach_o_flags.py +++ b/build/mac/change_mach_o_flags.py @@ -1,78 +1,77 @@ -#!/usr/bin/python - +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# Usage: change_mach_o_flags.py [--executable-heap] [--no-pie] <executable_path> -# -# Arranges for the executable at |executable_path| to have its data (heap) -# pages protected to prevent execution on Mac OS X 10.7 ("Lion"), and to have -# the PIE (position independent executable) bit set to enable ASLR (address -# space layout randomization). With --executable-heap or --no-pie, the -# respective bits are cleared instead of set, making the heap executable or -# disabling PIE/ASLR. -# -# This script is able to operate on thin (single-architecture) Mach-O files -# and fat (universal, multi-architecture) files. When operating on fat files, -# it will set or clear the bits for each architecture contained therein. -# -# NON-EXECUTABLE HEAP -# -# Traditionally in Mac OS X, 32-bit processes did not have data pages set to -# prohibit execution. Although user programs could call mprotect and -# mach_vm_protect to deny execution of code in data pages, the kernel would -# silently ignore such requests without updating the page tables, and the -# hardware would happily execute code on such pages. 64-bit processes were -# always given proper hardware protection of data pages. This behavior was -# controllable on a system-wide level via the vm.allow_data_exec sysctl, which -# is set by default to 1. The bit with value 1 (set by default) allows code -# execution on data pages for 32-bit processes, and the bit with value 2 -# (clear by default) does the same for 64-bit processes. -# -# In Mac OS X 10.7, executables can "opt in" to having hardware protection -# against code execution on data pages applied. This is done by setting a new -# bit in the |flags| field of an executable's |mach_header|. When -# MH_NO_HEAP_EXECUTION is set, proper protections will be applied, regardless -# of the setting of vm.allow_data_exec. See xnu-1699.22.73/osfmk/vm/vm_map.c -# override_nx and xnu-1699.22.73/bsd/kern/mach_loader.c load_machfile. -# -# The Apple toolchain has been revised to set the MH_NO_HEAP_EXECUTION when -# producing executables, provided that -allow_heap_execute is not specified -# at link time. Only linkers shipping with Xcode 4.0 and later (ld64-123.2 and -# later) have this ability. See ld64-123.2.1/src/ld/Options.cpp -# Options::reconfigureDefaults() and -# ld64-123.2.1/src/ld/HeaderAndLoadCommands.hpp -# HeaderAndLoadCommandsAtom<A>::flags(). -# -# This script sets the MH_NO_HEAP_EXECUTION bit on Mach-O executables. It is -# intended for use with executables produced by a linker that predates Apple's -# modifications to set this bit itself. It is also useful for setting this bit -# for non-i386 executables, including x86_64 executables. Apple's linker only -# sets it for 32-bit i386 executables, presumably under the assumption that -# the value of vm.allow_data_exec is set in stone. However, if someone were to -# change vm.allow_data_exec to 2 or 3, 64-bit x86_64 executables would run -# without hardware protection against code execution on data pages. This -# script can set the bit for x86_64 executables, guaranteeing that they run -# with appropriate protection even when vm.allow_data_exec has been tampered -# with. -# -# POSITION-INDEPENDENT EXECUTABLES/ADDRESS SPACE LAYOUT RANDOMIZATION -# -# This script sets or clears the MH_PIE bit in an executable's Mach-O header, -# enabling or disabling position independence on Mac OS X 10.5 and later. -# Processes running position-independent executables have varying levels of -# ASLR protection depending on the OS release. The main executable's load -# address, shared library load addresess, and the heap and stack base -# addresses may be randomized. Position-independent executables are produced -# by supplying the -pie flag to the linker (or defeated by supplying -no_pie). -# Executables linked with a deployment target of 10.7 or higher have PIE on -# by default. -# -# This script is never strictly needed during the build to enable PIE, as all -# linkers used are recent enough to support -pie. However, it's used to -# disable the PIE bit as needed on already-linked executables. - +"""Usage: change_mach_o_flags.py [--executable-heap] [--no-pie] <executablepath> + +Arranges for the executable at |executable_path| to have its data (heap) +pages protected to prevent execution on Mac OS X 10.7 ("Lion"), and to have +the PIE (position independent executable) bit set to enable ASLR (address +space layout randomization). With --executable-heap or --no-pie, the +respective bits are cleared instead of set, making the heap executable or +disabling PIE/ASLR. + +This script is able to operate on thin (single-architecture) Mach-O files +and fat (universal, multi-architecture) files. When operating on fat files, +it will set or clear the bits for each architecture contained therein. + +NON-EXECUTABLE HEAP + +Traditionally in Mac OS X, 32-bit processes did not have data pages set to +prohibit execution. Although user programs could call mprotect and +mach_vm_protect to deny execution of code in data pages, the kernel would +silently ignore such requests without updating the page tables, and the +hardware would happily execute code on such pages. 64-bit processes were +always given proper hardware protection of data pages. This behavior was +controllable on a system-wide level via the vm.allow_data_exec sysctl, which +is set by default to 1. The bit with value 1 (set by default) allows code +execution on data pages for 32-bit processes, and the bit with value 2 +(clear by default) does the same for 64-bit processes. + +In Mac OS X 10.7, executables can "opt in" to having hardware protection +against code execution on data pages applied. This is done by setting a new +bit in the |flags| field of an executable's |mach_header|. When +MH_NO_HEAP_EXECUTION is set, proper protections will be applied, regardless +of the setting of vm.allow_data_exec. See xnu-1699.22.73/osfmk/vm/vm_map.c +override_nx and xnu-1699.22.73/bsd/kern/mach_loader.c load_machfile. + +The Apple toolchain has been revised to set the MH_NO_HEAP_EXECUTION when +producing executables, provided that -allow_heap_execute is not specified +at link time. Only linkers shipping with Xcode 4.0 and later (ld64-123.2 and +later) have this ability. See ld64-123.2.1/src/ld/Options.cpp +Options::reconfigureDefaults() and +ld64-123.2.1/src/ld/HeaderAndLoadCommands.hpp +HeaderAndLoadCommandsAtom<A>::flags(). + +This script sets the MH_NO_HEAP_EXECUTION bit on Mach-O executables. It is +intended for use with executables produced by a linker that predates Apple's +modifications to set this bit itself. It is also useful for setting this bit +for non-i386 executables, including x86_64 executables. Apple's linker only +sets it for 32-bit i386 executables, presumably under the assumption that +the value of vm.allow_data_exec is set in stone. However, if someone were to +change vm.allow_data_exec to 2 or 3, 64-bit x86_64 executables would run +without hardware protection against code execution on data pages. This +script can set the bit for x86_64 executables, guaranteeing that they run +with appropriate protection even when vm.allow_data_exec has been tampered +with. + +POSITION-INDEPENDENT EXECUTABLES/ADDRESS SPACE LAYOUT RANDOMIZATION + +This script sets or clears the MH_PIE bit in an executable's Mach-O header, +enabling or disabling position independence on Mac OS X 10.5 and later. +Processes running position-independent executables have varying levels of +ASLR protection depending on the OS release. The main executable's load +address, shared library load addresess, and the heap and stack base +addresses may be randomized. Position-independent executables are produced +by supplying the -pie flag to the linker (or defeated by supplying -no_pie). +Executables linked with a deployment target of 10.7 or higher have PIE on +by default. + +This script is never strictly needed during the build to enable PIE, as all +linkers used are recent enough to support -pie. However, it's used to +disable the PIE bit as needed on already-linked executables. +""" import optparse import os @@ -267,8 +266,8 @@ def main(me, args): raise MachOError, '%s is not a Mach-O or fat file' % executable_file executable_file.close() - return 0 + if __name__ == '__main__': sys.exit(main(sys.argv[0], sys.argv[1:])) diff --git a/build/scan_sources.py b/build/scan_sources.py index 60febef..2b0e806 100755 --- a/build/scan_sources.py +++ b/build/scan_sources.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -233,4 +233,3 @@ def Main(argv): if __name__ == '__main__': sys.exit(Main(sys.argv)) - diff --git a/build/scan_sources_test.py b/build/scan_sources_test.py index 233d017..0d98030 100755 --- a/build/scan_sources_test.py +++ b/build/scan_sources_test.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -89,4 +89,3 @@ Not if __name__ == '__main__': unittest.main() - |