-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#8120] Include C/C++ dependenices into FOSSA analysis
Summary: Include C/C++ dependenices into FOSSA analysis for open source license compliance. This is done by taking the special YAML metadata file that we've included in the third-party dependencies archive and creating "raw" FOSSA modules from each dependency's tar.gz file, excluding some of the dependencies that are only used during build time. Test Plan: Jenkins: compile only Reviewers: jharveysmith, steve.varnau Reviewed By: jharveysmith, steve.varnau Subscribers: ybase Differential Revision: https://phabricator.dev.yugabyte.com/D11319
- Loading branch information
Showing
18 changed files
with
240 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright (c) Yugabyte, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
# in compliance with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under the License | ||
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
# or implied. See the License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
set -euo pipefail | ||
. "${BASH_SOURCE%/*}/common-build-env.sh" | ||
|
||
activate_virtualenv | ||
set_pythonpath | ||
|
||
if [[ -n ${BUILD_ROOT:-} ]]; then | ||
handle_predefined_build_root_quietly=true | ||
predefined_build_root=$BUILD_ROOT | ||
handle_predefined_build_root | ||
fi | ||
find_or_download_thirdparty | ||
|
||
python3 "$YB_SRC_ROOT"/python/yb/fossa_analysis.py "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
https://github.com/yugabyte/yugabyte-db-thirdparty/releases/download/v20210210192532-45c97f45f1-centos7-linuxbrew/yugabyte-db-thirdparty-v20210210192532-45c97f45f1-centos7-linuxbrew.tar.gz | ||
https://github.com/yugabyte/yugabyte-db-thirdparty/releases/download/v20210402083441-ee4e2e453b-centos7-linuxbrew/yugabyte-db-thirdparty-v20210402083441-ee4e2e453b-centos7-linuxbrew.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
https://github.com/yugabyte/yugabyte-db-thirdparty/releases/download/v20210306075844-471ef8e125-centos7-clang11/yugabyte-db-thirdparty-v20210306075844-471ef8e125-centos7-clang11.tar.gz | ||
https://github.com/yugabyte/yugabyte-db-thirdparty/releases/download/v20210402093407-ee4e2e453b-centos7-clang11/yugabyte-db-thirdparty-v20210402093407-ee4e2e453b-centos7-clang11.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
https://github.com/yugabyte/yugabyte-db-thirdparty/releases/download/v20210210222846-45c97f45f1-centos7-devtoolset-8/yugabyte-db-thirdparty-v20210210222846-45c97f45f1-centos7-devtoolset-8.tar.gz | ||
https://github.com/yugabyte/yugabyte-db-thirdparty/releases/download/v20210402122231-ee4e2e453b-centos7-devtoolset-8/yugabyte-db-thirdparty-v20210402122231-ee4e2e453b-centos7-devtoolset-8.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
https://github.com/yugabyte/yugabyte-db-thirdparty/releases/download/v20210210211756-45c97f45f1-centos7-devtoolset-9/yugabyte-db-thirdparty-v20210210211756-45c97f45f1-centos7-devtoolset-9.tar.gz | ||
https://github.com/yugabyte/yugabyte-db-thirdparty/releases/download/v20210402130708-ee4e2e453b-centos7-devtoolset-9/yugabyte-db-thirdparty-v20210402130708-ee4e2e453b-centos7-devtoolset-9.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
https://github.com/yugabyte/yugabyte-db-thirdparty/releases/download/v20210210192517-45c97f45f1-macos/yugabyte-db-thirdparty-v20210210192517-45c97f45f1-macos.tar.gz | ||
https://github.com/yugabyte/yugabyte-db-thirdparty/releases/download/v20210402050931-ee4e2e453b-macos/yugabyte-db-thirdparty-v20210402050931-ee4e2e453b-macos.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
https://github.com/yugabyte/yugabyte-db-thirdparty/releases/download/v20210210212603-45c97f45f1-ubuntu1804-gcc7/yugabyte-db-thirdparty-v20210210212603-45c97f45f1-ubuntu1804-gcc7.tar.gz | ||
https://github.com/yugabyte/yugabyte-db-thirdparty/releases/download/v20210402084227-ee4e2e453b-ubuntu1804-gcc7/yugabyte-db-thirdparty-v20210402084227-ee4e2e453b-ubuntu1804-gcc7.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) Yugabyte, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
# in compliance with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under the License | ||
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
# or implied. See the License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import os | ||
import yaml | ||
import subprocess | ||
import argparse | ||
import tempfile | ||
import atexit | ||
import logging | ||
import shlex | ||
import packaging | ||
import re | ||
import time | ||
|
||
from packaging import version | ||
|
||
from yb.common_util import ( | ||
YB_SRC_ROOT, get_thirdparty_dir, get_download_cache_dir, load_yaml_file, init_env, shlex_join | ||
) | ||
|
||
from downloadutil.downloader import Downloader | ||
from downloadutil.download_config import DownloadConfig | ||
|
||
|
||
FOSSA_VERSION_RE = re.compile(r'^fossa-cli version ([^ ]+) .*$') | ||
MIN_FOSSA_CLI_VERSION = '1.1.7' | ||
|
||
|
||
def should_include_fossa_module(name: str) -> bool: | ||
return not name.startswith(('llvm', 'gmock', 'cassandra-cpp-driver', 'bison', 'flex')) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description='Run FOSSA analysis (open source license compliance).') | ||
parser.add_argument('--verbose', action='store_true', help='Enable verbose output') | ||
parser.add_argument( | ||
'fossa_cli_args', | ||
nargs='*', | ||
help='These arguments are passed directly to fossa-cli') | ||
args = parser.parse_args() | ||
init_env(args.verbose) | ||
|
||
fossa_cmd_line = ['fossa', 'analyze'] | ||
fossa_cmd_line.extend(args.fossa_cli_args) | ||
|
||
should_upload = not any( | ||
arg in args.fossa_cli_args for arg in ('--show-output', '--output', '-o')) | ||
|
||
if not should_upload and not os.getenv('FOSSA_API_KEY'): | ||
# --output is used for local analysis only, without uploading the results. In all other | ||
# cases we would like . | ||
raise RuntimeError('FOSSA_API_KEY must be specified in order to upload analysis results.') | ||
|
||
logging.info( | ||
f"FOSSA CLI command line (except the configuration path): {shlex_join(fossa_cmd_line)}") | ||
|
||
fossa_version_str = subprocess.check_output(['fossa', '--version']).decode('utf-8') | ||
fossa_version_match = FOSSA_VERSION_RE.match(fossa_version_str) | ||
if not fossa_version_match: | ||
raise RuntimeError(f"Cannot parse fossa-cli version: {fossa_version_str}") | ||
fossa_version = fossa_version_match.group(1) | ||
if version.parse(fossa_version) < version.parse(MIN_FOSSA_CLI_VERSION): | ||
raise RuntimeError( | ||
f"fossa-cli version too old: {fossa_version} " | ||
f"(expected {MIN_FOSSA_CLI_VERSION} or later)") | ||
|
||
download_cache_path = get_download_cache_dir() | ||
logging.info(f"Using the download cache directory {download_cache_path}") | ||
download_config = DownloadConfig( | ||
verbose=args.verbose, | ||
cache_dir_path=download_cache_path | ||
) | ||
downloader = Downloader(download_config) | ||
|
||
fossa_yml_path = os.path.join(YB_SRC_ROOT, '.fossa.yml') | ||
fossa_yml_data = load_yaml_file(fossa_yml_path) | ||
modules = fossa_yml_data['analyze']['modules'] | ||
|
||
thirdparty_dir = get_thirdparty_dir() | ||
fossa_modules_path = os.path.join(thirdparty_dir, 'fossa_modules.yml') | ||
|
||
seen_urls = set() | ||
|
||
start_time_sec = time.time() | ||
if os.path.exists(fossa_modules_path): | ||
thirdparty_fossa_modules_data = load_yaml_file(fossa_modules_path) | ||
for thirdparty_module_data in thirdparty_fossa_modules_data: | ||
fossa_module_data = thirdparty_module_data['fossa_module'] | ||
module_name = fossa_module_data['name'] | ||
if not should_include_fossa_module(module_name): | ||
continue | ||
fossa_module_yb_metadata = thirdparty_module_data['yb_metadata'] | ||
expected_sha256 = fossa_module_yb_metadata['sha256sum'] | ||
url = fossa_module_yb_metadata['url'] | ||
if url in seen_urls: | ||
# Due to a bug in some versions of yugabyte-db-thirdparty scripts, as of 04/20/2021 | ||
# we may include the same dependency twince in the fossa_modules.yml file. We just | ||
# skip the duplicates here. | ||
continue | ||
seen_urls.add(url) | ||
|
||
logging.info(f"Adding module from {url}") | ||
downloaded_path = downloader.download_url( | ||
url, | ||
download_parent_dir_path=None, # Download to cache directly. | ||
verify_checksum=True, | ||
expected_sha256=expected_sha256 | ||
) | ||
fossa_module_data['target'] = downloaded_path | ||
modules.append(fossa_module_data) | ||
|
||
effective_fossa_yml_path = os.path.join(os.getenv('BUILD_ROOT'), 'effective_fossa.yml') | ||
with open(effective_fossa_yml_path, 'w') as effective_fossa_yml_file: | ||
effective_fossa_yml_file.write(yaml.dump(fossa_yml_data, default_flow_style=False)) | ||
|
||
logging.info(f"Wrote the expanded FOSSA file to {effective_fossa_yml_path}") | ||
else: | ||
logging.warning( | ||
f"File {fossa_modules_path} does not exist. Some C/C++ dependencies will be missing " | ||
f"from FOSSA analysis.") | ||
|
||
effective_fossa_yml_path = fossa_yml_path | ||
|
||
fossa_cmd_line += ['--config', effective_fossa_yml_path] | ||
|
||
elapsed_time_sec = time.time() - start_time_sec | ||
logging.info("Generated the effective FOSSA configuration file in %.1f sec", elapsed_time_sec) | ||
logging.info(f"Running command: {shlex_join(fossa_cmd_line)})") | ||
subprocess.check_call(fossa_cmd_line) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ compiledb | |
psutil | ||
distro | ||
boto | ||
overrides | ||
overrides | ||
downloadutil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ psutil==5.5.1 | |
distro==1.5.0 | ||
boto==2.49.0 | ||
overrides==3.1.0 | ||
downloadutil==1.0.2 | ||
packaging==20.9 |
Submodule thirdparty
updated
23 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters