File: update_checks.sh

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (50 lines) | stat: -rwxr-xr-x 1,670 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This files modifies all uses of CHECK/DCHECK to be prefixed with ABSL.

git grep --name-only " CHECK" > /tmp/to_change
git grep --name-only " DCHECK" >> /tmp/to_change
files=`sort -u /tmp/to_change`

if [ -z "$files" ]; then
  echo 'No files to rename'
  exit -1
fi

# mediapipe defines it's own CHECK_OK
# (in src/mediapipe/framework/deps/status.h), which means only some CHECK's need
# to be modified. `check_extensions` is the list to replace. X is replaced with
# the empty string.
check_extensions="_EQ _NE _LE _LT _GE _GT _"

for file in $files
do
  echo "Modifying ${file}"
  for extension in $check_extensions
  do
    if [ $extension = "_" ]; then
      extension=""
    fi
    sed -i -e "s| CHECK${extension}(| ABSL_CHECK${extension}(|g" $file
    sed -i -e "s| DCHECK${extension}(| ABSL_DCHECK${extension}(|g" $file
  done
  # Check to see if we modified the file. Only add the include if we did.
  git diff --quiet $file
  if [ $? -eq 1 ];  then
    check_include=`grep "^#include \"absl/log/absl_check.h\"" $file`
    if [ -z "$check_include" ]; then
      line_number=`grep -n "^#include" $file | tail -1 | awk -F: '{print $1}'`
      if [ ! -z "$line_number" ]; then
        ((line_number=line_number+1))
        echo "Adding include to ${file} at line ${line_number}"
        sed -i "${line_number} i #include \"absl/log/absl_check.h\"" $file
      fi
    fi
  fi
done

echo "WARNING: this script may have added includes to the wrong section (such as"
echo "shaders) be sure to sanity check results."