Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

action: add license check #85

Merged
merged 2 commits into from
May 21, 2024
Merged

action: add license check #85

merged 2 commits into from
May 21, 2024

Conversation

WangJialei-A
Copy link
Contributor

@WangJialei-A WangJialei-A commented May 17, 2024

Add license check
Files in the changeset with suffix .c, .cpp, .h, .hpp, .py, CMakeLists.txt will be checked.
Please see the result at #86 and url

@WangJialei-A WangJialei-A added the WIP work in progress label May 17, 2024
@WangJialei-A WangJialei-A removed the WIP work in progress label May 17, 2024
run: |
import os, datetime, sys

intel_license: list[str] = [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we put this script in .github or somewhere inside our repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Menooker
If developers need to run it as a local check, it is ok to split the script into a seperate python file.
Do you really need to do the local check?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also note that we already have script/ directory for compiling the repo and compiling LLVM. The sh files are used in CI too. I think we should add the py file to this directory.

Copy link

@AshburnLee AshburnLee May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about put this check script into repo_dir/scripts/license_check.py, so that this script can be used not only in actions but also from local.
For complex logic, normally put them into scrips/

]

llvm_license: list[str] = [
'This file is licensed under the Apache License v2.0 with LLVM Exceptions.',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLVM's header looks like

//===- Example.cpp - Tests for Example ------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

Shall we check the header //===- Example.cpp - Tests for Example ------------------------------------===// and the footer //===----------------------------------------------------------------------===// as well?

Note that the header has variable number of ------------------------------------ to align the line wrap limit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Menooker
The string Tests for Example you mentioned is not a costant string or from the filename. I do not know how to verify it.
That's why I skipped the first line check for llvm license.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is {file name} - {desc} ---------. I think we can check the filename and the number of ---------. For auto-fix, we can fill-in the filename and a place holder "{DESC}" and auto fix the number of ------------.

In checking mode, we can throw an error when detecting "{DESC}".

A workflow for the user to use auto-fix should be:

  1. write code without LLVM header
  2. auto-fix for the first time
  3. fill in {DESC} in the code
  4. auto-fix again, maybe check if there are remaining {DESC}

'SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception',
]

def check_license(filename: str, license: list[str]):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oneDNN's script also provides a utility to auto fix the headers. It is useful when a PR is across two years (to update year).
I think for LLVM, auto fixing headers are also useful, when we introduce many cpp files in a PR, and we need to manually fill-in the file names in the licence. Maybe we can improve the script in another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can write another small script to handle the fixing job in the future, but not in the automatic CI script.

year: int = datetime.datetime.now().year
success: bool = True

for filepath in os.environ["CHANGED_FILES"].split(','):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we pass this by args, so that users can check it locally?

test/lit.cfg.py Outdated
@@ -1,3 +1,19 @@
# Copyright (C) 2024 Intel Corporation
#

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is part of MLIR testing. And upstream MLIR does not add copyright on this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is part of MLIR testing. And upstream MLIR does not add copyright on this file

@Menooker It is Intel license, not the LLVM one and non-related with upstream work.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is copied and modified based on upstream MLIR. In upstream, this file seems not to have copyright?

success = False
print("Fail : %s" % filepath)
else:
print("Success: %s" % filepath)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we provide suggestions on how to fix that?

@WangJialei-A WangJialei-A force-pushed the wangjial/check_license branch 2 times, most recently from 3f08c68 to 6a1274f Compare May 21, 2024 05:22
@WangJialei-A
Copy link
Contributor Author

@Menooker
Please start another review. You can see the test result here: url

@WangJialei-A WangJialei-A merged commit acc2d84 into main May 21, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants