lint_config.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/bash -e
  2. #
  3. # Copyright (c) 2012 The Chromium Authors. All rights reserved.
  4. # Use of this source code is governed by a BSD-style license that can be
  5. # found in the LICENSE file.
  6. # This script is used to compare vpx_config.h and vpx_config.asm to
  7. # verify the two files match.
  8. #
  9. # Arguments:
  10. #
  11. # -h - C Header file.
  12. # -a - ASM file.
  13. # -p - Print the options if correct.
  14. # -o - Output file.
  15. #
  16. # Usage:
  17. #
  18. # # Compare the two configuration files and output the final results.
  19. # ./lint_config.sh -h vpx_config.h -a vpx_config.asm -o libvpx.config -p
  20. export LC_ALL=C
  21. print_final="no"
  22. while getopts "h:a:o:p" flag
  23. do
  24. if [ "$flag" = "h" ]; then
  25. header_file=$OPTARG
  26. elif [ "$flag" = "a" ]; then
  27. asm_file=$OPTARG
  28. elif [ "$flag" = "o" ]; then
  29. out_file=$OPTARG
  30. elif [ "$flag" = "p" ]; then
  31. print_final="yes"
  32. fi
  33. done
  34. if [ -z "$header_file" ]; then
  35. echo "Header file not specified."
  36. false
  37. exit
  38. fi
  39. if [ -z "$asm_file" ]; then
  40. echo "ASM file not specified."
  41. false
  42. exit
  43. fi
  44. # Concat header file and assembly file and select those ended with 0 or 1.
  45. combined_config="$(cat $header_file $asm_file | grep -E ' +[01] *$')"
  46. # Extra filtering for known exceptions.
  47. combined_config="$(echo "$combined_config" | grep -v WIDE_REFERENCE)"
  48. combined_config="$(echo "$combined_config" | grep -v ARCHITECTURE)"
  49. combined_config="$(echo "$combined_config" | grep -v DO1STROUNDING)"
  50. # Remove all spaces.
  51. combined_config="$(echo "$combined_config" | sed 's/[[:space:]]//g')"
  52. # Remove #define in the header file.
  53. combined_config="$(echo "$combined_config" | sed 's/.*define//')"
  54. # Remove equ in the ASM file.
  55. combined_config="$(echo "$combined_config" | sed 's/\.equ//')" # gas style
  56. combined_config="$(echo "$combined_config" | sed 's/equ//')" # rvds style
  57. combined_config="$(echo "$combined_config" | sed 's/\.set//')" # apple style
  58. # Remove %define in YASM ASM files.
  59. combined_config="$(echo "$combined_config" | sed 's/%define[[:space:]]*//')"
  60. # Remove useless comma in gas style assembly file.
  61. combined_config="$(echo "$combined_config" | sed 's/,//')"
  62. # Substitute 0 with =no.
  63. combined_config="$(echo "$combined_config" | sed 's/0$/=no/')"
  64. # Substitute 1 with =yes.
  65. combined_config="$(echo "$combined_config" | sed 's/1$/=yes/')"
  66. # Find the mismatch variables.
  67. odd_config="$(echo "$combined_config" | sort | uniq -u)"
  68. odd_vars="$(echo "$odd_config" | sed 's/=.*//' | uniq)"
  69. for var in $odd_vars; do
  70. echo "Error: Configuration mismatch for $var."
  71. echo "Header file: $header_file"
  72. echo "$(cat -n $header_file | grep "$var[ \t]")"
  73. echo "Assembly file: $asm_file"
  74. echo "$(cat -n $asm_file | grep "$var[ \t]")"
  75. echo ""
  76. done
  77. if [ -n "$odd_vars" ]; then
  78. false
  79. exit
  80. fi
  81. if [ "$print_final" = "no" ]; then
  82. exit
  83. fi
  84. # Do some additional filter to make libvpx happy.
  85. combined_config="$(echo "$combined_config" | grep -v ARCH_X86=no)"
  86. combined_config="$(echo "$combined_config" | grep -v ARCH_X86_64=no)"
  87. # Print out the unique configurations.
  88. if [ -n "$out_file" ]; then
  89. echo "$combined_config" | sort | uniq > $out_file
  90. else
  91. echo "$combined_config" | sort | uniq
  92. fi