• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright 2022 The Android Open Source Project
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#      http://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
16# Formats source files according to Google's style guide.
17
18REPO=$(dirname "$0")/../../..
19OS=$(uname | tr '[:upper:]' '[:lower:]') # The possible values are "linux" and "darwin".
20
21# Run clang-format.
22find $REPO/tools/netsim/src \( -name '*.cc' -o -name '*.h' \) \
23  -exec clang-format -i {} \;
24
25find $REPO/tools/netsim/proto \( -name '*.proto' \) \
26  -exec clang-format -i {} \;
27
28# Format rust.
29RUSTFMT=$REPO/prebuilts/rust/$OS-x86/stable/rustfmt
30find $REPO/tools/netsim/rust \( \
31  -path $REPO/tools/netsim/rust/target -prune -false \
32  -o -name '*.rs' \) \
33  -exec $RUSTFMT --files-with-diff {} \;
34
35# Format TypeScript.
36find $REPO/tools/netsim/ui/ts \( -name '*.ts' \) \
37  -exec clang-format -i {} \;
38
39# Format Java (go/google-java-format).
40find $REPO/tools/netsim \( -name '*.java' \) \
41  -exec google-java-format --dry-run {} \;
42find $REPO/tools/netsim \( -name '*.java' \) \
43  -exec google-java-format -i {} \;
44
45# Format Python (go/pyformat).
46pyformat --in_place --alsologtostderr --noshowprefixforinfo \
47  --recursive $REPO/tools/netsim
48
49# Run cmake-format.
50find $REPO/tools/netsim \( -name 'CMakeLists.txt' \) \
51  -exec cmake-format -i {} \;
52find $REPO/tools/netsim/cmake \( -name "*.cmake" \) \
53  -exec cmake-format -i {} \;
54
55# Run bpfmt to format Android.bp if in aosp_master repo.
56BPFMT=$REPO/prebuilts/build-tools/$OS-x86/bin/bpfmt
57if [ -f "$BPFMT" ]; then
58  find $find \( -name "Android.bp" \) \
59    -exec $BPFMT -w {} \;
60fi
61