Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .github/scripts/check_license_headers.py
Original file line number Diff line number Diff line change
@@ -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())
24 changes: 24 additions & 0 deletions .github/workflows/lint.yml.disabled → .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 8 additions & 0 deletions libkineto/src/plugin/aiupti/AiuptiActivityApi.cpp
Original file line number Diff line number Diff line change
@@ -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 <assert.h>
Expand Down
8 changes: 8 additions & 0 deletions libkineto/src/plugin/aiupti/AiuptiActivityApi.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 8 additions & 0 deletions libkineto/src/plugin/aiupti/AiuptiActivityBuffer.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 8 additions & 0 deletions libkineto/src/plugin/aiupti/AiuptiActivityHandlers.cpp
Original file line number Diff line number Diff line change
@@ -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 <aiupti_runtime_cbid.h>
Expand Down
8 changes: 8 additions & 0 deletions libkineto/src/plugin/aiupti/AiuptiActivityProfiler.cpp
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
8 changes: 8 additions & 0 deletions libkineto/src/plugin/aiupti/AiuptiActivityProfiler.h
Original file line number Diff line number Diff line change
@@ -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 <mutex>
Expand Down
8 changes: 8 additions & 0 deletions libkineto/src/plugin/aiupti/AiuptiProfilerMacros.h
Original file line number Diff line number Diff line change
@@ -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 <libkineto.h>
Expand Down
8 changes: 8 additions & 0 deletions libkineto/test/xpupti/compute/XpuptiScopeProfilerCompute.cpp
Original file line number Diff line number Diff line change
@@ -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
//
Expand Down
6 changes: 6 additions & 0 deletions tools/linter/adapters/clangformat_linter.py
Original file line number Diff line number Diff line change
@@ -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
"""
Expand Down
6 changes: 6 additions & 0 deletions tools/linter/adapters/grep_linter.py
Original file line number Diff line number Diff line change
@@ -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
"""
Expand Down
6 changes: 6 additions & 0 deletions tools/linter/adapters/newlines_linter.py
Original file line number Diff line number Diff line change
@@ -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
"""
Expand Down
6 changes: 6 additions & 0 deletions tools/linter/install/clangformat.py
Original file line number Diff line number Diff line change
@@ -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
"""
Expand Down
Loading