oss-fuzz/infra/base-images/base-sanitizer-libs-builder/wrapper_utils.py

47 lines
1.5 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
Clean up MemorySanitizer library warnings (#4694) * Update infra/base-images/all.sh Add build of base-sanitizer-libs-builder and msan-libs-builder to this shell script. * msan: Don't warn on un-instrumented standard libs These libraries do not need to be built with instrumentation, because MemorySanitizer includes interceptors for them. * Fix indentation * Add missing docstrings * Fix unused variable * Fix invalid names * Install python-apt on CI * Revert "Install python-apt on CI" This reverts commit d3da49cf90f138674c1a8bcbdca2f0dfe6c385d1. * Install and use python-apt in system directory * Revert "Install and use python-apt in system directory" This reverts commit e0ede101fbdfbf82da5f32d0a206da247e6dde98. * Build python-apt from source * Check out correct version of python-apt * Fix octal literals * More indentation fixes * Add more missing docstrings * Change variable names of opened files * Remove unused import * Ignore lints about package.Package API * Fix or ignore remaining invalid names * Fix apparent typo in compiler_wrapper_test.py -z should precede a keyword, not a long option * Fix use of xrange * Style fixes, compiler_wrapper * Fix apparent error in compiler_wrapper_test.py Similar to the previous error, the test case would pass "-z --no-undefined" to the linker. "-z" only has an effect when it is followed by a keyword, otherwise ld ignores it and prints a warning message. In this test case, "-z" and "--no-undefined" were passed in two separate "-Wl," compiler arguments, but they reflect a common issue. * Add missing license header * Rename more functions * Better name for global variable * Rename methods of Package * Rename functions in msan_builder.py * Fix invalid variable names * Fix useless-object-inheritance * pylint: Fixes for Package and its subclasses * Remove unused imports * Indentation fixes * Fix too-may-locals error in msan_build.py * Add missing docstrings
2020-12-02 20:52:36 +00:00
"""Functions to help with wrapper scripts."""
from __future__ import print_function
import os
import subprocess
Clean up MemorySanitizer library warnings (#4694) * Update infra/base-images/all.sh Add build of base-sanitizer-libs-builder and msan-libs-builder to this shell script. * msan: Don't warn on un-instrumented standard libs These libraries do not need to be built with instrumentation, because MemorySanitizer includes interceptors for them. * Fix indentation * Add missing docstrings * Fix unused variable * Fix invalid names * Install python-apt on CI * Revert "Install python-apt on CI" This reverts commit d3da49cf90f138674c1a8bcbdca2f0dfe6c385d1. * Install and use python-apt in system directory * Revert "Install and use python-apt in system directory" This reverts commit e0ede101fbdfbf82da5f32d0a206da247e6dde98. * Build python-apt from source * Check out correct version of python-apt * Fix octal literals * More indentation fixes * Add more missing docstrings * Change variable names of opened files * Remove unused import * Ignore lints about package.Package API * Fix or ignore remaining invalid names * Fix apparent typo in compiler_wrapper_test.py -z should precede a keyword, not a long option * Fix use of xrange * Style fixes, compiler_wrapper * Fix apparent error in compiler_wrapper_test.py Similar to the previous error, the test case would pass "-z --no-undefined" to the linker. "-z" only has an effect when it is followed by a keyword, otherwise ld ignores it and prints a warning message. In this test case, "-z" and "--no-undefined" were passed in two separate "-Wl," compiler arguments, but they reflect a common issue. * Add missing license header * Rename more functions * Better name for global variable * Rename methods of Package * Rename functions in msan_builder.py * Fix invalid variable names * Fix useless-object-inheritance * pylint: Fixes for Package and its subclasses * Remove unused imports * Indentation fixes * Fix too-may-locals error in msan_build.py * Add missing docstrings
2020-12-02 20:52:36 +00:00
def dpkg_host_architecture():
"""Return the host architecture."""
Clean up MemorySanitizer library warnings (#4694) * Update infra/base-images/all.sh Add build of base-sanitizer-libs-builder and msan-libs-builder to this shell script. * msan: Don't warn on un-instrumented standard libs These libraries do not need to be built with instrumentation, because MemorySanitizer includes interceptors for them. * Fix indentation * Add missing docstrings * Fix unused variable * Fix invalid names * Install python-apt on CI * Revert "Install python-apt on CI" This reverts commit d3da49cf90f138674c1a8bcbdca2f0dfe6c385d1. * Install and use python-apt in system directory * Revert "Install and use python-apt in system directory" This reverts commit e0ede101fbdfbf82da5f32d0a206da247e6dde98. * Build python-apt from source * Check out correct version of python-apt * Fix octal literals * More indentation fixes * Add more missing docstrings * Change variable names of opened files * Remove unused import * Ignore lints about package.Package API * Fix or ignore remaining invalid names * Fix apparent typo in compiler_wrapper_test.py -z should precede a keyword, not a long option * Fix use of xrange * Style fixes, compiler_wrapper * Fix apparent error in compiler_wrapper_test.py Similar to the previous error, the test case would pass "-z --no-undefined" to the linker. "-z" only has an effect when it is followed by a keyword, otherwise ld ignores it and prints a warning message. In this test case, "-z" and "--no-undefined" were passed in two separate "-Wl," compiler arguments, but they reflect a common issue. * Add missing license header * Rename more functions * Better name for global variable * Rename methods of Package * Rename functions in msan_builder.py * Fix invalid variable names * Fix useless-object-inheritance * pylint: Fixes for Package and its subclasses * Remove unused imports * Indentation fixes * Fix too-may-locals error in msan_build.py * Add missing docstrings
2020-12-02 20:52:36 +00:00
return subprocess.check_output(['dpkg-architecture',
'-qDEB_HOST_GNU_TYPE']).strip()
Clean up MemorySanitizer library warnings (#4694) * Update infra/base-images/all.sh Add build of base-sanitizer-libs-builder and msan-libs-builder to this shell script. * msan: Don't warn on un-instrumented standard libs These libraries do not need to be built with instrumentation, because MemorySanitizer includes interceptors for them. * Fix indentation * Add missing docstrings * Fix unused variable * Fix invalid names * Install python-apt on CI * Revert "Install python-apt on CI" This reverts commit d3da49cf90f138674c1a8bcbdca2f0dfe6c385d1. * Install and use python-apt in system directory * Revert "Install and use python-apt in system directory" This reverts commit e0ede101fbdfbf82da5f32d0a206da247e6dde98. * Build python-apt from source * Check out correct version of python-apt * Fix octal literals * More indentation fixes * Add more missing docstrings * Change variable names of opened files * Remove unused import * Ignore lints about package.Package API * Fix or ignore remaining invalid names * Fix apparent typo in compiler_wrapper_test.py -z should precede a keyword, not a long option * Fix use of xrange * Style fixes, compiler_wrapper * Fix apparent error in compiler_wrapper_test.py Similar to the previous error, the test case would pass "-z --no-undefined" to the linker. "-z" only has an effect when it is followed by a keyword, otherwise ld ignores it and prints a warning message. In this test case, "-z" and "--no-undefined" were passed in two separate "-Wl," compiler arguments, but they reflect a common issue. * Add missing license header * Rename more functions * Better name for global variable * Rename methods of Package * Rename functions in msan_builder.py * Fix invalid variable names * Fix useless-object-inheritance * pylint: Fixes for Package and its subclasses * Remove unused imports * Indentation fixes * Fix too-may-locals error in msan_build.py * Add missing docstrings
2020-12-02 20:52:36 +00:00
def install_wrapper(bin_dir, name, contents, extra_names=None):
"""Install a custom wrapper script into |bin_dir|."""
path = os.path.join(bin_dir, name)
Clean up MemorySanitizer library warnings (#4694) * Update infra/base-images/all.sh Add build of base-sanitizer-libs-builder and msan-libs-builder to this shell script. * msan: Don't warn on un-instrumented standard libs These libraries do not need to be built with instrumentation, because MemorySanitizer includes interceptors for them. * Fix indentation * Add missing docstrings * Fix unused variable * Fix invalid names * Install python-apt on CI * Revert "Install python-apt on CI" This reverts commit d3da49cf90f138674c1a8bcbdca2f0dfe6c385d1. * Install and use python-apt in system directory * Revert "Install and use python-apt in system directory" This reverts commit e0ede101fbdfbf82da5f32d0a206da247e6dde98. * Build python-apt from source * Check out correct version of python-apt * Fix octal literals * More indentation fixes * Add more missing docstrings * Change variable names of opened files * Remove unused import * Ignore lints about package.Package API * Fix or ignore remaining invalid names * Fix apparent typo in compiler_wrapper_test.py -z should precede a keyword, not a long option * Fix use of xrange * Style fixes, compiler_wrapper * Fix apparent error in compiler_wrapper_test.py Similar to the previous error, the test case would pass "-z --no-undefined" to the linker. "-z" only has an effect when it is followed by a keyword, otherwise ld ignores it and prints a warning message. In this test case, "-z" and "--no-undefined" were passed in two separate "-Wl," compiler arguments, but they reflect a common issue. * Add missing license header * Rename more functions * Better name for global variable * Rename methods of Package * Rename functions in msan_builder.py * Fix invalid variable names * Fix useless-object-inheritance * pylint: Fixes for Package and its subclasses * Remove unused imports * Indentation fixes * Fix too-may-locals error in msan_build.py * Add missing docstrings
2020-12-02 20:52:36 +00:00
with open(path, 'w') as wrapper_file:
wrapper_file.write(contents)
Clean up MemorySanitizer library warnings (#4694) * Update infra/base-images/all.sh Add build of base-sanitizer-libs-builder and msan-libs-builder to this shell script. * msan: Don't warn on un-instrumented standard libs These libraries do not need to be built with instrumentation, because MemorySanitizer includes interceptors for them. * Fix indentation * Add missing docstrings * Fix unused variable * Fix invalid names * Install python-apt on CI * Revert "Install python-apt on CI" This reverts commit d3da49cf90f138674c1a8bcbdca2f0dfe6c385d1. * Install and use python-apt in system directory * Revert "Install and use python-apt in system directory" This reverts commit e0ede101fbdfbf82da5f32d0a206da247e6dde98. * Build python-apt from source * Check out correct version of python-apt * Fix octal literals * More indentation fixes * Add more missing docstrings * Change variable names of opened files * Remove unused import * Ignore lints about package.Package API * Fix or ignore remaining invalid names * Fix apparent typo in compiler_wrapper_test.py -z should precede a keyword, not a long option * Fix use of xrange * Style fixes, compiler_wrapper * Fix apparent error in compiler_wrapper_test.py Similar to the previous error, the test case would pass "-z --no-undefined" to the linker. "-z" only has an effect when it is followed by a keyword, otherwise ld ignores it and prints a warning message. In this test case, "-z" and "--no-undefined" were passed in two separate "-Wl," compiler arguments, but they reflect a common issue. * Add missing license header * Rename more functions * Better name for global variable * Rename methods of Package * Rename functions in msan_builder.py * Fix invalid variable names * Fix useless-object-inheritance * pylint: Fixes for Package and its subclasses * Remove unused imports * Indentation fixes * Fix too-may-locals error in msan_build.py * Add missing docstrings
2020-12-02 20:52:36 +00:00
os.chmod(path, 0o755)
if extra_names:
Clean up MemorySanitizer library warnings (#4694) * Update infra/base-images/all.sh Add build of base-sanitizer-libs-builder and msan-libs-builder to this shell script. * msan: Don't warn on un-instrumented standard libs These libraries do not need to be built with instrumentation, because MemorySanitizer includes interceptors for them. * Fix indentation * Add missing docstrings * Fix unused variable * Fix invalid names * Install python-apt on CI * Revert "Install python-apt on CI" This reverts commit d3da49cf90f138674c1a8bcbdca2f0dfe6c385d1. * Install and use python-apt in system directory * Revert "Install and use python-apt in system directory" This reverts commit e0ede101fbdfbf82da5f32d0a206da247e6dde98. * Build python-apt from source * Check out correct version of python-apt * Fix octal literals * More indentation fixes * Add more missing docstrings * Change variable names of opened files * Remove unused import * Ignore lints about package.Package API * Fix or ignore remaining invalid names * Fix apparent typo in compiler_wrapper_test.py -z should precede a keyword, not a long option * Fix use of xrange * Style fixes, compiler_wrapper * Fix apparent error in compiler_wrapper_test.py Similar to the previous error, the test case would pass "-z --no-undefined" to the linker. "-z" only has an effect when it is followed by a keyword, otherwise ld ignores it and prints a warning message. In this test case, "-z" and "--no-undefined" were passed in two separate "-Wl," compiler arguments, but they reflect a common issue. * Add missing license header * Rename more functions * Better name for global variable * Rename methods of Package * Rename functions in msan_builder.py * Fix invalid variable names * Fix useless-object-inheritance * pylint: Fixes for Package and its subclasses * Remove unused imports * Indentation fixes * Fix too-may-locals error in msan_build.py * Add missing docstrings
2020-12-02 20:52:36 +00:00
create_symlinks(path, bin_dir, extra_names)
Clean up MemorySanitizer library warnings (#4694) * Update infra/base-images/all.sh Add build of base-sanitizer-libs-builder and msan-libs-builder to this shell script. * msan: Don't warn on un-instrumented standard libs These libraries do not need to be built with instrumentation, because MemorySanitizer includes interceptors for them. * Fix indentation * Add missing docstrings * Fix unused variable * Fix invalid names * Install python-apt on CI * Revert "Install python-apt on CI" This reverts commit d3da49cf90f138674c1a8bcbdca2f0dfe6c385d1. * Install and use python-apt in system directory * Revert "Install and use python-apt in system directory" This reverts commit e0ede101fbdfbf82da5f32d0a206da247e6dde98. * Build python-apt from source * Check out correct version of python-apt * Fix octal literals * More indentation fixes * Add more missing docstrings * Change variable names of opened files * Remove unused import * Ignore lints about package.Package API * Fix or ignore remaining invalid names * Fix apparent typo in compiler_wrapper_test.py -z should precede a keyword, not a long option * Fix use of xrange * Style fixes, compiler_wrapper * Fix apparent error in compiler_wrapper_test.py Similar to the previous error, the test case would pass "-z --no-undefined" to the linker. "-z" only has an effect when it is followed by a keyword, otherwise ld ignores it and prints a warning message. In this test case, "-z" and "--no-undefined" were passed in two separate "-Wl," compiler arguments, but they reflect a common issue. * Add missing license header * Rename more functions * Better name for global variable * Rename methods of Package * Rename functions in msan_builder.py * Fix invalid variable names * Fix useless-object-inheritance * pylint: Fixes for Package and its subclasses * Remove unused imports * Indentation fixes * Fix too-may-locals error in msan_build.py * Add missing docstrings
2020-12-02 20:52:36 +00:00
def create_symlinks(original_path, bin_dir, extra_names):
"""Create symlinks."""
for extra_name in extra_names:
extra_path = os.path.join(bin_dir, extra_name)
os.symlink(original_path, extra_path)