-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
A quick and dirty script for bisecting nixpkgs to find where we broke | ||
This is not complete and will probably not be, just keeping for reference | ||
""" | ||
|
||
from typing import List | ||
import math | ||
import argparse | ||
import logging | ||
import subprocess | ||
import re | ||
import os | ||
import shutil | ||
from pathlib import Path | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def main(): | ||
logging.basicConfig(encoding='utf-8', level=logging.DEBUG) | ||
args = argparser().parse_args() | ||
|
||
revlist_path: Path = Path(args.revlist) | ||
revlist = read_oneline_log(revlist_path) | ||
logger.info("Found %d revisions, bisection will take approximately %d steps", revlist, math.log2(len(revlist))) | ||
|
||
repo_dir = Path(__file__).parent.parent | ||
logger.info("Changing working directory to repo directory %s", repo_dir) | ||
os.chdir(repo_dir) | ||
|
||
logger.info("Initiating bisection") | ||
i_bad = 0 | ||
i_good = len(revlist) - 1 | ||
|
||
|
||
|
||
def argparser(): | ||
parser = argparse.ArgumentParser(prog='nixpkgs-bisect', description='Bisect nixpkgs') | ||
parser.add_argument( | ||
"--revlist", | ||
required=True, | ||
description=( | ||
"File containing nixpkgs revision list. Generate this from nixpkgs with this command:\n\n" | ||
"git log --oneline $KNOWN_GOOD_REV..master --no-abbrev-commit" | ||
) | ||
) | ||
return parser | ||
|
||
|
||
def read_oneline_log(revlist_path: Path) -> List[str]: | ||
with revlist.open() as f: | ||
return [ | ||
l.split()[0] | ||
for l in f | ||
] | ||
|
||
|
||
def change_this_repo_nixpkgs_version(flake_url: str): | ||
flake_file = Path('flake.nix') | ||
|
||
logger.info("Setting nixpkgs revision in %s to %s", flake_file, flake_url) | ||
|
||
with flakefile.open() as f: | ||
lines = list(f) | ||
lines[3] = f'nixpkgs.url = "{flake_url}";\n' | ||
|
||
with flakefile.open("w") as f: | ||
f.write(''.join(lines)) | ||
|
||
|
||
def set_nixpkgs_version(): | ||
pass | ||
|
||
|
||
def try_build() -> bool: | ||
""" | ||
Try to nix flake update and build. Returns True on success, False otherwise. | ||
""" | ||
|
||
cmd = "nix flake update && nix build" | ||
logger.info("Executing: %s", cmd) | ||
result = subprocess.run(cmd, shell=True) | ||
return result.returncode == 0 | ||
|
||
|
||
def run_command(cmd: str): | ||
logger.debug("Executing shell command: %s", cmd) | ||
result = subprocess.run(cmd, shell=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
|
||
nix flake update && nix build | ||
|