blob: 15f414db8f095d6420d88972e60e5eee7b9545a6 [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001#!/bin/sh
2###############################################################################
3#
4# <:copyright-BRCM:2016:proprietary:standard
5#
6# Broadcom Ltd. Proprietary and Confidential.(c) 2016 Broadcom Ltd.
7# All Rights Reserved
8#
9# This program is the proprietary software of Broadcom Ltd. and/or its
10# licensors, and may only be used, duplicated, modified or distributed pursuant
11# to the terms and conditions of a separate, written license agreement executed
12# between you and Broadcom Ltd. (an "Authorized License"). Except as set forth in
13# an Authorized License, Broadcom Ltd. grants no license (express or implied), right
14# to use, or waiver of any kind with respect to the Software, and Broadcom Ltd.
15# expressly reserves all rights in and to the Software and all intellectual
16# property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE
17# NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY
18# BROADCOM LTD AND DISCONTINUE ALL USE OF THE SOFTWARE.
19#
20# Except as expressly set forth in the Authorized License,
21#
22# 1. This program, including its structure, sequence and organization,
23# constitutes the valuable trade secrets of Broadcom Ltd., and you shall use
24# all reasonable efforts to protect the confidentiality thereof, and to
25# use this information only in connection with your use of Broadcom Ltd.
26# integrated circuit products.
27#
28# 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29# AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
30# WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH
31# RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND
32# ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT,
33# FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR
34# COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE
35# TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF USE OR
36# PERFORMANCE OF THE SOFTWARE.
37#
38# 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR
39# ITS LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL,
40# INDIRECT, OR EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY
41# WAY RELATING TO YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN
42# IF BROADCOM HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES;
43# OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE
44# SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE LIMITATIONS
45# SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF ANY
46# LIMITED REMEDY.
47# :>
48#
49###############################################################################
50#
51# Script: update_copyright.sh
52#
53# Purpose: This script updates the copyright comment headers in
54# c/c++, shell script, and Makefiles. Depending on the options
55# specified below, this script will also automatically create a
56# Perforce changelist and checkout the files before updating the
57# copyright headers.
58#
59# Usage: ./update_copyright.sh [-c chglist num|"none"] <files>
60# Options:
61#
62# -c num|"none" If -c is specified with a Perforce changelist
63# number, then files that are updated by this
64# script will be put into the specified changelist.
65#
66# If '-c none' is specified, the script will not
67# execute any Perforce commands before updating the
68# copyright in files. The user is expected to checkout
69# the files prior to excuting this script.
70#
71# If -c is not specified (default), a new change list
72# is created and all updated files are put into the new
73# change list.
74#
75#
76# This script makes use of the following perl scripts:
77# strip_c_copyright.pl - Strips a copyright header from a c/c++ file.
78# strip_sh_copyright.pl - Strips a copyright header from a Makefile or shell
79# script.
80# insert_copyright.pl - Inserts a copyright header into a c/c++, shell script,
81# or Makefile file.
82#
83#
84# --------------------------
85# Copyright Update Procedure
86# --------------------------
87#
88# The following procedure should be used to update the copyright information.
89#
90# 1) find . -regextype egrep -regex '.*\.c|.*\.h|.*\.cpp|.*Makefile|.*Makefile\.sdk|.*\.mk|.*\.sh' | xargs $PROJROOT/tools/copyright_tools/update_copyright.sh
91#
92# To exlude a directory from the search, use the following command
93#
94# 1a) find . -path ./3rdparty -prune -o -regextype egrep -regex '.*\.c|.*\.h|.*\.cpp|.*Makefile|.*Makefile\.sdk|.*\.mk|.*\.sh' | xargs $PROJROOT/tools/copyright_tools/update_copyright.sh
95#
96# 2) Update the "Copyright (c)" statement in the debug CLI (./lib/libdbg/dbgCli.c)
97# - Note: newer versions of the script may already handle this automatically.
98#
99# 3) Update the following files by hand because they do not follow
100# the standard source file naming conventions:
101# - bal/cur/3rdparty/indigo/indigo/modules/ofpal_driver/module/src/ofpal_driver.c
102# - bal/cur/3rdparty/indigo/indigo/modules/ofpal-driver/utest/main.c
103# - bal/cur/doxygen/Makefile
104#
105# Also, you can use the following command to find additional straglers...
106#
107# find . | xargs grep 2013
108#
109# (Optional) Use the following procedure to verify the changes.
110#
111# a) Use p4 to build a list of files that are being modified by this CL.
112#
113# p4 describe <CL from step1> | grep '^\.\.\.' | awk '{print $2}' | sed 's%//SystemSoftware/Rel/pioneer/dml/%%g' | sed 's%\#.$%%g' > p4_changes_files.txt
114#
115# b) Add the following bash script to a file called temp.sh and
116# add execute permissions to the file.
117#
118# #!/bin/sh
119# #
120# while read -r line; do
121# echo "$line: "`p4 diff -ds $line | grep changed`
122# done < p4_changes_files.txt
123#
124# c) Run the script
125#
126# ./temp.sh | tee p4_diffs.txt
127#
128# d) Check the scripe for unusual/unexpected changes and use 'p4 diff file'
129# to investigate.
130#
131# cat p4_diffs.txt | grep -v "changed 1 chunks 1 / 1 lines" | tee t1.txt
132#
133#
134###############################################################################
135
136COPYRIGHT_FILE=${PROJROOT}/COPYRIGHT
137P4_CHANGELIST_DESC="Copyright Header Update - "`date`
138
139if [ "$1" = "-c" ]
140 then
141 P4_CHANGELIST_NUM="$2"
142
143 if [ "$P4_CHANGELIST_NUM" = "" ]
144 then
145 echo "ERROR: must specify 'none' or P4 change list number for the '-c' option."
146 exit 1
147 elif [ "$P4_CHANGELIST_NUM" = "none" ]
148 then
149 echo "NOTE: Perforce commands will be skipped"
150 else
151 echo "Using existing change list $P4_CHANGELIST_NUM"
152 fi
153 shift ; shift
154else
155 P4_CHANGELIST_NUM=`echo -e "Change: new\nDescription: ${P4_CHANGELIST_DESC}" | p4 change -i | cut -d " " -f 2`
156 echo "Created change list $P4_CHANGELIST_NUM"
157fi
158
159for path in "$@"
160do
161 file=`basename $path`
162
163 file_ext="${file#*.}"
164
165 # Only checkout files from perforce is an existing or new change list was specified
166 if [ "$P4_CHANGELIST_NUM" != "none" ]
167 then
168
169 # Only update text files
170 p4_file_type=`p4 fstat $path | grep headType | cut -d " " -f 3 | grep -o text`
171 if [ "$p4_file_type" != "text" ]
172 then
173 echo "WARNING: skipping file '$path' because it it not a text file."
174 continue ### resumes iteration of an enclosing for loop ###
175 fi
176
177 # Open the file for editing
178 p4 opened $path 2>&1 | grep -q "not opened"
179 if [ $? != 0 ]
180 then
181 echo "WARNING: file '$path' is already opened for edit..."
182 else
183 p4 edit -c $P4_CHANGELIST_NUM $path &>/dev/null
184 fi
185 fi
186
187 # Update the Copyright based on file type
188 if [ "$file_ext" == "c" ] || [ "$file_ext" == "h" ] || [ "$file_ext" == "cpp" ]
189 then
190 #
191 # C/C++ files
192 #
193 echo -ne "Updating '$file', type = c/c++ ... "
194 cat $path | perl ${PROJROOT}/tools/copyright_tools/strip_c_copyright.pl > $path"_crtemp";
195 perl ${PROJROOT}/tools/copyright_tools/insert_copyright.pl -t c -l ${COPYRIGHT_FILE} $path"_crtemp" > $path;
196 rm $path"_crtemp"
197 echo "done."
198 elif [ "$file_ext" == "sh" ]
199 then
200 #
201 # Shell script files
202 #
203 echo -ne "Updating '$file', type = shell script ... "
204 cat $path | perl ${PROJROOT}/tools/copyright_tools/strip_sh_copyright.pl > $path"_crtemp";
205 perl ${PROJROOT}/tools/copyright_tools/insert_copyright.pl -t s -l ${COPYRIGHT_FILE} $path"_crtemp" > $path;
206 rm $path"_crtemp"
207 echo "done."
208 elif [ "$file" == "Makefile" ] || [ "$file" == "Makefile.sdk" ] || [ "$file_ext" == "mk" ]
209 then
210 #
211 # Makefiles
212 #
213 echo -ne "Updating '$file', type = Makefile ... "
214 cat $path | perl ${PROJROOT}/tools/copyright_tools/strip_sh_copyright.pl > $path"_crtemp";
215 perl ${PROJROOT}/tools/copyright_tools/insert_copyright.pl -t m -l ${COPYRIGHT_FILE} $path"_crtemp" > $path;
216 rm $path"_crtemp"
217 echo "done."
218 else
219 echo "Skipping $file, type = unknown type"
220 fi
221done