From 130703a37382e411390e6db171e9100a8f95cf38 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 24 Mar 2023 10:46:59 -0700 Subject: [PATCH] Delete old dependency to bazel's //tools/objc Followup to https://github.com/bazelbuild/bazel/pull/16619. PiperOrigin-RevId: 519183744 Change-Id: I13e4d00d679e1c1150c309264dc5fd3a980eb221 --- src/test/shell/bazel/bazel_tools_test.sh | 4 +- tools/objc/libtool.sh | 141 ----------------------- tools/objc/make_hashed_objlist.py | 58 ---------- 3 files changed, 2 insertions(+), 201 deletions(-) delete mode 100755 tools/objc/libtool.sh delete mode 100644 tools/objc/make_hashed_objlist.py diff --git a/src/test/shell/bazel/bazel_tools_test.sh b/src/test/shell/bazel/bazel_tools_test.sh index 91a3574b6326ee..6e180618beabef 100755 --- a/src/test/shell/bazel/bazel_tools_test.sh +++ b/src/test/shell/bazel/bazel_tools_test.sh @@ -21,8 +21,8 @@ source "${CURRENT_DIR}/../integration_test_setup.sh" \ function test_build_objc_tools() { # TODO(cparsons): Test building tools/objc/... - bazel build @bazel_tools//tools/objc:make_hashed_objlist.py \ - || fail "should build tools/objc/make_hashed_objlist.py" + bazel build @bazel_tools//tools/objc:j2objc_dead_code_pruner_binary.py \ + || fail "should build tools/objc/j2objc_dead_code_pruner_binary.py" } # Test that verifies @bazel_tools//tools:bzl_srcs contains all .bzl source diff --git a/tools/objc/libtool.sh b/tools/objc/libtool.sh deleted file mode 100755 index 2b7282d39fdd3f..00000000000000 --- a/tools/objc/libtool.sh +++ /dev/null @@ -1,141 +0,0 @@ -#!/bin/bash -# -# Copyright 2016 The Bazel Authors. All rights reserved. -# -# 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. -# -# libtool.sh runs the command passed to it using "xcrunwrapper libtool". -# -# It creates symbolic links for all input files with a path-hash appended -# to their original name (foo.o becomes foo_{md5sum}.o). This is to circumvent -# a bug in the original libtool that arises when two input files have the same -# base name (even if they are in different directories). - -set -eu - -# A trick to allow invoking this script in multiple contexts. -if [ -z ${MY_LOCATION+x} ]; then - if [ -d "$0.runfiles/" ]; then - MY_LOCATION="$0.runfiles/bazel_tools/tools/objc" - else - MY_LOCATION="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - fi -fi - -function invoke_libtool() { - # Just invoke libtool via xcrunwrapper - "${MY_LOCATION}/xcrunwrapper.sh" libtool "$@" \ - 2> >(grep -v "the table of contents is empty (no object file members in the"` - `" library define global symbols)$" >&2) - # ^ Filtering a warning that's unlikely to indicate a real issue - # ...and not silencable via a flag. -} - -if [ ! -f "${MY_LOCATION}"/libtool_check_unique ] ; then - echo "libtool_check_unique not found. Please file an issue at github.com/bazelbuild/bazel" - exit 1 -elif "${MY_LOCATION}"/libtool_check_unique "$@"; then - # If there are no duplicate .o basenames, - # libtool can be invoked with the original arguments. - invoke_libtool "$@" - exit -fi - -TEMPDIR="$(mktemp -d "${TMPDIR:-/tmp}/libtool.XXXXXXXX")" -trap 'rm -rf "$TEMPDIR"' EXIT - -# Creates a symbolic link to the input argument file and returns the symlink -# file path. -function hash_objfile() { - ORIGINAL_NAME="$1" - ORIGINAL_HASH="$(/sbin/md5 -qs "${ORIGINAL_NAME}")" - SYMLINK_NAME="${TEMPDIR}/$(basename "${ORIGINAL_NAME%.o}_${ORIGINAL_HASH}.o")" - if [[ ! -e "$SYMLINK_NAME" ]]; then - case "${ORIGINAL_NAME}" in - /*) ln -sf "$ORIGINAL_NAME" "$SYMLINK_NAME" ;; - *) ln -sf "$(pwd)/$ORIGINAL_NAME" "$SYMLINK_NAME" ;; - esac - fi - echo "$SYMLINK_NAME" -} - -python_executable=/usr/bin/python3 -if [[ ! -x "$python_executable" ]]; then - python_executable=python3 -fi - -ARGS=() -handle_filelist=0 -keep_next=0 - -function parse_option() { - local -r ARG="$1" - if [[ "$handle_filelist" == "1" ]]; then - handle_filelist=0 - HASHED_FILELIST="${ARG%.objlist}_hashes.objlist" - rm -f "${HASHED_FILELIST}" - # Use python helper script for fast md5 calculation of many strings. - "$python_executable" "${MY_LOCATION}/make_hashed_objlist.py" \ - "${ARG}" "${HASHED_FILELIST}" "${TEMPDIR}" - ARGS+=("${HASHED_FILELIST}") - elif [[ "$keep_next" == "1" ]]; then - keep_next=0 - ARGS+=("$ARG") - else - case "${ARG}" in - # Filelist flag, need to symlink each input in the contents of file and - # pass a new filelist which contains the symlinks. - -filelist) - handle_filelist=1 - ARGS+=("${ARG}") - ;; - @*) - path="${ARG:1}" - while IFS= read -r opt - do - parse_option "$opt" - done < "$path" || exit 1 - ;; - # Flags with no args - -static|-s|-a|-c|-L|-T|-D|-v|-no_warning_for_no_symbols) - ARGS+=("${ARG}") - ;; - # Single-arg flags - -arch_only|-syslibroot|-o) - keep_next=1 - ARGS+=("${ARG}") - ;; - # Any remaining flags are unexpected and may ruin flag parsing. - # Add any flags here to libtool_check_unique.cc as well - -*) - echo "Unrecognized libtool flag ${ARG}" - exit 1 - ;; - # Archive inputs can remain untouched, as they come from other targets. - *.a) - ARGS+=("${ARG}") - ;; - # Remaining args are input objects - *) - ARGS+=("$(hash_objfile "${ARG}")") - ;; - esac - fi -} - -for arg in "$@"; do - parse_option "$arg" -done - -printf '%s\n' "${ARGS[@]}" > "$TEMPDIR/processed.params" -invoke_libtool "@$TEMPDIR/processed.params" diff --git a/tools/objc/make_hashed_objlist.py b/tools/objc/make_hashed_objlist.py deleted file mode 100644 index bb326423edc24f..00000000000000 --- a/tools/objc/make_hashed_objlist.py +++ /dev/null @@ -1,58 +0,0 @@ -# pylint: disable=g-bad-file-header -# Copyright 2016 The Bazel Authors. All rights reserved. -# -# 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. - -"""Creates symbolic links for .o files with hashcode. - -This script reads the file list containing the input files, creates -symbolic links with a path-hash appended to their original name (foo.o -becomes foo_{md5sum}.o), then saves the list of symbolic links to another -file. - -The symbolic links are created into the given temporary directory. There is -no guarantee that we can write to the directory that contained the inputs to -this script. - -This is to circumvent a bug in the original libtool that arises when two -input files have the same base name (even if they are in different -directories). -""" - -import hashlib -import os -import sys - - -def main(): - outdir = sys.argv[3] - with open(sys.argv[1]) as obj_file_list: - with open(sys.argv[2], 'w') as hashed_obj_file_list: - for line in obj_file_list: - obj_file_path = line.rstrip('\n') - - hashed_obj_file_name = '%s_%s.o' % ( - os.path.basename(os.path.splitext(obj_file_path)[0]), - hashlib.md5(obj_file_path.encode('utf-8')).hexdigest()) - hashed_obj_file_path = os.path.join(outdir, hashed_obj_file_name) - - hashed_obj_file_list.write(hashed_obj_file_path + '\n') - - # Create symlink only if the symlink doesn't exist. - if not os.path.exists(hashed_obj_file_path): - os.symlink(os.path.abspath(obj_file_path), - hashed_obj_file_path) - - -if __name__ == '__main__': - main()