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