From 2f3f75f510d1b23ae363457415a4cdc716bccb49 Mon Sep 17 00:00:00 2001 From: sangoly Date: Fri, 23 Aug 2019 21:23:13 -0500 Subject: [PATCH] [Pre-Commit] fix pre-commit hooks bug (#1844) --- .pre-commit-config.yaml | 16 +- .travis.yml | 19 +- .travis/pre-commit-job.sh | 2 + .../java/android/PaddlePredictor/gradlew.bat | 168 +++++++++--------- lite/tools/debug/debug_utils.h | 2 +- lite/utils/io.h | 2 +- 6 files changed, 107 insertions(+), 102 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f4b7f4e375..2a7235a9d6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,8 @@ repos: sha: v1.0.1 hooks: - id: remove-crlf - files: (?!.*third_party)^.*$ | (?!.*book)^.*$ ^mobile/ ^metal/ ^web/ + files: (?!.*third_party)^.*$|(?!.*book)^.*$ + exclude: ^(mobile/|metal/|web/) #- repo: https://github.com/PaddlePaddle/mirrors-yapf.git #sha: 0d79c0c469bab64f7229c9aca2b1186ef47f0e37 #hooks: @@ -16,7 +17,7 @@ repos: - id: check-merge-conflict - id: check-symlinks - id: detect-private-key - files: (?!.*third_party)^.*$ | (?!.*book)^.*$ + files: (?!.*third_party)^.*$|(?!.*book)^.*$ - id: end-of-file-fixer - repo: local hooks: @@ -25,7 +26,8 @@ repos: description: Format files with ClangFormat. entry: bash ./tools/codestyle/clang_format.hook -i language: system - files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto)$ ^mobile/ ^metal/ ^web/ + files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto)$ + exclude: ^(mobile/|metal/|web/) - repo: local hooks: - id: cpplint-cpp-source @@ -33,7 +35,8 @@ repos: description: Check C++ code style using cpplint.py. entry: bash ./tools/codestyle/cpplint_pre_commit.hook language: system - files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx)$ ^mobile/ ^metal/ ^web/ + files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx)$ + exclude: ^(mobile/|metal/|web/) #- repo: local #hooks: #- id: pylint-doc-string @@ -48,5 +51,6 @@ repos: name: copyright_checker entry: python ./tools/codestyle/copyright.hook language: system - files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto|py)$ ^mobile/ ^metal/ ^web/ - exclude: (?!.*third_party)^.*$ | (?!.*book)^.*$ + files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto|py)$ + exclude: (?!.*third_party)^.*$|(?!.*book)^.*$ + exclude: ^(mobile/|metal/|web/) diff --git a/.travis.yml b/.travis.yml index 20fdddd5a1..c902afef91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,18 +9,17 @@ os: addons: apt: packages: - - git - - python - - python-pip - - python2.7-dev - - libc6-i386 - - curl - -compiler: - - clang +# - git +# - python +# - python-pip +# - python2.7-dev +# - libc6-i386 +# - curl + - clang-format-3.8 before_install: - - sudo pip install -U virtualenv pre-commit pip + - sudo pip install cpplint pre-commit + - sudo ln -s /usr/bin/clang-format-3.8 /usr/bin/clang-format # Download and install recent cmake script: diff --git a/.travis/pre-commit-job.sh b/.travis/pre-commit-job.sh index a0ae98dddd..cf4dd30659 100755 --- a/.travis/pre-commit-job.sh +++ b/.travis/pre-commit-job.sh @@ -11,6 +11,8 @@ cd `dirname $0` cd .. export PATH=/usr/bin:$PATH pre-commit install +which clang-format +clang-format --version if ! pre-commit run -a ; then ls -lh diff --git a/lite/demo/java/android/PaddlePredictor/gradlew.bat b/lite/demo/java/android/PaddlePredictor/gradlew.bat index e95643d6a2..f9553162f1 100644 --- a/lite/demo/java/android/PaddlePredictor/gradlew.bat +++ b/lite/demo/java/android/PaddlePredictor/gradlew.bat @@ -1,84 +1,84 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/lite/tools/debug/debug_utils.h b/lite/tools/debug/debug_utils.h index 644cdaba1d..7f77b90488 100644 --- a/lite/tools/debug/debug_utils.h +++ b/lite/tools/debug/debug_utils.h @@ -115,7 +115,7 @@ void FillTensorData(lite::Tensor* tensor, const DebugConfig& conf, int col) { data[i] = input_data[i]; } } else { - LOG(INFO) << "------------> Use all-ones input"; + LOG(INFO) << "-------------> Use all-ones input"; for (int i = 0; i < dim_size; i++) { data[i] = 1; } diff --git a/lite/utils/io.h b/lite/utils/io.h index 72f00bd1ca..ddd7e39b0d 100644 --- a/lite/utils/io.h +++ b/lite/utils/io.h @@ -35,7 +35,7 @@ static bool IsFileExists(const std::string& path) { // ARM mobile not support mkdir in C++ static void MkDirRecur(const std::string& path) { #ifndef LITE_WITH_ARM - if(system(string_format("mkdir -p %s", path.c_str()).c_str()) != 0) { + if (system(string_format("mkdir -p %s", path.c_str()).c_str()) != 0) { LOG(ERROR) << "Cann't mkdir " << path; } #else // On ARM -- GitLab