vitess.io/vitess@v0.16.2/tools/check_make_parser.sh (about)

     1  #!/bin/bash
     2  #
     3  # Validate that the current version of the generated parser matches the output
     4  # generated by the version of goyacc installed on the local system.
     5  #
     6  # This is used in Travis to verify that the currently committed version was
     7  # generated with the proper version of goyacc.
     8  
     9  source build.env
    10  
    11  CUR="sql.go"
    12  TMP="/tmp/sql.$$.go"
    13  
    14  set -e
    15  
    16  if ! cd go/vt/sqlparser/ ; then
    17          echo "ERROR: $0 must be run in the root project directory"
    18          exit 1
    19  fi
    20  
    21  mv $CUR $TMP
    22  output=$(go run ./goyacc -fo $CUR sql.y)
    23  expectedOutput=$'\nconflicts: 3 shift/reduce'
    24  
    25  if [[ "$output" != "$expectedOutput" ]]; then
    26      echo -e "Expected output from goyacc:$expectedOutput\ngot:$output"
    27      mv $TMP $CUR
    28      exit 1
    29  fi
    30  
    31  gofmt -w $CUR
    32  
    33  if ! diff -q $CUR $TMP > /dev/null ; then
    34          echo "ERROR: Regenerated parser $TMP does not match current version $(pwd)/sql.go:"
    35          diff -u $CUR $TMP
    36          mv $TMP $CUR
    37  
    38          echo
    39          echo "Please ensure go and goyacc are up to date and re-run 'make parser' to generate."
    40          exit 1
    41  fi
    42  
    43  mv $TMP $CUR