mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-09-29 03:10:19 +00:00
jetbrains.*: updater: update for by-name migration
This commit is contained in:
committed by
Marco Köpcke
parent
ce68722dfd
commit
a1e1d94d1c
@@ -24,6 +24,7 @@ class UpdaterConfig:
|
||||
no_bin: bool
|
||||
no_src: bool
|
||||
no_maven_deps: bool
|
||||
dry_run: bool
|
||||
|
||||
def __init__(self, argparse_result):
|
||||
self.nixpkgs_root = (
|
||||
@@ -47,3 +48,4 @@ class UpdaterConfig:
|
||||
self.no_bin = argparse_result.no_bin
|
||||
self.no_src = argparse_result.no_src
|
||||
self.no_maven_deps = argparse_result.no_maven_deps
|
||||
self.dry_run = argparse_result.dry_run
|
||||
|
||||
@@ -22,43 +22,33 @@ class Ide:
|
||||
update_info: UpdateInfo | None
|
||||
|
||||
|
||||
def is_source_ide(drv_path: Path):
|
||||
assert " " not in str(drv_path)
|
||||
try:
|
||||
return (
|
||||
run_command(
|
||||
[
|
||||
"nix-instantiate",
|
||||
"--eval",
|
||||
"-E",
|
||||
f'builtins.hasAttr "mkJetBrainsSource" (builtins.functionArgs (import {drv_path}))',
|
||||
]
|
||||
)
|
||||
== "true"
|
||||
)
|
||||
except CalledProcessError as ex:
|
||||
print(f"Failed to eval {drv_path}: {ex.stderr}", file=sys.stderr)
|
||||
exit(1)
|
||||
def by_name_path(ide_name: str, nixpkgs_root: Path) -> Path:
|
||||
by_name_stem = ide_name[0:2]
|
||||
return nixpkgs_root / "pkgs" / "by-name" / by_name_stem / ide_name
|
||||
|
||||
|
||||
def get_single_ide(update_info: dict[str, UpdateInfo], jb_root: Path, name: str) -> Ide:
|
||||
drv_path = jb_root / "ides" / f"{name}.nix"
|
||||
def is_source_ide(ide_name: str):
|
||||
return ide_name.endswith("-oss")
|
||||
|
||||
|
||||
def get_single_ide(update_info: dict[str, UpdateInfo], nixpkgs_root: Path, name: str) -> Ide:
|
||||
drv_path = by_name_path(name, nixpkgs_root) / "package.nix"
|
||||
if not drv_path.exists():
|
||||
raise Exception(f"IDE not found at {drv_path}")
|
||||
return Ide(
|
||||
name=name,
|
||||
drv_path=drv_path,
|
||||
is_source=is_source_ide(drv_path),
|
||||
is_source=is_source_ide(name),
|
||||
update_info=update_info.get(name),
|
||||
)
|
||||
|
||||
|
||||
def get_all_ides(update_info: dict[str, UpdateInfo], jb_root: Path) -> Iterable[Ide]:
|
||||
for file in sorted((jb_root / "ides").iterdir()):
|
||||
if file.suffix == ".nix":
|
||||
yield Ide(
|
||||
name=file.stem,
|
||||
drv_path=file,
|
||||
is_source=is_source_ide(file),
|
||||
update_info=update_info.get(file.stem),
|
||||
)
|
||||
def get_all_ides(update_info: dict[str, UpdateInfo], nixpkgs_root: Path) -> Iterable[Ide]:
|
||||
for name, update_info in update_info.items():
|
||||
drv_path = by_name_path(name, nixpkgs_root) / "package.nix"
|
||||
yield Ide(
|
||||
name=name,
|
||||
drv_path=drv_path,
|
||||
is_source=is_source_ide(name),
|
||||
update_info=update_info,
|
||||
)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
import json
|
||||
@@ -8,7 +9,7 @@ from subprocess import CalledProcessError
|
||||
|
||||
from jetbrains_nix_updater.config import UpdaterConfig
|
||||
from jetbrains_nix_updater.fetcher import VersionInfo
|
||||
from jetbrains_nix_updater.ides import Ide
|
||||
from jetbrains_nix_updater.ides import Ide, by_name_path
|
||||
from jetbrains_nix_updater.update_src_maven import (
|
||||
get_maven_deps_for_ide,
|
||||
ensure_is_list,
|
||||
@@ -148,10 +149,6 @@ def generate_jps_hash(config: UpdaterConfig, root_path: Path) -> str:
|
||||
)
|
||||
|
||||
|
||||
def maven_out_path(jb_root: Path, name: str) -> Path:
|
||||
return jb_root / "source" / f"{name}_maven_artefacts.json"
|
||||
|
||||
|
||||
def run_src_update(ide: Ide, info: VersionInfo, config: UpdaterConfig) -> bool:
|
||||
variant = ide.name.removesuffix("-oss")
|
||||
try:
|
||||
@@ -194,7 +191,7 @@ def run_src_update(ide: Ide, info: VersionInfo, config: UpdaterConfig) -> bool:
|
||||
androidHash = "{android_hash}";
|
||||
jpsHash = "{jps_hash}";
|
||||
restarterHash = "{restarter_hash}";
|
||||
mvnDeps = ../source/{variant}_maven_artefacts.json;
|
||||
mvnDeps = ./maven_artefacts.json;
|
||||
repositories = [
|
||||
{repositories_nix}
|
||||
];
|
||||
@@ -213,7 +210,12 @@ def run_src_update(ide: Ide, info: VersionInfo, config: UpdaterConfig) -> bool:
|
||||
if not config.no_maven_deps:
|
||||
print("[*] Collecting maven hashes")
|
||||
maven_hashes = get_maven_deps_for_ide(config, ide)
|
||||
with open(maven_out_path(config.jetbrains_root, variant), "w") as f:
|
||||
json.dump(maven_hashes, f, indent=4)
|
||||
f.write("\n")
|
||||
maven_out_path = by_name_path(ide.name, config.nixpkgs_root) / "maven_artefacts.json"
|
||||
if config.dry_run:
|
||||
assert maven_out_path.parent.exists()
|
||||
print(f"[D] --dry-run: {maven_out_path} not modified", file=sys.stderr)
|
||||
else:
|
||||
with open(maven_out_path, "w") as f:
|
||||
json.dump(maven_hashes, f, indent=4)
|
||||
f.write("\n")
|
||||
return True
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import sys
|
||||
from typing import Iterable
|
||||
|
||||
import subprocess
|
||||
@@ -45,6 +46,10 @@ def replace_blocks(
|
||||
with open(file, "r") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
if config.dry_run:
|
||||
print(f"[D] --dry-run: {file} not modified", file=sys.stderr)
|
||||
return
|
||||
|
||||
for name, block in blocks:
|
||||
old_lines = lines
|
||||
lines = []
|
||||
|
||||
@@ -34,6 +34,9 @@ def main():
|
||||
action="store_true",
|
||||
help="do not update maven dependencies for source IDEs",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--dry-run", action="store_true", help="do not change any files"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--old-version",
|
||||
type=str,
|
||||
@@ -50,9 +53,9 @@ def main():
|
||||
version_fetcher = VersionFetcher()
|
||||
|
||||
ides_to_run_for = (
|
||||
[get_single_ide(update_info, config.jetbrains_root, config.ide)]
|
||||
[get_single_ide(update_info, config.nixpkgs_root, config.ide)]
|
||||
if config.ide is not None
|
||||
else list(get_all_ides(update_info, config.jetbrains_root))
|
||||
else list(get_all_ides(update_info, config.nixpkgs_root))
|
||||
)
|
||||
|
||||
print(f"[.] found IDEs to update: {', '.join(ide.name for ide in ides_to_run_for)}")
|
||||
|
||||
Reference in New Issue
Block a user