ci: Add scripts to check for necessary headers Take the scripts by @acomodi from https://github.com/SymbiFlow/fpga-tool-perf/tree/f8d143b73f670eea5efdbe96f1236d82998c896e/.github/travis Fix files that fail the checks Signed-off-by: Daniel Lim Wee Soong <weesoong.lim@gmail.com>
diff --git a/.github/travis/check_license.sh b/.github/travis/check_license.sh new file mode 100755 index 0000000..8463847 --- /dev/null +++ b/.github/travis/check_license.sh
@@ -0,0 +1,64 @@ +#!/bin/bash + +# Copyright (C) 2020 The SymbiFlow Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC + +echo +echo "===========================" +echo "Check SPDX identifier" +echo "===========================" +echo + +ERROR_FILES="" +FILES_TO_CHECK=`find . \ + -type f \( -name '*.sh' -o -name '*.py' -o -name 'Makefile' -o -name '*.v' \) \ + \( -not -path "*/*/__init__.py" -not -path "*/.*/*" -not -path "*/third_party/*" -not -path "*/env/*" \)` + +for file in $FILES_TO_CHECK; do + echo "Checking $file" + grep -q "SPDX-License-Identifier" $file || ERROR_FILES="$ERROR_FILES $file" +done + +if [ ! -z "$ERROR_FILES" ]; then + for file in $ERROR_FILES; do + echo "ERROR: $file does not have license information." + done + return 1 +fi + +echo +echo "===========================" +echo "Check third party LICENSE" +echo "===========================" +echo + +function check_if_submodule { + for submodule in `git submodule --quiet foreach 'echo $sm_path'`; do + if [ "$1" == "$submodule" ]; then + return 1 + fi + done +} + +THIRD_PARTY_DIRS=`ls -d third_party/*` +ERROR_NO_LICENSE="" + +for dir in $THIRD_PARTY_DIRS; do + # Checks if we are not in a submodule + if check_if_submodule $dir; then + echo "Checking $dir" + [ -f $dir/LICENSE ] || ERROR_NO_LICENSE="$ERROR_NO_LICENSE $dir" + fi +done + +if [ ! -z "$ERROR_NO_LICENSE" ]; then + for dir in $ERROR_NO_LICENSE; do + echo "ERROR: $dir does not have the LICENSE file." + done + return 1 +fi \ No newline at end of file
diff --git a/.github/travis/check_python_script.sh b/.github/travis/check_python_script.sh new file mode 100644 index 0000000..57d792f --- /dev/null +++ b/.github/travis/check_python_script.sh
@@ -0,0 +1,35 @@ +#!/bin/bash + +echo +echo "===================================" +echo "Check python utf coding and shebang" +echo "===================================" +echo + +ERROR_FILES_SHEBANG="" +ERROR_FILES_UTF_CODING="" +FILES_TO_CHECK=`find . \ + -type f \( -name '*.py' \) \ + \( -not -path "*/.*/*" -not -path "*/third_party/*" -not -path "*/env/*" \)` + +for file in $FILES_TO_CHECK; do + echo "Checking $file" + grep -q "\#\!/usr/bin/env python3" $file || ERROR_FILES_SHEBANG="$ERROR_FILES_SHEBANG $file" + grep -q "\#.*coding: utf-8" $file || ERROR_FILES_UTF_CODING="$ERROR_FILES_UTF_CODING $file" +done + +if [ ! -z "$ERROR_FILES_SHEBANG" ]; then + for file in $ERROR_FILES_SHEBANG; do + echo "ERROR: $file does not have the python3 shebang." + done + return 1 +fi + +if [ ! -z "$ERROR_FILES_UTF_CODING" ]; then + for file in $ERROR_FILES_UTF_CODING; do + echo "ERROR: $file does not have the utf encoding set." + done + return 1 +fi + +echo \ No newline at end of file
diff --git a/.travis.yml b/.travis.yml index 5c492fa..dabf64f 100644 --- a/.travis.yml +++ b/.travis.yml
@@ -8,6 +8,8 @@ install: - . prepareenv.sh - conda activate yosys-env + - source .github/travis/check_license.sh + - source .github/travis/check_python_script.sh script: tox
diff --git a/docs/Makefile b/docs/Makefile index 64f9ba2..8e8fe65 100644 --- a/docs/Makefile +++ b/docs/Makefile
@@ -1,3 +1,11 @@ +# Copyright (C) 2020 The SymbiFlow Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC + # Minimal makefile for Sphinx documentation #
diff --git a/prepareenv.sh b/prepareenv.sh index 5169d5a..5193fa0 100755 --- a/prepareenv.sh +++ b/prepareenv.sh
@@ -1,4 +1,12 @@ #!/bin/bash +# +# Copyright (C) 2020 The SymbiFlow Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC pip install tox wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
diff --git a/v2x/__init__.py b/v2x/__init__.py index e69de29..56fafa5 100644 --- a/v2x/__init__.py +++ b/v2x/__init__.py
@@ -0,0 +1,2 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*-
diff --git a/v2x/lib/__init__.py b/v2x/lib/__init__.py index e69de29..56fafa5 100644 --- a/v2x/lib/__init__.py +++ b/v2x/lib/__init__.py
@@ -0,0 +1,2 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*-
diff --git a/v2x/xmlinc/__init__.py b/v2x/xmlinc/__init__.py index e69de29..56fafa5 100644 --- a/v2x/xmlinc/__init__.py +++ b/v2x/xmlinc/__init__.py
@@ -0,0 +1,2 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*-
diff --git a/v2x/yosys/__init__.py b/v2x/yosys/__init__.py index e5a0d9b..56fafa5 100644 --- a/v2x/yosys/__init__.py +++ b/v2x/yosys/__init__.py
@@ -1 +1,2 @@ #!/usr/bin/env python3 +# -*- coding: utf-8 -*-