git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #44650 from dtzWill/update/r2-2.8.0

radare2: 2.7.0 -> 2.8.0, radare2-cutter: 1.6 -> 1.7, refactor

commitcf68a14a0184138ca7644a14c0724fa32e0e34a5 authorWill Dietz <github@wdtz.org> dateWed 22 Aug 2018, 09:40 (8 years ago) parent05310e336d8beb
4 files changed+183−102
pkgs/development/tools/analysis/radare2-cutter/default.nix → pkgs/development/tools/analysis/radare2/cutter.nix+4−13 pkgs/development/tools/analysis/radare2/default.nix+83−54 pkgs/development/tools/analysis/radare2/update.py+91−32 pkgs/top-level/all-packages.nix+5−3
pkgs/development/tools/analysis/radare2-cutter/default.nix → pkgs/development/tools/analysis/radare2/cutter.nixrenamed+4−13
@@ -4,20 +4,11 @@
44# Qt
55, qtbase, qtsvg, qtwebengine
66# buildInputs
7−, radare2
7+, r2-for-cutter
88, python3 }:
99
1010let
11− r2 = radare2.overrideDerivation (o: {
12− name = "radare2-for-cutter-${version}";
13− src = fetchFromGitHub {
14− owner = "radare";
15− repo = "radare2";
16− rev = "a98557bfbfa96e9f677a8c779ee78085ee5a23bb";
17− sha256 = "04jl1lq3dqljb6vagzlym4wc867ayhx1v52f75rkfz0iybsh249r";
18− };
19− });
20− version = "1.6";
11+ version = "1.7";
2112in
2213stdenv.mkDerivation rec {
2314 name = "radare2-cutter-${version}";
@@ -26,7 +17,7 @@ stdenv.mkDerivation rec {
2617 owner = "radareorg";
2718 repo = "cutter";
2819 rev = "v${version}";
29− sha256 = "1ps52yf94yfnws3nn1iiwch2jy33dyvi7j47xkmh0m5fpdqi5xk7";
20+ sha256 = "0z9wzxd5hw0ivakrg3xiv4zx1rjj032hlmizq0pxj22xjrj1gg9n";
3021 };
3122
3223 postUnpack = "export sourceRoot=$sourceRoot/src";
@@ -41,7 +32,7 @@ stdenv.mkDerivation rec {
4132 '';
4233
4334 nativeBuildInputs = [ qmake pkgconfig ];
44− buildInputs = [ qtbase qtsvg qtwebengine r2 python3 ];
35+ buildInputs = [ qtbase qtsvg qtwebengine r2-for-cutter python3 ];
4536
4637 qmakeFlags = [
4738 "CONFIG+=link_pkgconfig"
pkgs/development/tools/analysis/radare2/default.nix+83−54
@@ -1,4 +1,5 @@
11{stdenv, fetchFromGitHub
2+, callPackage
23, ninja, meson , pkgconfig
34, libusb, readline, libewf, perl, zlib, openssl
45, gtk2 ? null, vte ? null, gtkdialog ? null
@@ -15,66 +16,94 @@ assert pythonBindings -> python != null;
1516
1617let
1718 inherit (stdenv.lib) optional;
18− #<generated>
19− # DO NOT EDIT! Automatically generated by ./update.py
20− version_commit = "18681";
21− gittap = "2.7.0";
22− gittip = "6e08e452a7ec231a73997c44b4ff556c2998c7d9";
23− version = "2.7.0";
24− sha256 = "1a9z8w897256dhh3yhyfnshz3n2nrc4plc2i06cm5sznhl6x9xfx";
25− cs_tip = "ec8a5ce98fa0422a395489ed47da912b15d77441";
26− cs_sha256 = "080a64bqck28a2xfjwz29ddcr8p6hc6gi67mgry3pca289qrkk3q";
27− #</generated>
28−in
29−stdenv.mkDerivation rec {
30− name = "radare2-${version}";
3119
32− src = fetchFromGitHub {
33− owner = "radare";
34− repo = "radare2";
35− rev = version;
36− inherit sha256;
37− };
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+ };
3838
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− ln -s ${capstone} shlr/capstone
50− '';
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+ '';
5153
52− postInstall = ''
53− ln -s $out/bin/radare2 $out/bin/r2
54− install -D -m755 $src/binr/r2pm/r2pm $out/bin/r2pm
55− '';
54+ postInstall = ''
55+ ln -s $out/bin/radare2 $out/bin/r2
56+ install -D -m755 $src/binr/r2pm/r2pm $out/bin/r2pm
57+ '';
5658
57− mesonFlags = [
58− "-Dr2_version_commit=${version_commit}"
59− "-Dr2_gittap=${gittap}"
60− "-Dr2_gittip=${gittip}"
61− ];
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+ ];
6266
63− enableParallelBuilding = true;
67+ enableParallelBuilding = true;
6468
65− nativeBuildInputs = [ pkgconfig ninja meson ];
66− buildInputs = [ readline libusb libewf perl zlib openssl]
67− ++ optional useX11 [gtkdialog vte gtk2]
68− ++ optional rubyBindings [ruby]
69− ++ optional pythonBindings [python]
70− ++ optional luaBindings [lua];
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];
7175
72− meta = {
73− description = "unix-like reverse engineering framework and commandline tools";
74− homepage = http://radare.org/;
75− license = stdenv.lib.licenses.gpl2Plus;
76− maintainers = with stdenv.lib.maintainers; [raskin makefu mic92];
77− platforms = with stdenv.lib.platforms; linux;
78− inherit version;
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+ };
7984 };
85+in {
86+ #<generated>
87+ # DO NOT EDIT! Automatically generated by ./update.py
88+ radare2 = generic {
89+ version_commit = "19251";
90+ gittap = "2.8.0";
91+ gittip = "a76b965410aba07b4ef8b96d90b25b271c2003dd";
92+ rev = "2.8.0";
93+ version = "2.8.0";
94+ sha256 = "1d9rkzc3vychy2h1bnywwx4why83rr18r0lvvl1cqx87ad5awcjk";
95+ cs_tip = "782ea67e17a391ca0d3faafdc365b335a1a8930a";
96+ cs_sha256 = "1maww4ir78a193pm3f8lr2kdkizi7rywn68ffa65ipyr7j4pl6i4";
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+ };
108+ #</generated>
80109}
pkgs/development/tools/analysis/radare2/update.py+91−32
@@ -2,14 +2,16 @@
22#!nix-shell -p nix -p python3 -p git -i python
33# USAGE - just run the script: ./update.py
44# When editing this file, make also sure it passes the mypy typecheck
5−# and is formatted with yapf.
6−import urllib.request
7−import json
8−import tempfile
9−import subprocess
5+# and is formatted with black.
106import fileinput
7+import json
118import re
9+import subprocess
10+import tempfile
11+import urllib.request
12+from datetime import datetime
1213from pathlib import Path
14+from typing import Dict
1315
1416
1517def sh(*args: str) -> str:
@@ -18,50 +20,107 @@ def sh(*args: str) -> str:
1820
1921
2022def 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+ )
2328
2429
25−def main() -> None:
30+def get_radare2_rev() -> str:
2631 url = "https://api.github.com/repos/radare/radare2/releases/latest"
2732 with urllib.request.urlopen(url) as response:
2833 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+
3146
32− def git(*args: str) -> str:
33− return sh("git", "-C", dirname, *args)
47+def git(dirname: str, *args: str) -> str:
48+ return sh("git", "-C", dirname, *args)
3449
35− git("clone", "--branch", version, "https://github.com/radare/radare2",
36− ".")
37− sha256 = prefetch_github("radare", "radare2", version)
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+ }}"""
86+
87+
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+ )
38101 nix_file = str(Path(__file__).parent.joinpath("default.nix"))
39102
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")
47109
48− cs_sha256 = prefetch_github("aquynh", "capstone", cs_tip)
110+ r2_cutter_info = get_repo_info(dirname, r2_cutter_rev)
49111
50112 in_block = False
51113 with fileinput.FileInput(nix_file, inplace=True) as f:
52114 for l in f:
53115 if "#<generated>" in l:
54116 in_block = True
55− print(f""" #<generated>
117+ print(
118+ f""" #<generated>
56119 # 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+ )
65124 elif "#</generated>" in l:
66125 in_block = False
67126 elif not in_block:
pkgs/top-level/all-packages.nix+5−3
@@ -8532,15 +8532,17 @@ with pkgs;
85328532 rubyBindings = config.radare.rubyBindings or false;
85338533 luaBindings = config.radare.luaBindings or false;
85348534 };
8535− radare2 = callPackage ../development/tools/analysis/radare2 {
8535+
8536+ inherit (callPackages ../development/tools/analysis/radare2 {
85368537 inherit (gnome2) vte;
85378538 lua = lua5;
85388539 useX11 = config.radare.useX11 or false;
85398540 pythonBindings = config.radare.pythonBindings or false;
85408541 rubyBindings = config.radare.rubyBindings or false;
85418542 luaBindings = config.radare.luaBindings or false;
8542− };
8543− radare2-cutter = libsForQt5.callPackage ../development/tools/analysis/radare2-cutter { };
8543+ }) radare2 r2-for-cutter;
8544+
8545+ radare2-cutter = libsForQt5.callPackage ../development/tools/analysis/radare2/cutter.nix { };
85448546
85458547 ragel = ragelStable;
85468548