blob: 4e42548599eff20db80ba4734f6465919ecbf3f4 [file] [log] [blame]
xiaohu.huangba019752022-11-29 11:23:09 +08001#!/bin/bash
2#
3# Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
4#
5# SPDX-License-Identifier: MIT
6#
7
8function aml_help() {
9cat <<EOF
10
11- aml_root: Changes directory to the top of the tree, or a subdirectory.
12
13- aml_reset: Reset all repositories to remote branch among rtos sdk.
14- aml_checkout: Checkout trunk branch if track needed among rtos sdk.
15- aml_git: Execute git command for all repositories among rtos sdk.
16- aml_pull: Pull rebase all repositories among rtos sdk.
17
18- aml_cgrep: Greps on all local project C/C++ files.
19- aml_kgrep: Greps on all local project Kconfig files.
20- aml_cmgrep: Greps on all local project CMakelists.txt files.
21- aml_shgrep: Greps on all local project shell files.
22
23EOF
24}
25
26function aml_top
27{
28 local TOPFILE=build_system/cmake/root.cmake
29 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
30 (cd $TOP; PWD= /bin/pwd)
31 else
32 if [ -f $TOPFILE ] ; then
33 PWD= /bin/pwd
34 else
35 local HERE=$PWD
36 local T=
37 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
38 \cd ..
39 T=`PWD= /bin/pwd -P`
40 done
41 \cd $HERE
42 if [ -f "$T/$TOPFILE" ]; then
43 echo $T
44 fi
45 fi
46 fi
47}
48
49function aml_trunk_remote
50{
51 trunk_remote_name=origin
52
53 echo $trunk_remote_name
54}
55
56function aml_trunk_branch
57{
58 trunk_branch_name=projects/amlogic-dev
59
60 echo $trunk_branch_name
61}
62
63function aml_trunk_name
64{
65 trunk_name=$(aml_trunk_remote)/$(aml_trunk_branch)
66
67 echo $trunk_name
68}
69
70function aml_root()
71{
72 local T=$(aml_top)
73 if [ "$T" ]; then
74 if [ "$1" ]; then
75 \cd $(gettop)/$1
76 else
77 \cd $(gettop)
78 fi
79 else
80 echo "Locate the top dir failed."
81 fi
82}
83
84function aml_reset()
85{
86 git_list_dir=$(find $(aml_top) ! -path "*/.repo/*" -name .git | xargs dirname)
87
88 for PRODUCT_PATH in $git_list_dir;
89 do
90 if [ -d $PRODUCT_PATH ];then
91 echo product:${PRODUCT_PATH#*"$(aml_top)/"}
92 git -C $PRODUCT_PATH reset -q --hard $(aml_trunk_name)
93 fi
94 done
95}
96
97function aml_checkout()
98{
99 git_list_dir=$(find $(aml_top) ! -path "*/.repo/*" -name .git | xargs dirname)
100
101 for PRODUCT_PATH in $git_list_dir;
102 do
103 if [ -d $PRODUCT_PATH ];then
104 echo product:${PRODUCT_PATH#*"$(aml_top)/"}
105 git -C $PRODUCT_PATH checkout $(aml_trunk_branch)
106 if [ "$?" != 0 ]; then
107 git -C $PRODUCT_PATH checkout --track $(aml_trunk_name)
108 fi
109 fi
110 done
111}
112
113function aml_git()
114{
115 git_list_dir=$(find $(aml_top) ! -path "*/.repo/*" -name .git | xargs dirname)
116
117 for PRODUCT_PATH in $git_list_dir;
118 do
119 if [ -d $PRODUCT_PATH ];then
120 echo product:${PRODUCT_PATH#*"$(aml_top)/"}
121 git -C $PRODUCT_PATH $@
122 fi
123 done
124}
125
126function aml_pull()
127{
128 aml_checkout
129 aml_git pull --rebase
130}
131
132function aml_cgrep()
133{
134 find $(aml_top) -name .repo -prune -o -name .git -prune -o -name output -prune -o -type f \
135 \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) \
136 -exec grep --color -n "$@" {} +
137}
138
139function aml_kgrep()
140{
141 find $(aml_top) -name .repo -prune -o -name .git -prune -o -name output -prune -o -type f \
142 \( -name 'Kconfig' \) -exec grep --color -n "$@" {} +
143}
144
145function aml_cmgrep()
146{
147 find $(aml_top) -name .repo -prune -o -name .git -prune -o -name output -prune -o -type f \
148 \( -name 'CMakeLists.txt' \) -exec grep --color -n "$@" {} +
149}
150
151function aml_shgrep()
152{
153 find $(aml_top) -name .repo -prune -o -name .git -prune -o -name output -prune -o -type f \
154 \( -name '*.sh' \) -exec grep --color -n "$@" {} +
155}
156