lol

radare2: rework update script to include cutter's radare2 version

+192 -137
+98 -5
pkgs/development/tools/analysis/radare2/default.nix
··· 1 - { callPackage, ...} @ args: 1 + {stdenv, fetchFromGitHub 2 + , callPackage 3 + , ninja, meson , pkgconfig 4 + , libusb, readline, libewf, perl, zlib, openssl 5 + , gtk2 ? null, vte ? null, gtkdialog ? null 6 + , python ? null 7 + , ruby ? null 8 + , lua ? null 9 + , useX11, rubyBindings, pythonBindings, luaBindings 10 + }: 11 + 12 + assert useX11 -> (gtk2 != null && vte != null && gtkdialog != null); 13 + assert rubyBindings -> ruby != null; 14 + assert pythonBindings -> python != null; 15 + 16 + 17 + let 18 + inherit (stdenv.lib) optional; 19 + 20 + generic = { 21 + version_commit, 22 + gittap, 23 + gittip, 24 + rev, 25 + version, 26 + sha256, 27 + cs_tip, 28 + cs_sha256 29 + }: 30 + stdenv.mkDerivation rec { 31 + name = "radare2-${version}"; 32 + 33 + src = fetchFromGitHub { 34 + owner = "radare"; 35 + repo = "radare2"; 36 + inherit rev sha256; 37 + }; 38 + 39 + postPatch = let 40 + capstone = fetchFromGitHub { 41 + owner = "aquynh"; 42 + repo = "capstone"; 43 + # version from $sourceRoot/shlr/Makefile 44 + rev = cs_tip; 45 + sha256 = cs_sha256; 46 + }; 47 + in '' 48 + if ! grep -F "CS_TIP=${cs_tip}" shlr/Makefile; then echo "CS_TIP mismatch"; exit 1; fi 49 + # When using meson, it expects capstone source relative to build directory 50 + mkdir -p build/shlr 51 + ln -s ${capstone} build/shlr/capstone 52 + ''; 53 + 54 + postInstall = '' 55 + ln -s $out/bin/radare2 $out/bin/r2 56 + install -D -m755 $src/binr/r2pm/r2pm $out/bin/r2pm 57 + ''; 2 58 3 - callPackage ./generic.nix (args // { 59 + mesonFlags = [ 60 + "-Dr2_version_commit=${version_commit}" 61 + "-Dr2_gittap=${gittap}" 62 + "-Dr2_gittip=${gittip}" 63 + # 2.8.0 expects this, but later it becomes an option with default=false. 64 + "-Dcapstone_in_builddir=true" 65 + ]; 66 + 67 + enableParallelBuilding = true; 68 + 69 + nativeBuildInputs = [ pkgconfig ninja meson ]; 70 + buildInputs = [ readline libusb libewf perl zlib openssl] 71 + ++ optional useX11 [gtkdialog vte gtk2] 72 + ++ optional rubyBindings [ruby] 73 + ++ optional pythonBindings [python] 74 + ++ optional luaBindings [lua]; 75 + 76 + meta = { 77 + description = "unix-like reverse engineering framework and commandline tools"; 78 + homepage = http://radare.org/; 79 + license = stdenv.lib.licenses.gpl2Plus; 80 + maintainers = with stdenv.lib.maintainers; [raskin makefu mic92]; 81 + platforms = with stdenv.lib.platforms; linux; 82 + inherit version; 83 + }; 84 + }; 85 + in { 4 86 #<generated> 5 87 # DO NOT EDIT! Automatically generated by ./update.py 6 - src_info = { 7 - version_commit = "19004"; 88 + radare2 = generic { 89 + version_commit = "19251"; 8 90 gittap = "2.8.0"; 9 91 gittip = "a76b965410aba07b4ef8b96d90b25b271c2003dd"; 92 + rev = "2.8.0"; 10 93 version = "2.8.0"; 11 94 sha256 = "1d9rkzc3vychy2h1bnywwx4why83rr18r0lvvl1cqx87ad5awcjk"; 12 95 cs_tip = "782ea67e17a391ca0d3faafdc365b335a1a8930a"; 13 96 cs_sha256 = "1maww4ir78a193pm3f8lr2kdkizi7rywn68ffa65ipyr7j4pl6i4"; 14 97 }; 98 + r2-for-cutter = generic { 99 + version_commit = "19251"; 100 + gittap = "2.8.0-118-gb0547831f"; 101 + gittip = "b0547831f127b7357e3c93bc43933482a4d6213b"; 102 + rev = "b0547831f127b7357e3c93bc43933482a4d6213b"; 103 + version = "2018-08-07"; 104 + sha256 = "1ix42kipd1aayb494ajbxawzc1cwikm9fxk343d1kchxx4a30a1m"; 105 + cs_tip = "782ea67e17a391ca0d3faafdc365b335a1a8930a"; 106 + cs_sha256 = "1maww4ir78a193pm3f8lr2kdkizi7rywn68ffa65ipyr7j4pl6i4"; 107 + }; 15 108 #</generated> 16 - }) 109 + }
-75
pkgs/development/tools/analysis/radare2/generic.nix
··· 1 - {stdenv, fetchFromGitHub 2 - , src_info, callPackage 3 - , ninja, meson , pkgconfig 4 - , libusb, readline, libewf, perl, zlib, openssl 5 - , gtk2 ? null, vte ? null, gtkdialog ? null 6 - , python ? null 7 - , ruby ? null 8 - , lua ? null 9 - , useX11, rubyBindings, pythonBindings, luaBindings 10 - }: 11 - 12 - assert useX11 -> (gtk2 != null && vte != null && gtkdialog != null); 13 - assert rubyBindings -> ruby != null; 14 - assert pythonBindings -> python != null; 15 - 16 - 17 - let 18 - inherit (stdenv.lib) optional; 19 - in stdenv.mkDerivation (with src_info; rec { 20 - name = "radare2-${version}"; 21 - 22 - src = fetchFromGitHub { 23 - owner = "radare"; 24 - repo = "radare2"; 25 - rev = version; 26 - inherit sha256; 27 - }; 28 - 29 - postPatch = let 30 - capstone = fetchFromGitHub { 31 - owner = "aquynh"; 32 - repo = "capstone"; 33 - # version from $sourceRoot/shlr/Makefile 34 - rev = cs_tip; 35 - sha256 = cs_sha256; 36 - }; 37 - in '' 38 - if ! grep -F "CS_TIP=${cs_tip}" shlr/Makefile; then echo "CS_TIP mismatch"; exit 1; fi 39 - # When using meson, it expects capstone source relative to build directory 40 - mkdir -p build/shlr 41 - ln -s ${capstone} build/shlr/capstone 42 - ''; 43 - 44 - postInstall = '' 45 - ln -s $out/bin/radare2 $out/bin/r2 46 - install -D -m755 $src/binr/r2pm/r2pm $out/bin/r2pm 47 - ''; 48 - 49 - mesonFlags = [ 50 - "-Dr2_version_commit=${version_commit}" 51 - "-Dr2_gittap=${gittap}" 52 - "-Dr2_gittip=${gittip}" 53 - # 2.8.0 expects this, but later it becomes an option with default=false. 54 - "-Dcapstone_in_builddir=true" 55 - ]; 56 - 57 - enableParallelBuilding = true; 58 - 59 - nativeBuildInputs = [ pkgconfig ninja meson ]; 60 - buildInputs = [ readline libusb libewf perl zlib openssl] 61 - ++ optional useX11 [gtkdialog vte gtk2] 62 - ++ optional rubyBindings [ruby] 63 - ++ optional pythonBindings [python] 64 - ++ optional luaBindings [lua]; 65 - 66 - meta = { 67 - description = "unix-like reverse engineering framework and commandline tools"; 68 - homepage = http://radare.org/; 69 - license = stdenv.lib.licenses.gpl2Plus; 70 - maintainers = with stdenv.lib.maintainers; [raskin makefu mic92]; 71 - platforms = with stdenv.lib.platforms; linux; 72 - inherit version; 73 - }; 74 - }) 75 -
-16
pkgs/development/tools/analysis/radare2/r2-for-cutter.nix
··· 1 - { callPackage, ...} @ args: 2 - 3 - callPackage ./generic.nix (args // { 4 - #<generated> 5 - # DO NOT EDIT! Automatically generated by ./update.py 6 - src_info = { 7 - version_commit = "19256"; 8 - gittap = "2.8.0-118-gb0547831f"; 9 - gittip = "b0547831f127b7357e3c93bc43933482a4d6213b"; 10 - version = "2.9.0-git"; 11 - sha256 = "1ix42kipd1aayb494ajbxawzc1cwikm9fxk343d1kchxx4a30a1m"; 12 - cs_tip = "782ea67e17a391ca0d3faafdc365b335a1a8930a"; 13 - cs_sha256 = "1maww4ir78a193pm3f8lr2kdkizi7rywn68ffa65ipyr7j4pl6i4"; 14 - }; 15 - #</generated> 16 - })
+90 -31
pkgs/development/tools/analysis/radare2/update.py
··· 3 3 # USAGE - just run the script: ./update.py 4 4 # When editing this file, make also sure it passes the mypy typecheck 5 5 # and is formatted with yapf. 6 - import urllib.request 7 - import json 8 - import tempfile 9 - import subprocess 10 6 import fileinput 7 + import json 11 8 import re 9 + import subprocess 10 + import tempfile 11 + import urllib.request 12 + from datetime import datetime 12 13 from pathlib import Path 14 + from typing import Dict 13 15 14 16 15 17 def sh(*args: str) -> str: ··· 18 20 19 21 20 22 def prefetch_github(owner: str, repo: str, ref: str) -> str: 21 - return sh("nix-prefetch-url", "--unpack", 22 - f"https://github.com/{owner}/{repo}/archive/{ref}.tar.gz") 23 + return sh( 24 + "nix-prefetch-url", 25 + "--unpack", 26 + f"https://github.com/{owner}/{repo}/archive/{ref}.tar.gz", 27 + ) 23 28 24 29 25 - def main() -> None: 30 + def get_radare2_rev() -> str: 26 31 url = "https://api.github.com/repos/radare/radare2/releases/latest" 27 32 with urllib.request.urlopen(url) as response: 28 33 release = json.load(response) # type: ignore 29 - version = release["tag_name"] 30 - with tempfile.TemporaryDirectory() as dirname: 34 + return release["tag_name"] 35 + 36 + 37 + def get_r2_cutter_rev() -> str: 38 + url = "https://api.github.com/repos/radareorg/cutter/contents/" 39 + with urllib.request.urlopen(url) as response: 40 + data = json.load(response) # type: ignore 41 + for entry in data: 42 + if entry["name"] == "radare2": 43 + return entry["sha"] 44 + raise Exception("no radare2 submodule found in github.com/radareorg/cutter") 45 + 46 + 47 + def git(dirname: str, *args: str) -> str: 48 + return sh("git", "-C", dirname, *args) 49 + 50 + 51 + def get_repo_info(dirname: str, rev: str) -> Dict[str, str]: 52 + sha256 = prefetch_github("radare", "radare2", rev) 53 + 54 + cs_tip = None 55 + with open(Path(dirname).joinpath("shlr", "Makefile")) as makefile: 56 + for l in makefile: 57 + match = re.match("CS_TIP=(\S+)", l) 58 + if match: 59 + cs_tip = match.group(1) 60 + assert cs_tip is not None 61 + 62 + cs_sha256 = prefetch_github("aquynh", "capstone", cs_tip) 63 + 64 + return dict( 65 + rev=rev, 66 + sha256=sha256, 67 + version_commit=git(dirname, "rev-list", "--all", "--count"), 68 + gittap=git(dirname, "describe", "--tags", "--match", "[0-9]*"), 69 + gittip=git(dirname, "rev-parse", "HEAD"), 70 + cs_tip=cs_tip, 71 + cs_sha256=cs_sha256, 72 + ) 73 + 74 + 75 + def write_package_expr(version: str, info: Dict[str, str]) -> str: 76 + return f"""generic {{ 77 + version_commit = "{info["version_commit"]}"; 78 + gittap = "{info["gittap"]}"; 79 + gittip = "{info["gittip"]}"; 80 + rev = "{info["rev"]}"; 81 + version = "{version}"; 82 + sha256 = "{info["sha256"]}"; 83 + cs_tip = "{info["cs_tip"]}"; 84 + cs_sha256 = "{info["cs_sha256"]}"; 85 + }}""" 31 86 32 - def git(*args: str) -> str: 33 - return sh("git", "-C", dirname, *args) 34 87 35 - git("clone", "--branch", version, "https://github.com/radare/radare2", 36 - ".") 37 - sha256 = prefetch_github("radare", "radare2", version) 88 + def main() -> None: 89 + radare2_rev = get_radare2_rev() 90 + r2_cutter_rev = get_r2_cutter_rev() 91 + 92 + with tempfile.TemporaryDirectory() as dirname: 93 + git( 94 + dirname, 95 + "clone", 96 + "--branch", 97 + radare2_rev, 98 + "https://github.com/radare/radare2", 99 + ".", 100 + ) 38 101 nix_file = str(Path(__file__).parent.joinpath("default.nix")) 39 102 40 - cs_tip = None 41 - with open(Path(dirname).joinpath("shlr", "Makefile")) as makefile: 42 - for l in makefile: 43 - match = re.match("CS_TIP=(\S+)", l) 44 - if match: 45 - cs_tip = match.group(1) 46 - assert cs_tip is not None 103 + radare2_info = get_repo_info(dirname, radare2_rev) 104 + 105 + git(dirname, "checkout", r2_cutter_rev) 106 + 107 + timestamp = git(dirname, "log", "-n1", "--format=%at") 108 + r2_cutter_version = datetime.fromtimestamp(int(timestamp)).strftime("%Y-%m-%d") 47 109 48 - cs_sha256 = prefetch_github("aquynh", "capstone", cs_tip) 110 + r2_cutter_info = get_repo_info(dirname, r2_cutter_rev) 49 111 50 112 in_block = False 51 113 with fileinput.FileInput(nix_file, inplace=True) as f: 52 114 for l in f: 53 115 if "#<generated>" in l: 54 116 in_block = True 55 - print(f""" #<generated> 117 + print( 118 + f""" #<generated> 56 119 # DO NOT EDIT! Automatically generated by ./update.py 57 - version_commit = "{git("rev-list", "--all", "--count")}"; 58 - gittap = "{git("describe", "--tags", "--match", "[0-9]*")}"; 59 - gittip = "{git("rev-parse", "HEAD")}"; 60 - version = "{version}"; 61 - sha256 = "{sha256}"; 62 - cs_tip = "{cs_tip}"; 63 - cs_sha256 = "{cs_sha256}"; 64 - #</generated>""") 120 + radare2 = {write_package_expr(radare2_rev, radare2_info)}; 121 + r2-for-cutter = {write_package_expr(r2_cutter_version, r2_cutter_info)}; 122 + #</generated>""" 123 + ) 65 124 elif "#</generated>" in l: 66 125 in_block = False 67 126 elif not in_block:
+4 -10
pkgs/top-level/all-packages.nix
··· 8532 8532 rubyBindings = config.radare.rubyBindings or false; 8533 8533 luaBindings = config.radare.luaBindings or false; 8534 8534 }; 8535 - radare2 = callPackage ../development/tools/analysis/radare2 { 8536 - inherit (gnome2) vte; 8537 - lua = lua5; 8538 - useX11 = config.radare.useX11 or false; 8539 - pythonBindings = config.radare.pythonBindings or false; 8540 - rubyBindings = config.radare.rubyBindings or false; 8541 - luaBindings = config.radare.luaBindings or false; 8542 - }; 8543 - r2-for-cutter = callPackage ../development/tools/analysis/radare2/r2-for-cutter.nix { 8535 + 8536 + inherit (callPackages ../development/tools/analysis/radare2 { 8544 8537 inherit (gnome2) vte; 8545 8538 lua = lua5; 8546 8539 useX11 = config.radare.useX11 or false; 8547 8540 pythonBindings = config.radare.pythonBindings or false; 8548 8541 rubyBindings = config.radare.rubyBindings or false; 8549 8542 luaBindings = config.radare.luaBindings or false; 8550 - }; 8543 + }) radare2 r2-for-cutter; 8544 + 8551 8545 radare2-cutter = libsForQt5.callPackage ../development/tools/analysis/radare2/cutter.nix { }; 8552 8546 8553 8547 ragel = ragelStable;