Skip to content

Commit

Permalink
[UR] Dont run license checks at configure time
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Vesely committed Aug 1, 2023
1 parent 36fdd69 commit 154699b
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ jobs:
- name: Generate source from spec, check for uncommitted diff
if: matrix.os == 'ubuntu-22.04'
run: cmake --build ${{github.workspace}}/build --target check-generated

- name: Verify that each source file contains a license
run: cmake --build ${{github.workspace}}/build --target verify-licenses

- name: Build
run: cmake --build ${{github.workspace}}/build -j $(nproc)
Expand Down
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ endif()

# Obtain files for clang-format
set(format_glob)
set(license_glob)
foreach(dir examples include source test tools)
list(APPEND format_glob
"${dir}/*.h"
Expand All @@ -167,11 +168,26 @@ foreach(dir examples include source test tools)
"${dir}/**/*.hpp"
"${dir}/**/*.c"
"${dir}/**/*.cpp")
list(APPEND license_glob
"${dir}/*.yml"
"${dir}/**/*.yml"
"${dir}/*.py"
"${dir}/**/*.py"
"${dir}/**/CMakeLists.txt"
"${dir}/CMakeLists.txt"
)
endforeach()
file(GLOB_RECURSE format_src ${format_glob})
file(GLOB_RECURSE license_src ${license_glob})

# check for licence
VerifyLicence(${format_src})
list(FILTER license_src EXCLUDE REGEX "registry.yml")
add_custom_target(verify-licenses
COMMAND ${Python3_EXECUTABLE}
"${PROJECT_SOURCE_DIR}/scripts/verify_license.py"
"--files" ${format_src} ${license_src}
COMMENT "Verify all files contain a license."
)

# Add code formatter target
add_custom_target(cppformat)
Expand Down
10 changes: 0 additions & 10 deletions cmake/helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,3 @@ function(FetchContentSparse_Declare name GIT_REPOSITORY GIT_TAG GIT_DIR)
FetchContent_Declare(${name} SOURCE_DIR ${content-build-dir}/${GIT_DIR})
endfunction()


# Checks that every input file includes an appropriate license notice.
function(VerifyLicence)
foreach(file ${ARGN})
file(READ ${file} file_contents LIMIT 300)
if(NOT "${file_contents}" MATCHES "SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception")
message(FATAL_ERROR "${file} does not contain an appropriate license comment.")
endif()
endforeach()
endfunction()
9 changes: 9 additions & 0 deletions scripts/core/exp-bindless-images.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#
# Copyright (C) 2022 Intel Corporation
#
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
# See LICENSE.TXT
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# See YaML.md for syntax definition
#
--- #--------------------------------------------------------------------------
type: header
desc: "Bindless Images Extension APIs"
Expand Down
9 changes: 9 additions & 0 deletions scripts/core/exp-usm-import-release.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#
# Copyright (C) 2022 Intel Corporation
#
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
# See LICENSE.TXT
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# See YaML.md for syntax definition
#
--- #--------------------------------------------------------------------------
type: header
desc: "Intel $OneApi USM Import/Release Extension APIs"
Expand Down
8 changes: 8 additions & 0 deletions scripts/templates/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Copyright (C) 2022 Intel Corporation
Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
See LICENSE.TXT
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
28 changes: 28 additions & 0 deletions scripts/verify_license.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Copyright (C) 2022 Intel Corporation
Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
See LICENSE.TXT
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""

import sys
import argparse

def verify_file_has_license(file):
with open(file, 'r') as in_file:
input = in_file.read(300)
if "SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception" not in input:
raise Exception(f"{file} does not contain a license!")

def main():
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--files', nargs='+', default=[])
args = parser.parse_args()
for file in args.files:
verify_file_has_license(file)


if __name__ == "__main__":
sys.exit(main())

0 comments on commit 154699b

Please sign in to comment.