xref: /aosp_15_r20/external/ruy/cmake/bazel_to_cmake.sh (revision bb86c7ed5fb1b98a7eac808e443a46cc8b90dfc0)
1*bb86c7edSAndroid Build Coastguard Worker#!/bin/bash
2*bb86c7edSAndroid Build Coastguard Worker# Copyright 2021 Google LLC
3*bb86c7edSAndroid Build Coastguard Worker#
4*bb86c7edSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
5*bb86c7edSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
6*bb86c7edSAndroid Build Coastguard Worker# You may obtain a copy of the License at
7*bb86c7edSAndroid Build Coastguard Worker#
8*bb86c7edSAndroid Build Coastguard Worker#      https://www.apache.org/licenses/LICENSE-2.0
9*bb86c7edSAndroid Build Coastguard Worker#
10*bb86c7edSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
11*bb86c7edSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
12*bb86c7edSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*bb86c7edSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
14*bb86c7edSAndroid Build Coastguard Worker# limitations under the License.
15*bb86c7edSAndroid Build Coastguard Worker
16*bb86c7edSAndroid Build Coastguard Workerthis_script_dir="$(dirname "$0")"
17*bb86c7edSAndroid Build Coastguard Worker
18*bb86c7edSAndroid Build Coastguard Workerroot_dir="$(git -C "${this_script_dir}" rev-parse --show-toplevel)"
19*bb86c7edSAndroid Build Coastguard Worker
20*bb86c7edSAndroid Build Coastguard Workerbuild_files="$(find "${root_dir}" -type f -name BUILD)"
21*bb86c7edSAndroid Build Coastguard Worker
22*bb86c7edSAndroid Build Coastguard Workerif ! command -v python3 &> /dev/null; then
23*bb86c7edSAndroid Build Coastguard Worker  python_command=python
24*bb86c7edSAndroid Build Coastguard Workerelse
25*bb86c7edSAndroid Build Coastguard Worker  python_command=python3
26*bb86c7edSAndroid Build Coastguard Workerfi
27*bb86c7edSAndroid Build Coastguard Worker
28*bb86c7edSAndroid Build Coastguard Workerfor build_file in ${build_files}; do
29*bb86c7edSAndroid Build Coastguard Worker    package_dir="$(dirname "${build_file}")"
30*bb86c7edSAndroid Build Coastguard Worker    if [[ "${package_dir}" == "${root_dir}" ]]; then
31*bb86c7edSAndroid Build Coastguard Worker      # The root CMakeLists.txt is not generated.
32*bb86c7edSAndroid Build Coastguard Worker      continue
33*bb86c7edSAndroid Build Coastguard Worker    fi
34*bb86c7edSAndroid Build Coastguard Worker    "${python_command}" "${this_script_dir}/bazel_to_cmake.py" "${root_dir}" "${package_dir}" > "${package_dir}/CMakeLists.txt"
35*bb86c7edSAndroid Build Coastguard Workerdone
36