diff --git a/.github/scripts/check_license_headers.py b/.github/scripts/check_license_headers.py new file mode 100644 index 000000000..926ca81c8 --- /dev/null +++ b/.github/scripts/check_license_headers.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python3 +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +import argparse +import os +import sys + +REQUIRED_LICENSE_TEXT = "Copyright (c) Meta Platforms, Inc. and affiliates." + +# Extensions that must use /* */ block comment style +C_STYLE_EXTENSIONS = {".cpp", ".h", ".cu", ".cuh"} + +# Extensions that must use # comment style +HASH_STYLE_EXTENSIONS = {".py", ".sh"} + +C_STYLE_HEADER = """\ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */""" + +HASH_STYLE_HEADER = """\ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree.""" + + +def check_license_header(file_path): + """Check if a file has the required license header with the correct comment style.""" + try: + with open(file_path, "r", encoding="utf-8") as f: + content = f.read() + except Exception as e: + print(f"Error reading {file_path}: {e}") + return False, "error" + + if REQUIRED_LICENSE_TEXT not in content: + return False, "missing" + + ext = os.path.splitext(file_path)[1] + if ext in C_STYLE_EXTENSIONS: + if "* " + REQUIRED_LICENSE_TEXT not in content: + return False, "wrong_style" + elif ext in HASH_STYLE_EXTENSIONS: + if "# " + REQUIRED_LICENSE_TEXT not in content: + return False, "wrong_style" + + return True, "ok" + + +def main(): + parser = argparse.ArgumentParser(description="Check license headers in source files") + parser.add_argument("files", nargs="*", help="Files to check") + args = parser.parse_args() + + if not args.files: + return 0 + + missing_headers = [] + wrong_style = [] + + for file_path in args.files: + ok, reason = check_license_header(file_path) + if not ok: + if reason == "wrong_style": + wrong_style.append(file_path) + else: + missing_headers.append(file_path) + + has_errors = False + + if missing_headers: + has_errors = True + print("Missing license headers in the following files:") + for file_path in missing_headers: + print(f" - {file_path}") + + if wrong_style: + has_errors = True + print("\nWrong comment style for license header in the following files:") + for file_path in wrong_style: + print(f" - {file_path}") + + if has_errors: + print("\nExpected license header for .cpp, .h, .cu, .cuh files:") + print(C_STYLE_HEADER) + print("\nExpected license header for .py, .sh files:") + print(HASH_STYLE_HEADER) + return 1 + + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/.github/workflows/lint.yml.disabled b/.github/workflows/lint.yml similarity index 58% rename from .github/workflows/lint.yml.disabled rename to .github/workflows/lint.yml index 71c9a0c9c..4165f1fb0 100644 --- a/.github/workflows/lint.yml.disabled +++ b/.github/workflows/lint.yml @@ -6,6 +6,7 @@ on: # Linting is separate from tests - this only checks code formatting jobs: lint: + if: false # TODO: Temporarily disabled until lintrunner issues are resolved runs-on: ubuntu-latest steps: - name: Checkout code @@ -41,3 +42,26 @@ jobs: echo "" exit $status fi + + license-headers: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v5 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Check license headers + run: | + find . \ + \( -name "*.py" -o -name "*.cpp" -o -name "*.h" -o -name "*.cu" -o -name "*.cuh" -o -name "*.sh" \) \ + -type f \ + -not -path "./.git/*" \ + -not -path "./.venv/*" \ + -not -path "./__pycache__/*" \ + -not -path "*/build/*" \ + -not -path "*/third_party/*" \ + | xargs python .github/scripts/check_license_headers.py diff --git a/libkineto/src/plugin/aiupti/AiuptiActivityApi.cpp b/libkineto/src/plugin/aiupti/AiuptiActivityApi.cpp index a5ebdab6d..3999ca8fc 100644 --- a/libkineto/src/plugin/aiupti/AiuptiActivityApi.cpp +++ b/libkineto/src/plugin/aiupti/AiuptiActivityApi.cpp @@ -1,3 +1,11 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + #include "AiuptiActivityApi.h" #include diff --git a/libkineto/src/plugin/aiupti/AiuptiActivityApi.h b/libkineto/src/plugin/aiupti/AiuptiActivityApi.h index b5a47f9df..13cb43117 100644 --- a/libkineto/src/plugin/aiupti/AiuptiActivityApi.h +++ b/libkineto/src/plugin/aiupti/AiuptiActivityApi.h @@ -1,3 +1,11 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + #pragma once #include "AiuptiActivityBuffer.h" diff --git a/libkineto/src/plugin/aiupti/AiuptiActivityBuffer.h b/libkineto/src/plugin/aiupti/AiuptiActivityBuffer.h index c3ac19d02..21f0a1459 100644 --- a/libkineto/src/plugin/aiupti/AiuptiActivityBuffer.h +++ b/libkineto/src/plugin/aiupti/AiuptiActivityBuffer.h @@ -1,3 +1,11 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + #pragma once #include "AiuptiProfilerMacros.h" diff --git a/libkineto/src/plugin/aiupti/AiuptiActivityHandlers.cpp b/libkineto/src/plugin/aiupti/AiuptiActivityHandlers.cpp index 501804d3f..ccc6512a4 100644 --- a/libkineto/src/plugin/aiupti/AiuptiActivityHandlers.cpp +++ b/libkineto/src/plugin/aiupti/AiuptiActivityHandlers.cpp @@ -1,3 +1,11 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + #include "AiuptiActivityProfiler.h" #include diff --git a/libkineto/src/plugin/aiupti/AiuptiActivityProfiler.cpp b/libkineto/src/plugin/aiupti/AiuptiActivityProfiler.cpp index 431b9c693..3961229c7 100644 --- a/libkineto/src/plugin/aiupti/AiuptiActivityProfiler.cpp +++ b/libkineto/src/plugin/aiupti/AiuptiActivityProfiler.cpp @@ -1,3 +1,11 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + #include "AiuptiActivityProfiler.h" #include "AiuptiActivityApi.h" diff --git a/libkineto/src/plugin/aiupti/AiuptiActivityProfiler.h b/libkineto/src/plugin/aiupti/AiuptiActivityProfiler.h index 147fcd0ae..c201bf562 100644 --- a/libkineto/src/plugin/aiupti/AiuptiActivityProfiler.h +++ b/libkineto/src/plugin/aiupti/AiuptiActivityProfiler.h @@ -1,3 +1,11 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + #pragma once #include diff --git a/libkineto/src/plugin/aiupti/AiuptiProfilerMacros.h b/libkineto/src/plugin/aiupti/AiuptiProfilerMacros.h index 5c23d94f9..82c6137b0 100644 --- a/libkineto/src/plugin/aiupti/AiuptiProfilerMacros.h +++ b/libkineto/src/plugin/aiupti/AiuptiProfilerMacros.h @@ -1,3 +1,11 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + #pragma once #include diff --git a/libkineto/test/xpupti/compute/XpuptiScopeProfilerCompute.cpp b/libkineto/test/xpupti/compute/XpuptiScopeProfilerCompute.cpp index a7865545c..b4c753e27 100644 --- a/libkineto/test/xpupti/compute/XpuptiScopeProfilerCompute.cpp +++ b/libkineto/test/xpupti/compute/XpuptiScopeProfilerCompute.cpp @@ -1,3 +1,11 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + //============================================================== // Copyright (C) Intel Corporation // diff --git a/tools/linter/adapters/clangformat_linter.py b/tools/linter/adapters/clangformat_linter.py index 730b727ff..380e0db3a 100755 --- a/tools/linter/adapters/clangformat_linter.py +++ b/tools/linter/adapters/clangformat_linter.py @@ -1,4 +1,10 @@ #!/usr/bin/env python3 +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + """ clang-format linter adapter for lintrunner """ diff --git a/tools/linter/adapters/grep_linter.py b/tools/linter/adapters/grep_linter.py index 6f811410a..a192a5fb9 100755 --- a/tools/linter/adapters/grep_linter.py +++ b/tools/linter/adapters/grep_linter.py @@ -1,4 +1,10 @@ #!/usr/bin/env python3 +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + """ Generic grep-based linter """ diff --git a/tools/linter/adapters/newlines_linter.py b/tools/linter/adapters/newlines_linter.py index 65a64df75..cbbbdcc9b 100755 --- a/tools/linter/adapters/newlines_linter.py +++ b/tools/linter/adapters/newlines_linter.py @@ -1,4 +1,10 @@ #!/usr/bin/env python3 +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + """ Newlines linter - ensures files end with exactly one newline """ diff --git a/tools/linter/install/clangformat.py b/tools/linter/install/clangformat.py index 90eca1502..dd2b1e392 100755 --- a/tools/linter/install/clangformat.py +++ b/tools/linter/install/clangformat.py @@ -1,4 +1,10 @@ #!/usr/bin/env python3 +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + """ clang-format installer for lintrunner """