diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 993405142be3e2b95aef685c773e2d8876addf92..cc00118c0d821a830920f9dcd175c3a7f1d5dd9d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,16 +16,25 @@ repos: - id: detect-private-key files: (?!.*tar.gz)^.*$ - id: end-of-file-fixer - files: (src).*\.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$ + files: (src).*\.(md|py|mm|swift|java|c|cc|cxx|cpp|h|hpp|hxx)$ - id: trailing-whitespace - files: (src).*\.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$ + files: (src).*\.(md|py|mm|swift|java|c|cc|cxx|cpp|h|hpp|hxx)$ + +- repo: local + hooks: + - id: copyright + name: copyright + entry: python ./tools/pre-commit.hooks/copyright.hook + language: system + files: (src).*\.(c|cc|cxx|cpp|h|hpp|hxx|py)$ + exclude: (?!.*third_party)^.*$ | (?!.*book)^.*$ - repo: local hooks: - id: clang-format name: clang-format description: Format files with ClangFormat. - entry: bash ./tools/pre-commit.hooks/.clang-format.hook -i + entry: bash ./tools/pre-commit.hooks/clang-format.hook -i language: system files: (src).*\.(c|cc|cxx|cpp|h|hpp|hxx)$ @@ -44,15 +53,8 @@ repos: - id: cpplint name: cpplint description: Check C++ code style using cpplint. - entry: bash ./tools/pre-commit.hooks/.cpplint.hook + entry: bash ./tools/pre-commit.hooks/cpplint.hook language: system - files: (src).*\.(c|cc|cxx|cpp|cu|h|hpp|hxx)$ + files: (src).*\.(c|cc|cxx|cpp|h|hpp|hxx)$ exclude: (?!.*third_party)^.*$ | (?!.*book)^.*$i | *\.pb\.cpp -#- repo: local -# hooks: -# - id: copyright_checker -# name: copyright_checker -# entry: python ./tools/pre-commit.hooks/.copyright.hook -# language: system -# files: (src).*\.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto|py)$ -# exclude: (?!.*third_party)^.*$ | (?!.*book)^.*$ + diff --git a/src/framework/framework.pb.cpp b/src/framework/framework.pb.cpp index 636b0ad182eb5ee09057f1baba510e5d82e4a237..ae4016e8b137a0f5e27c032f08b7e50d24c2dc5b 100644 --- a/src/framework/framework.pb.cpp +++ b/src/framework/framework.pb.cpp @@ -1,3 +1,17 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + // Generated by the protocol buffer compiler. DO NOT EDIT! // source: framework.proto diff --git a/src/framework/framework.pb.h b/src/framework/framework.pb.h index 25f3dcb0b4835d40a7ceae0e0e66cc459d601ef5..fa75a92e57ddee571a611146e91fa93e8b943b60 100644 --- a/src/framework/framework.pb.h +++ b/src/framework/framework.pb.h @@ -1,3 +1,17 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + // Generated by the protocol buffer compiler. DO NOT EDIT! // source: framework.proto diff --git a/src/framework/op_desc.cpp b/src/framework/op_desc.cpp index d7b946424e6af07119d1579a150494c207b0989c..73037ecf3077d5ef746929487eea22efdd0b3194 100644 --- a/src/framework/op_desc.cpp +++ b/src/framework/op_desc.cpp @@ -1,8 +1,23 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + // // Created by liuRuiLong on 2018/5/4. // - -#include "op_desc.h" +#include "framework/op_desc.h" +#include +#include namespace paddle_mobile { namespace framework { @@ -30,10 +45,6 @@ OpDesc::OpDesc(const proto::OpDesc &desc) : desc_(desc) { std::string attr_name = attr.name(); if (attr.type() != proto::AttrType::BLOCK) { attrs_[attr_name] = Attribute::GetAttrValue(attr); - // if (attr.type() == proto::AttrType::INT){ - // std::cout << " attrName " << attr_name << " " << - // attrs_[attr_name].Get() << std::endl; - // } } } } diff --git a/src/framework/program_desc.cpp b/src/framework/program_desc.cpp index 4f6a4699bde5e19ee61e502ef15efd9296a08973..5537dacdebccd5533b79b7331ad6bb77699d9b93 100644 --- a/src/framework/program_desc.cpp +++ b/src/framework/program_desc.cpp @@ -1,8 +1,22 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + // // Created by liuRuiLong on 2018/5/4. // -#include "program_desc.h" +#include "framework/program_desc.h" namespace paddle_mobile { namespace framework { diff --git a/src/framework/scope.cc b/src/framework/scope.cc index b7f3926a8f6ddce4ce6ec24666881d58b6f25e25..ba5da674a45badff18966a91e070df324e9a8352 100644 --- a/src/framework/scope.cc +++ b/src/framework/scope.cc @@ -1,6 +1,21 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#include "framework/scope.h" -#include "scope.h" #include +#include #include namespace paddle_mobile { @@ -16,7 +31,7 @@ Variable *Scope::Var(const std::string &name) { auto *pvar = FindVarLocally(name); if (pvar != nullptr) { return pvar; - }; + } pvar = new Variable; vars_[name] = pvar; pvar->name_ = &(vars_.find(name)->first); diff --git a/tools/pre-commit.hooks/.clang-format.hook b/tools/pre-commit.hooks/clang-format.hook similarity index 100% rename from tools/pre-commit.hooks/.clang-format.hook rename to tools/pre-commit.hooks/clang-format.hook diff --git a/tools/pre-commit.hooks/.clang-tidy.hook b/tools/pre-commit.hooks/clang-tidy.hook similarity index 100% rename from tools/pre-commit.hooks/.clang-tidy.hook rename to tools/pre-commit.hooks/clang-tidy.hook diff --git a/tools/pre-commit.hooks/.copyright.hook b/tools/pre-commit.hooks/copyright.hook similarity index 54% rename from tools/pre-commit.hooks/.copyright.hook rename to tools/pre-commit.hooks/copyright.hook index 7e02c05b1434fed830e11ca518aa19457633af89..8fc0028059c8e841ceb7a70368563f54a4584b06 100644 --- a/tools/pre-commit.hooks/.copyright.hook +++ b/tools/pre-commit.hooks/copyright.hook @@ -3,28 +3,25 @@ from __future__ import print_function from __future__ import unicode_literals import argparse -import io, re -import sys, os -import subprocess +import io import platform +import re +import subprocess COPYRIGHT = ''' -Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. ''' LANG_COMMENT_MARK = None @@ -46,22 +43,27 @@ else: def generate_copyright(template, lang='C'): + end_line = "" if lang == 'Python': - LANG_COMMENT_MARK = '#' + lang_coment_mark = '# ' + start = lang_coment_mark + blank = " " else: - LANG_COMMENT_MARK = "//" - + lang_coment_mark = "" + start = "/* " + blank = "" + end_line = " */" lines = template.split(NEW_LINE_MARK) - BLANK = " " - ans = LANG_COMMENT_MARK + BLANK + COPYRIGHT_HEADER + NEW_LINE_MARK + + ans = start + blank + COPYRIGHT_HEADER + NEW_LINE_MARK + for lino, line in enumerate(lines): - if lino == 0 or lino == 1 or lino == len(lines) - 1: continue - if len(line) == 0: - BLANK = "" + if lino == 0 or lino == 1 or lino == len(lines) - 1: + continue + if lino == (len(lines) - 2): + ans += lang_coment_mark + blank + line + end_line + NEW_LINE_MARK else: - BLANK = " " - ans += LANG_COMMENT_MARK + BLANK + line + NEW_LINE_MARK - + ans += lang_coment_mark + blank + line + NEW_LINE_MARK return ans + "\n" @@ -78,14 +80,6 @@ def lang_type(filename): return "C" elif filename.endswith(".cpp"): return "C" - elif filename.endswith(".cu"): - return "C" - elif filename.endswith(".cuh"): - return "C" - elif filename.endswith(".go"): - return "C" - elif filename.endswith(".proto"): - return "C" else: print("Unsupported filetype %s", filename) exit(0) @@ -105,9 +99,10 @@ def main(argv=None): fd = io.open(filename, encoding="utf-8") first_line = fd.readline() second_line = fd.readline() - if "COPYRIGHT (C)" in first_line.upper(): continue - if first_line.startswith("#!") or PYTHON_ENCODE.match( - second_line) != None or PYTHON_ENCODE.match(first_line) != None: + if "COPYRIGHT (C)" in first_line.upper() or "COPYRIGHT (C)" in second_line.upper(): + continue + if first_line.startswith("/*") or first_line.startswith("#!") or PYTHON_ENCODE.match( + second_line) is not None or PYTHON_ENCODE.match(first_line) is not None: continue original_contents = io.open(filename, encoding="utf-8").read() new_contents = generate_copyright( @@ -116,9 +111,14 @@ def main(argv=None): retv = 1 with io.open(filename, 'w') as output_file: output_file.write(new_contents) - return retv +def test_generate_copyright(): + print(generate_copyright(COPYRIGHT)) + + if __name__ == '__main__': + # test_generate_copyright() exit(main()) + diff --git a/tools/pre-commit.hooks/.cpplint.hook b/tools/pre-commit.hooks/cpplint.hook similarity index 100% rename from tools/pre-commit.hooks/.cpplint.hook rename to tools/pre-commit.hooks/cpplint.hook