From ef76bfaaf010bfda44d79eb7e1836f45e87a7411 Mon Sep 17 00:00:00 2001 From: Justin Boswell Date: Tue, 2 Mar 2021 18:00:59 -0800 Subject: [PATCH] aws-lc/s2n fixes (#100) * Switched s2n from depending on libcrypto to aws-lc * Updates to s2n/aws-lc to make them play nice --- builder/actions/cmake.py | 2 +- builder/core/project.py | 13 ++++++++++--- builder/imports/awslc.py | 25 +++++++++++++++++++++++++ builder/imports/s2n.py | 6 ++++-- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/builder/actions/cmake.py b/builder/actions/cmake.py index ce96fdea4..d72da1b36 100644 --- a/builder/actions/cmake.py +++ b/builder/actions/cmake.py @@ -10,7 +10,7 @@ def _project_dirs(env, project): if not project.resolved(): - print('Project is not resolved: {}'.format(project.name)) + raise Exception('Project is not resolved: {}'.format(project.name)) source_dir = str(Path(project.path).relative_to(env.root_dir)) build_dir = str(Path(os.path.join(env.build_dir, project.name)).relative_to(env.root_dir)) diff --git a/builder/core/project.py b/builder/core/project.py index 677d70f9a..59568d030 100644 --- a/builder/core/project.py +++ b/builder/core/project.py @@ -604,6 +604,7 @@ def get_config(self, spec, overrides=None, **additional_vars): # project cache _projects = {} + _imports = {} @staticmethod def _publish_variable(var, value): @@ -632,9 +633,15 @@ def _cache_project(project): Project._projects[project.name.lower()] = project if getattr(project, 'path', None): Scripts.load(project.path) - return project + @staticmethod + def _cache_import(imp): + Project._imports[imp.name.lower()] = imp + if getattr(imp, 'path', None): + Scripts.load(imp.path) + return imp + @staticmethod def default_project(): project = Project._project_from_path('.') @@ -716,7 +723,7 @@ def find_project(name, hints=None): def find_import(name, hints=None): if hints is None: hints = [] - imp = Project._projects.get(name.lower(), None) + imp = Project._imports.get(name.lower(), None) if imp and imp.resolved(): return imp @@ -724,5 +731,5 @@ def find_import(name, hints=None): Scripts.load(h) imp_cls = Project._find_import_class(name) if imp_cls: - return Project._cache_project(imp_cls()) + return Project._cache_import(imp_cls()) return Import(name=name, resolved=False) diff --git a/builder/imports/awslc.py b/builder/imports/awslc.py index 4285c0524..9c51695eb 100644 --- a/builder/imports/awslc.py +++ b/builder/imports/awslc.py @@ -1,7 +1,10 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0. +import os + from builder.core.project import Project, Import +from builder.actions.git import DownloadSource config = { @@ -13,15 +16,37 @@ class AWSLCImport(Import): def __init__(self, **kwargs): + if kwargs.get('name'): + del kwargs['name'] super().__init__( library=True, + name='aws-lc', config=config, **kwargs) + def pre_build(self, env): + # Search for an aws-lc directory + if not hasattr(self, 'path'): + for root, dirs, files in os.walk(env.deps_dir): + for search_dir in dirs: + if search_dir.endswith('aws-lc'): + self.path = os.path.join(root, search_dir) + break + # No aws-lc directory, download to deps dir now + if not hasattr(self, 'path'): + self.path = os.path.join(env.deps_dir, 'aws-lc') + DownloadSource(project=Project.find_project(self.name), path=env.deps_dir).run(env) + + def build(self, env): + return Project.build(Project.find_project(self.name, [self.path]), env) + class AWSLCProject(Project): def __init__(self, **kwargs): + if kwargs.get('name'): + del kwargs['name'] super().__init__( account='awslabs', + name='aws-lc', config=config, **kwargs) diff --git a/builder/imports/s2n.py b/builder/imports/s2n.py index 123e25338..4790637b4 100644 --- a/builder/imports/s2n.py +++ b/builder/imports/s2n.py @@ -15,8 +15,9 @@ class S2NImport(Import): def __init__(self, **kwargs): super().__init__( library=True, - upstreams=['aws-lc'], + imports=['aws-lc'], config=config, + url='https://github.com/aws/s2n-tls.git', **kwargs) @@ -24,6 +25,7 @@ class S2NProject(Project): def __init__(self, **kwargs): super().__init__( account='awslabs', - upstreams=['aws-lc'], + imports=['aws-lc'], config=config, + url='https://github.com/aws/s2n-tls.git', **kwargs)