blob: 65c90f19c1d2212f3bbb205931b0fdde5da6e56c [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
xiaohu.huangda47f672024-12-06 15:16:42 +080023- aml_dirs_tracer:Trace the dependent dirs of current project.
24- aml_files_tracer:Trace the dependent files of current project.
25
xiaohu.huangba019752022-11-29 11:23:09 +080026EOF
27}
28
29function aml_top
30{
31 local TOPFILE=build_system/cmake/root.cmake
32 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
33 (cd $TOP; PWD= /bin/pwd)
34 else
35 if [ -f $TOPFILE ] ; then
36 PWD= /bin/pwd
37 else
38 local HERE=$PWD
39 local T=
40 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
41 \cd ..
42 T=`PWD= /bin/pwd -P`
43 done
44 \cd $HERE
45 if [ -f "$T/$TOPFILE" ]; then
46 echo $T
47 fi
48 fi
49 fi
50}
51
52function aml_trunk_remote
53{
54 trunk_remote_name=origin
55
56 echo $trunk_remote_name
57}
58
59function aml_trunk_branch
60{
61 trunk_branch_name=projects/amlogic-dev
62
63 echo $trunk_branch_name
64}
65
66function aml_trunk_name
67{
68 trunk_name=$(aml_trunk_remote)/$(aml_trunk_branch)
69
70 echo $trunk_name
71}
72
73function aml_root()
74{
75 local T=$(aml_top)
76 if [ "$T" ]; then
77 if [ "$1" ]; then
78 \cd $(gettop)/$1
79 else
80 \cd $(gettop)
81 fi
82 else
83 echo "Locate the top dir failed."
84 fi
85}
86
87function aml_reset()
88{
89 git_list_dir=$(find $(aml_top) ! -path "*/.repo/*" -name .git | xargs dirname)
90
91 for PRODUCT_PATH in $git_list_dir;
92 do
93 if [ -d $PRODUCT_PATH ];then
94 echo product:${PRODUCT_PATH#*"$(aml_top)/"}
95 git -C $PRODUCT_PATH reset -q --hard $(aml_trunk_name)
96 fi
97 done
98}
99
100function aml_checkout()
101{
102 git_list_dir=$(find $(aml_top) ! -path "*/.repo/*" -name .git | xargs dirname)
103
104 for PRODUCT_PATH in $git_list_dir;
105 do
106 if [ -d $PRODUCT_PATH ];then
107 echo product:${PRODUCT_PATH#*"$(aml_top)/"}
108 git -C $PRODUCT_PATH checkout $(aml_trunk_branch)
109 if [ "$?" != 0 ]; then
110 git -C $PRODUCT_PATH checkout --track $(aml_trunk_name)
111 fi
112 fi
113 done
114}
115
116function aml_git()
117{
118 git_list_dir=$(find $(aml_top) ! -path "*/.repo/*" -name .git | xargs dirname)
119
120 for PRODUCT_PATH in $git_list_dir;
121 do
122 if [ -d $PRODUCT_PATH ];then
123 echo product:${PRODUCT_PATH#*"$(aml_top)/"}
124 git -C $PRODUCT_PATH $@
125 fi
126 done
127}
128
129function aml_pull()
130{
131 aml_checkout
132 aml_git pull --rebase
133}
134
135function aml_cgrep()
136{
137 find $(aml_top) -name .repo -prune -o -name .git -prune -o -name output -prune -o -type f \
138 \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) \
139 -exec grep --color -n "$@" {} +
140}
141
142function aml_kgrep()
143{
144 find $(aml_top) -name .repo -prune -o -name .git -prune -o -name output -prune -o -type f \
145 \( -name 'Kconfig' \) -exec grep --color -n "$@" {} +
146}
147
148function aml_cmgrep()
149{
150 find $(aml_top) -name .repo -prune -o -name .git -prune -o -name output -prune -o -type f \
151 \( -name 'CMakeLists.txt' \) -exec grep --color -n "$@" {} +
152}
153
154function aml_shgrep()
155{
156 find $(aml_top) -name .repo -prune -o -name .git -prune -o -name output -prune -o -type f \
157 \( -name '*.sh' \) -exec grep --color -n "$@" {} +
158}
159
xiaohu.huangda47f672024-12-06 15:16:42 +0800160function aml_dirs_tracer()
161{
162 deps_file="$(aml_top)/output/$ARCH-$BOARD-$PRODUCT/$KERNEL/build.ninja"
163 if [ -f $deps_file ]; then
164 keyword="DEP_FILE ="
165 grep "$keyword" -nR "$deps_file" | sed -n 's|.*obj/\(.*\)/CMakeFiles.*|\1|p' | sort | uniq
166 else
167 echo "Not found $deps_file,make project please."
168 fi
169}
170
171function aml_files_tracer()
172{
173 deps_file="$(aml_top)/output/$ARCH-$BOARD-$PRODUCT/$KERNEL/build.ninja"
174 if [ -f $deps_file ]; then
175 keyword="DEP_FILE ="
176 grep "$keyword" -nR "$deps_file" | sort | uniq
177 else
178 echo "Not found $deps_file,make project please."
179 fi
180}