From e62d88843fd91140e555a74ca48fad6363355903 Mon Sep 17 00:00:00 2001 From: Alessandro Comodi Date: Fri, 21 May 2021 16:14:22 +0200 Subject: [PATCH 1/2] checks: use linguist to detect file types This commit also allows to skip the generated files checks by adding the file to the .gitattributes file Signed-off-by: Alessandro Comodi --- .gitattributes | 7 +++++++ checks/Dockerfile | 10 ++++++++++ checks/checks.py | 15 +++++++++++++-- .../tests/license/test-missing-spdx-generated.v | 5 +++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 .gitattributes create mode 100644 checks/tests/license/test-missing-spdx-generated.v diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..25ff38a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +# Linguist - vendored override + +third_party/* linguist-vendored + +# Linguist - generated override + +checks/tests/license/test-missing-spdx-generated.v linguist-generated diff --git a/checks/Dockerfile b/checks/Dockerfile index a3f5265..d1fba80 100644 --- a/checks/Dockerfile +++ b/checks/Dockerfile @@ -5,6 +5,16 @@ RUN apt-get update -qq \ && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ ca-certificates \ git \ + make \ + cmake \ + pkg-config \ + libicu-dev \ + zlib1g-dev \ + libcurl4-openssl-dev \ + ruby-dev \ + libssl-dev \ + build-essential \ + && gem install github-linguist \ && apt-get autoclean && apt-get clean && apt-get -y autoremove \ && update-ca-certificates \ && rm -rf /var/lib/apt/lists/* diff --git a/checks/checks.py b/checks/checks.py index eef9865..9d046e5 100755 --- a/checks/checks.py +++ b/checks/checks.py @@ -17,6 +17,8 @@ import re import sys import tempfile +import subprocess +import json __path__ = pathlib.Path(__file__).resolve().parent @@ -417,6 +419,15 @@ def main(args): logging.debug('Starting search in: %s', root_dir) errors = {} + + json_data = subprocess.check_output("github-linguist --json", shell=True).decode('utf8') + files_data = json.loads(json_data) + + ftypes = {} + for ftype, fpaths in files_data.items(): + for fpath in fpaths: + ftypes[fpath] = ftype + for root, dirs, files in os.walk(root_dir): rpath = pathlib.Path(root).resolve() fdebug(rpath, 'Searching') @@ -463,9 +474,9 @@ def main(args): fwarn(fpath, 'Skipping nonfile') continue - ftype = detect_file_type(fpath) + ftype = ftypes.get(os.path.relpath(fpath, root_dir), None) if ftype is None: - finfo(fpath, 'Skipping unknown file type') + finfo(fpath, 'Skipping generated or unknown file') continue ferrors = [] diff --git a/checks/tests/license/test-missing-spdx-generated.v b/checks/tests/license/test-missing-spdx-generated.v new file mode 100644 index 0000000..252c7bb --- /dev/null +++ b/checks/tests/license/test-missing-spdx-generated.v @@ -0,0 +1,5 @@ +module top (input in, output out); + +assign out = in; + +endmodule From 26ef65fe32fe7c9f07bc568ea2a4cab1cefe6e8d Mon Sep 17 00:00:00 2001 From: Alessandro Comodi Date: Fri, 21 May 2021 16:42:46 +0200 Subject: [PATCH 2/2] add license to Dockerfile Signed-off-by: Alessandro Comodi --- checks/Dockerfile | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/checks/Dockerfile b/checks/Dockerfile index d1fba80..24a9c3d 100644 --- a/checks/Dockerfile +++ b/checks/Dockerfile @@ -1,3 +1,14 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# 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 + FROM python:slim-buster # Install git