| @@ -13,7 +13,6 @@ logger = logging.getLogger(__name__) | |||
| @dataclass | |||
| class Configuration: | |||
| name: str | |||
| kotlin_version: str | |||
| gradle_version: Optional[str] | |||
| plugins: list[Plugin] | |||
| @@ -31,7 +30,7 @@ def parse_config(path: Path) -> Optional[Config]: | |||
| data = yaml.safe_load(f) | |||
| error: list[str] = [] | |||
| configurations: list[Configuration] = [] | |||
| configurations: dict[tuple[str, str], tuple[list[Plugin], list[Package]]] = {} | |||
| for i, section in enumerate(data.get('configurations')): | |||
| if (kotlin_versions := section.get('kotlin-version')) is None: | |||
| @@ -47,14 +46,17 @@ def parse_config(path: Path) -> Optional[Config]: | |||
| plugins = handle_plugins(section.get('plugins', {})) | |||
| packages = handle_packages(section.get('packages', {})) | |||
| configurations.extend( | |||
| [ | |||
| c | |||
| for kotlin in kotlin_versions | |||
| for gradle in gradle_versions | |||
| for c in generate_configurations(kotlin, gradle, plugins, packages) | |||
| ] | |||
| ) | |||
| for kotlin in kotlin_versions: | |||
| for gradle in gradle_versions: | |||
| key = (kotlin, gradle) | |||
| if key in configurations: | |||
| configurations[key] = ( | |||
| configurations[key][0] + plugins, | |||
| configurations[key][1] + packages, | |||
| ) | |||
| else: | |||
| configurations[key] = (plugins, packages) | |||
| if error: | |||
| for msg in error: | |||
| @@ -63,29 +65,9 @@ def parse_config(path: Path) -> Optional[Config]: | |||
| return None | |||
| else: | |||
| return Config( | |||
| configurations, | |||
| [ | |||
| Configuration(kotlin, gradle, plugins, packages) | |||
| for (kotlin, gradle), (plugins, packages) in configurations.items() | |||
| ], | |||
| data.get('maven', {}).get('mirrors', []), | |||
| ) | |||
| def generate_configurations(kotlin: str, gradle: str, plugins: list[Plugin], packages: list[Package]) -> list[Configuration]: | |||
| configurations = [] | |||
| configurations.append(Configuration( | |||
| name=f'{kotlin}-packages', | |||
| kotlin_version=kotlin, | |||
| gradle_version=gradle, | |||
| plugins=[], | |||
| packages=packages | |||
| )) | |||
| for j, plugin in enumerate(plugins): | |||
| configurations.append(Configuration( | |||
| name=f'{kotlin}-plugins-{j}', | |||
| kotlin_version=kotlin, | |||
| gradle_version=gradle, | |||
| plugins=[plugin], | |||
| packages=[] | |||
| )) | |||
| return configurations | |||
| @@ -1,6 +1,36 @@ | |||
| import logging | |||
| from pathlib import Path | |||
| from typing import Iterable | |||
| from config import Package, Plugin | |||
| from config import Configuration, Plugin, Package | |||
| logger = logging.getLogger(__name__) | |||
| def create_gradle(configuration: Configuration, repo: str, output_dir: Path): | |||
| gradle_path = output_dir / (configuration.gradle_version or "default") | |||
| name = f'kotlin-{configuration.kotlin_version}' | |||
| kotlin = configuration.kotlin_version | |||
| if configuration.packages: | |||
| create_gradle_project(f'{name}-packages', gradle_path, kotlin, [], configuration.packages, repo) | |||
| for i, plugin in enumerate(configuration.plugins): | |||
| create_gradle_project(f'{name}-plugins-{i}', gradle_path, kotlin, [plugin], [], repo) | |||
| def create_gradle_project(name: str, gradle_path, kotlin: str, plugins: Iterable[Plugin], packages: Iterable[Package], repo: str): | |||
| path = gradle_path / name | |||
| logger.debug(f'Creating {path}') | |||
| path.mkdir(parents=True) | |||
| logger.debug('Generating build.gradle.kts') | |||
| gradle_build = create_gradle_build(kotlin, set(plugins), set(packages), repo) | |||
| (path / 'build.gradle.kts').write_text(gradle_build) | |||
| logger.debug('Generating settings.gradle.kts') | |||
| gradle_settings = create_gradle_settings(repo) | |||
| (path / 'settings.gradle.kts').write_text(gradle_settings) | |||
| def create_gradle_settings(repo: str) -> str: | |||
| @@ -1,41 +1,31 @@ | |||
| import argparse | |||
| import asyncio | |||
| import dataclasses | |||
| import logging | |||
| from pathlib import Path | |||
| from maven import get_effective_packages | |||
| from config import parse_config, Configuration | |||
| from gradle import create_gradle_build, create_gradle_settings | |||
| from gradle import create_gradle | |||
| from maven import get_effective_packages | |||
| from maven.plugins import get_effective_plugins | |||
| logger = logging.getLogger(__name__) | |||
| async def resolve_kotlin(ident: str, configuration: Configuration, output_dir: Path, mirrors: list[str], gradle_repo: str): | |||
| resolved_packages = set([ | |||
| async def resolve_kotlin(configuration: Configuration, mirrors: list[str]): | |||
| packages = [ | |||
| resolved | |||
| for package in configuration.packages | |||
| for resolved in await get_effective_packages(package, mirrors) | |||
| ]) | |||
| ] | |||
| resolved_plugins = set([ | |||
| plugins = [ | |||
| resolved | |||
| for plugin in configuration.plugins | |||
| for resolved in await get_effective_plugins(plugin, mirrors) | |||
| ]) | |||
| gradle_path = configuration.gradle_version or "default" | |||
| path = output_dir / f"{gradle_path}/{ident}-kotlin-{configuration.kotlin_version}" | |||
| path.mkdir(parents=True) | |||
| logger.debug(f'Creating {path}') | |||
| logger.debug('Generating build.gradle.kts') | |||
| gradle_build = create_gradle_build(configuration.kotlin_version, resolved_plugins, resolved_packages, gradle_repo) | |||
| (path / 'build.gradle.kts').write_text(gradle_build) | |||
| ] | |||
| logger.debug('Generating settings.gradle.kts') | |||
| gradle_settings = create_gradle_settings(gradle_repo) | |||
| (path / 'settings.gradle.kts').write_text(gradle_settings) | |||
| return dataclasses.replace(configuration, packages=packages, plugins=plugins) | |||
| async def main(package_list: Path, output_dir: Path, gradle_repo: str) -> None: | |||
| @@ -51,7 +41,8 @@ async def main(package_list: Path, output_dir: Path, gradle_repo: str) -> None: | |||
| for i, configuration in enumerate(config.configurations): | |||
| logger.info(f'Resolving configuration kotlin={configuration.kotlin_version}, gradle={configuration.gradle_version}') | |||
| try: | |||
| await resolve_kotlin(str(i), configuration, output_dir, config.mirrors, gradle_repo) | |||
| configuration = await resolve_kotlin(configuration, config.mirrors) | |||
| create_gradle(configuration, gradle_repo, output_dir) | |||
| except: | |||
| logger.exception(f'Error resolving kotlin version {configuration.kotlin_version}') | |||