github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/bin/run_lint_rust (about)

     1  #!/bin/bash
     2  #
     3  # Copyright 2018 Intel Corporation
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  # ------------------------------------------------------------------------------
    17  
    18  top_dir=$(cd $(dirname $(dirname $0)) && pwd)
    19  
    20  dirs="
    21      $top_dir/sdk/rust
    22      $top_dir/sdk/examples/intkey_rust
    23      $top_dir/families/smallbank/smallbank_rust
    24      $top_dir/adm
    25      $top_dir/perf/sawtooth_perf
    26      $top_dir/perf/sawtooth_workload
    27      $top_dir/perf/intkey_workload
    28      $top_dir/perf/smallbank_workload
    29  "
    30  
    31  exitcode=0
    32  
    33  rustfmt --version
    34  
    35  for dir in $dirs; do
    36      cd $dir
    37      echo "$dir"
    38  
    39      echo "-- rustfmt"
    40  
    41      diff=$(cargo fmt -- --write-mode=diff)
    42      rustfmt_exit=$?
    43  
    44      # rustfmt returns the following exit codes:
    45      #
    46      # 0 = No errors
    47      # 1 = Encountered operational errors e.g. an IO error
    48      # 2 = Failed to reformat code because of parsing errors
    49      # 3 = Code is valid, but it is impossible to format it properly
    50      # 4 = Formatted code differs from existing code (write-mode diff only)
    51      #
    52      # Codes 3 and 4 both indicate formatting errors in the code, so
    53      # they will be treated the same.
    54      #
    55      # This may change in the future.
    56      # See https://github.com/rust-lang-nursery/rustfmt/issues/1977.
    57  
    58      if [[ $rustfmt_exit != 0 ]]; then
    59          exitcode=1
    60  
    61          if [[ $rustfmt_exit == 1 ]]; then
    62              echo "rustfmt encountered an operational error"
    63          elif [[ $rustfmt_exit == 2 ]]; then
    64              echo "Parsing error in $dir"
    65          else
    66              echo "Incorrect formatting: $dir (error code: $rustfmt_exit)"
    67              echo -e $diff
    68          fi
    69      fi
    70  
    71  done
    72  
    73  exit $exitcode