diff options
author | zaverden <zaverden@yandex-team.com> | 2024-04-22 08:48:33 +0300 |
---|---|---|
committer | zaverden <zaverden@yandex-team.com> | 2024-04-22 08:58:08 +0300 |
commit | 1d77668624e2483b5664ae4999537d7086be576b (patch) | |
tree | c49b3ba06de3f542cd62a7eb4b0a19eb8ba578ac /build/plugins | |
parent | 55f0e9fe0e7fe7ccba9365d822352dec9cf5332c (diff) | |
download | ydb-1d77668624e2483b5664ae4999537d7086be576b.tar.gz |
feat(conf): support prebuilder v1 in conf validation (with fallback to v0 logic)
Integration is added in backward-compatible manner with `v0.x.x`
1f45f7b3235314fb1ee8d2051ff6d592c95813f0
Diffstat (limited to 'build/plugins')
-rw-r--r-- | build/plugins/lib/nots/package_manager/base/lockfile.py | 4 | ||||
-rw-r--r-- | build/plugins/lib/nots/package_manager/base/package_json.py | 25 | ||||
-rw-r--r-- | build/plugins/lib/nots/package_manager/pnpm/lockfile.py | 10 | ||||
-rw-r--r-- | build/plugins/nots.py | 49 |
4 files changed, 73 insertions, 15 deletions
diff --git a/build/plugins/lib/nots/package_manager/base/lockfile.py b/build/plugins/lib/nots/package_manager/base/lockfile.py index b6b9952602..fde0ee2b49 100644 --- a/build/plugins/lib/nots/package_manager/base/lockfile.py +++ b/build/plugins/lib/nots/package_manager/base/lockfile.py @@ -74,3 +74,7 @@ class BaseLockfile(object): @abstractmethod def validate_has_addons_flags(self): pass + + @abstractmethod + def get_requires_build_packages(self): + pass diff --git a/build/plugins/lib/nots/package_manager/base/package_json.py b/build/plugins/lib/nots/package_manager/base/package_json.py index 2438511800..449b386556 100644 --- a/build/plugins/lib/nots/package_manager/base/package_json.py +++ b/build/plugins/lib/nots/package_manager/base/package_json.py @@ -222,3 +222,28 @@ class PackageJson(object): """ ws_map = self.get_workspace_map() return {pj.get_name(): path for path, (pj, _) in ws_map.items()} + + def validate_prebuilds(self, requires_build_packages: list[str]): + pnpm_overrides: dict[str, str] = self.data.get("pnpm", {}).get("overrides", {}) + use_prebuild_flags: dict[str, bool] = self.data.get("@yatool/prebuilder", {}).get("usePrebuild", {}) + + def covered(k: str) -> bool: + if k.startswith("@yandex-prebuild/"): + return True + return k in use_prebuild_flags + + not_covered = [key for key in requires_build_packages if not covered(key)] + use_prebuild_keys = [key for key in use_prebuild_flags if use_prebuild_flags[key]] + missing_overrides = [key for key in use_prebuild_keys if key not in pnpm_overrides] + + messages = [] + + if not_covered: + messages.append("These packages possibly have addons but are not checked yet:") + messages.extend([f" - {key}" for key in not_covered]) + + if missing_overrides: + messages.append("These packages have addons but overrides are not set:") + messages.extend([f" - {key}" for key in missing_overrides]) + + return (not messages, messages) diff --git a/build/plugins/lib/nots/package_manager/pnpm/lockfile.py b/build/plugins/lib/nots/package_manager/pnpm/lockfile.py index 46558861bd..fb8d688dea 100644 --- a/build/plugins/lib/nots/package_manager/pnpm/lockfile.py +++ b/build/plugins/lib/nots/package_manager/pnpm/lockfile.py @@ -112,6 +112,16 @@ class PnpmLockfile(BaseLockfile): return (not invalid_keys, invalid_keys) + def get_requires_build_packages(self): + packages = self.data.get("packages", {}) + requires_build_packages = [] + + for key, meta in iteritems(packages): + if meta.get("requiresBuild"): + requires_build_packages.append(key[1:]) # strip leading slash from key + + return requires_build_packages + def _parse_package_meta(key, meta, allow_file_protocol=False): """ diff --git a/build/plugins/nots.py b/build/plugins/nots.py index 9b0f854e17..49f003ace9 100644 --- a/build/plugins/nots.py +++ b/build/plugins/nots.py @@ -204,7 +204,7 @@ def on_peerdir_ts_resource(unit, *resources): @_with_report_configure_error def on_ts_configure(unit): - # type: (Unit, *str) -> None + # type: (Unit) -> None from lib.nots.package_manager.base import PackageJson from lib.nots.package_manager.base.utils import build_pj_path from lib.nots.typescript import TsConfig @@ -575,20 +575,6 @@ def on_node_modules_configure(unit): __set_append(unit, "_NODE_MODULES_INOUTS", _build_directives("output", ["hide"], sorted(outs))) if pj.get_use_prebuilder(): - lf = pm.load_lockfile_from_dir(pm.sources_path) - is_valid, invalid_keys = lf.validate_has_addons_flags() - - if not is_valid: - ymake.report_configure_error( - "Project is configured to use @yatool/prebuilder. \n" - + "Some packages in the pnpm-lock.yaml are misconfigured.\n" - + "Run `ya tool nots update-lockfile` to fix lockfile.\n" - + "All packages with `requiresBuild:true` have to be marked with `hasAddons:true/false`.\n" - + "Misconfigured keys: \n" - + " - " - + "\n - ".join(invalid_keys) - ) - unit.on_peerdir_ts_resource("@yatool/prebuilder") unit.set( [ @@ -597,6 +583,39 @@ def on_node_modules_configure(unit): ] ) + # YATOOL_PREBUILDER_0_7_0_RESOURCE_GLOBAL + prebuilder_major = unit.get("YATOOL_PREBUILDER-ROOT-VAR-NAME").split("_")[2] + logger.info(f"Detected prebuilder \033[0;32mv{prebuilder_major}.x.x\033[0;49m") + + if prebuilder_major == "0": + # TODO: FBP-1408 + lf = pm.load_lockfile_from_dir(pm.sources_path) + is_valid, invalid_keys = lf.validate_has_addons_flags() + + if not is_valid: + ymake.report_configure_error( + "Project is configured to use @yatool/prebuilder. \n" + + "Some packages in the pnpm-lock.yaml are misconfigured.\n" + + "Run \033[0;32m`ya tool nots update-lockfile`\033[0;49m to fix lockfile.\n" + + "All packages with `requiresBuild:true` have to be marked with `hasAddons:true/false`.\n" + + "Misconfigured keys: \n" + + " - " + + "\n - ".join(invalid_keys) + ) + else: + lf = pm.load_lockfile_from_dir(pm.sources_path) + requires_build_packages = lf.get_requires_build_packages() + is_valid, validation_messages = pj.validate_prebuilds(requires_build_packages) + + if not is_valid: + ymake.report_configure_error( + "Project is configured to use @yatool/prebuilder. \n" + + "Some packages are misconfigured.\n" + + "Run \033[0;32m`ya tool nots update-lockfile`\033[0;49m to fix pnpm-lock.yaml and package.json.\n" + + "Validation details: \n" + + "\n".join(validation_messages) + ) + @_with_report_configure_error def on_ts_test_for_configure(unit, test_runner, default_config, node_modules_filename): |