blob: f17002a2b9e79cfc956a169c109e013ce7fa003c [file] [log] [blame]
# Copyright 2021 The Pigweed Authors
# 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
# 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.
"""Install and check status of CRLSet and download chromium CRLSet."""
import os
import pathlib
import subprocess
from typing import Sequence
import pw_package.git_repo
import pw_package.package_manager
def crlset_tools_repo_path(path: pathlib.Path) -> pathlib.Path:
return path / 'crlset-tools'
def crlset_exec_path(path: pathlib.Path) -> pathlib.Path:
return path / 'crlset_exec'
def crlset_file_path(path: pathlib.Path) -> pathlib.Path:
return path / 'crlset'
class CRLSet(pw_package.package_manager.Package):
"""Install and check status of CRLSet and downloaded CLRSet file."""
def __init__(self, *args, **kwargs):
super().__init__(*args, name='crlset', **kwargs)
self._crlset_tools = pw_package.git_repo.GitRepo(
def status(self, path: pathlib.Path) -> bool:
if not self._crlset_tools.status(crlset_tools_repo_path(path)):
return False
# The executable should have been built and exist.
if not os.path.exists(crlset_exec_path(path)):
return False
# A crlset has been downloaded
if not os.path.exists(crlset_file_path(path)):
return False
return True
def install(self, path: pathlib.Path) -> None:
# Build the go tool
['go', 'build', '-o',
crlset_exec_path(path), 'crlset.go'],
crlset_tools_exec = crlset_exec_path(path)
if not os.path.exists(crlset_tools_exec):
raise FileNotFoundError('Fail to find crlset executable')
# Download the latest CRLSet with the go tool
with open(crlset_file_path(path), 'wb') as crlset_file:
fetched =[crlset_exec_path(path), 'fetch'],
def info(self, path: pathlib.Path) -> Sequence[str]:
return (
f'{} installed in: {path}',
"Enable by running 'gn args out' and adding this line:",
f' pw_tls_client_CRLSET_PATH = "{crlset_file_path(path)}"',