mirror of
https://github.com/radareorg/r2env.git
synced 2026-11-07 20:39:12 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
daeba4ebcf | ||
|
|
5578bee417 | ||
|
|
ab6cce7008 | ||
|
|
d501129500 | ||
|
|
51c1b2ca2c | ||
|
|
743812b653 | ||
|
|
ac3b695012 | ||
|
|
00a3db509c | ||
|
|
ccd7231065 | ||
|
|
3b8716ea1d | ||
|
|
d6b40cf4b8 | ||
|
|
a4d678511e | ||
|
|
658ede86d9 | ||
|
|
d8fc2f8b71 | ||
|
|
57398126f3 | ||
|
|
f7e211b014 | ||
|
|
3873eb48a7 | ||
|
|
c5ba226b21 | ||
|
|
88e68daef5 | ||
|
|
2468813a3c | ||
|
|
223af1e85d | ||
|
|
0ef5ff2d72 | ||
|
|
2f937f67f1 | ||
|
|
4380456e1d | ||
|
|
59c9445d10 | ||
|
|
713c18feb4 | ||
|
|
670de20b01 | ||
|
|
019e941dfa | ||
|
|
26925a29d6 | ||
|
|
1a1f3fcde5 | ||
|
|
0c838e7d08 | ||
|
|
b3852a92d3 | ||
|
|
6f81459f70 | ||
|
|
3f16036689 | ||
|
|
00782ae62f | ||
|
|
93bd2b0e1e | ||
|
|
100dc1a9d0 | ||
|
|
e5677a03ae | ||
|
|
35d769e73b | ||
|
|
587ce7ef96 | ||
|
|
edfe363401 | ||
|
|
9d521d7f0e | ||
|
|
2c0f8d48c9 |
No files matched your search
@@ -0,0 +1,23 @@
|
||||
on:
|
||||
pull_request: {}
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
paths:
|
||||
- .github/workflows/semgrep.yml
|
||||
schedule:
|
||||
# random HH:MM to avoid a load spike on GitHub Actions at 00:00
|
||||
- cron: 34 10 * * *
|
||||
name: Semgrep
|
||||
jobs:
|
||||
semgrep:
|
||||
name: Scan
|
||||
runs-on: ubuntu-20.04
|
||||
env:
|
||||
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
|
||||
container:
|
||||
image: returntocorp/semgrep
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: semgrep ci
|
||||
@@ -1,17 +1,20 @@
|
||||
PYTHON?=python3
|
||||
PIP?=pip3
|
||||
|
||||
all:
|
||||
pip install .
|
||||
$(PIP) install .
|
||||
|
||||
pub:
|
||||
rm -rf dist
|
||||
$(PYTHON) setup.py sdist
|
||||
twine upload --repository=pypi --verbose dist/*
|
||||
twine check dist/*
|
||||
twine upload -u __token__ --repository-url https://upload.pypi.org/legacy/ --verbose dist/*
|
||||
#twine upload --repository=pypi --verbose dist/*
|
||||
|
||||
install:
|
||||
pip install .
|
||||
$(PIP) install .
|
||||
|
||||
uninstall:
|
||||
pip uninstall r2env
|
||||
$(PIP) uninstall r2env
|
||||
|
||||
.PHONY: all clean pub install uninstall
|
||||
@@ -64,6 +64,7 @@ versions - list installed packages
|
||||
list - list all packages available to r2env
|
||||
shell - enter a new shell with PATH env var set
|
||||
purge - remove ~/.r2env
|
||||
update - update list of available profiles
|
||||
|
||||
Environment
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
from r2env.repl import main
|
||||
|
||||
main()
|
||||
@@ -1,147 +0,0 @@
|
||||
{
|
||||
"r2frida": {
|
||||
"source": "https://github.com/nowsecure/r2frida",
|
||||
"versions": [
|
||||
{
|
||||
"id": "git",
|
||||
"packages": {}
|
||||
}
|
||||
]
|
||||
},
|
||||
"r2dec": {
|
||||
"source": "https://github.com/wargio/r2dec-js",
|
||||
"versions": [
|
||||
{
|
||||
"id": "git",
|
||||
"packages": {}
|
||||
}
|
||||
]
|
||||
},
|
||||
"r2ghidra": {
|
||||
"source": "https://github.com/radareorg/r2ghidra",
|
||||
"versions": [
|
||||
{
|
||||
"id": "git",
|
||||
"packages": {}
|
||||
}
|
||||
]
|
||||
},
|
||||
"r0": {
|
||||
"source": "https://github.com/radareorg/r0",
|
||||
"versions": [
|
||||
{
|
||||
"id": "git",
|
||||
"packages": {}
|
||||
}
|
||||
]
|
||||
},
|
||||
"radare2": {
|
||||
"source": "https://github.com/radareorg/radare2",
|
||||
"versions": [
|
||||
{
|
||||
"id": "5.3.0",
|
||||
"packages": {
|
||||
"w64": "radare2-5.3.0-w64.zip",
|
||||
"deb_x64": "radare2_5.3.0_amd64.deb"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "5.3.1",
|
||||
"packages": {
|
||||
"w64": "radare2-5.3.1-w64.zip",
|
||||
"mac_x64": "radare2-5.3.1.pkg",
|
||||
"deb_x64": "radare2_5.3.1_amd64.deb"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "5.4.0",
|
||||
"packages": {
|
||||
"w64": "radare2-5.4.0-w64.zip",
|
||||
"mac_x64": "radare2-5.4.0.pkg",
|
||||
"deb_x64": "radare2_5.4.0_amd64.deb"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "5.4.2",
|
||||
"packages": {
|
||||
"w32": "radare2-5.4.2-w32.zip",
|
||||
"w64": "radare2-5.4.2-w64.zip",
|
||||
"mac_x64": "radare2-5.4.2-amd64.pkg",
|
||||
"mac_arm64": "radare2-5.4.2-m1.pkg",
|
||||
"deb_i386": "radare2_5.4.2_i386.deb",
|
||||
"deb_x64": "radare2_5.4.2_amd64.deb"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "5.5.0",
|
||||
"packages": {
|
||||
"w32": "radare2-5.5.0-w32.zip",
|
||||
"w64": "radare2-5.5.0-w64.zip",
|
||||
"mac_x64": "radare2-5.5.0-amd64.pkg",
|
||||
"mac_arm64": "radare2-5.5.0-m1.pkg",
|
||||
"deb_i386": "radare2_5.5.0_i386.deb",
|
||||
"deb_x64": "radare2_5.5.0_amd64.deb"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "5.5.2",
|
||||
"packages": {
|
||||
"w32": "radare2-5.5.2-w32.zip",
|
||||
"w64": "radare2-5.5.2-w64.zip",
|
||||
"mac_x64": "radare2-5.5.2-amd64.pkg",
|
||||
"mac_arm64": "radare2-5.5.2-m1.pkg",
|
||||
"deb_i386": "radare2_5.5.2_i386.deb",
|
||||
"deb_x64": "radare2_5.5.2_amd64.deb"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "5.5.4",
|
||||
"packages": {
|
||||
"w32": "radare2-5.5.4-w32.zip",
|
||||
"w64": "radare2-5.5.4-w64.zip",
|
||||
"mac_x64": "radare2-5.5.4-amd64.pkg",
|
||||
"mac_arm64": "radare2-5.5.4-m1.pkg",
|
||||
"deb_i386": "radare2_5.5.4_i386.deb",
|
||||
"deb_x64": "radare2_5.5.4_amd64.deb"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "5.6.0",
|
||||
"packages": {
|
||||
"w32": "radare2-5.6.0-w32.zip",
|
||||
"w64": "radare2-5.6.0-w64.zip",
|
||||
"mac_x64": "radare2-5.6.0-amd64.pkg",
|
||||
"mac_arm64": "radare2-5.6.0-m1.pkg",
|
||||
"deb_i386": "radare2_5.6.0_i386.deb",
|
||||
"deb_x64": "radare2_5.6.0_amd64.deb"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "5.6.2",
|
||||
"packages": {
|
||||
"w32": "radare2-5.6.2-w32.zip",
|
||||
"w64": "radare2-5.6.2-w64.zip",
|
||||
"mac_x64": "radare2-5.6.2-amd64.pkg",
|
||||
"mac_arm64": "radare2-5.6.2-m1.pkg",
|
||||
"deb_i386": "radare2_5.6.2_i386.deb",
|
||||
"deb_x64": "radare2_5.6.2_amd64.deb"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "5.6.4",
|
||||
"packages": {
|
||||
"w32": "radare2-5.6.4-w32.zip",
|
||||
"w64": "radare2-5.6.4-w64.zip",
|
||||
"mac_x64": "radare2-5.6.4-amd64.pkg",
|
||||
"mac_arm64": "radare2-5.6.4-m1.pkg",
|
||||
"deb_i386": "radare2_5.6.4_i386.deb",
|
||||
"deb_x64": "radare2_5.6.4_amd64.deb"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "git",
|
||||
"packages": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
+13
-7
@@ -67,6 +67,8 @@ class R2Env:
|
||||
self.check_if_r2env_initialized()
|
||||
use_meson = kwargs["use_meson"] if "use_meson" in kwargs else False
|
||||
use_dist = kwargs["use_dist"] if "use_dist" in kwargs else False
|
||||
if "@" not in package:
|
||||
package = f"{package}@git"
|
||||
if not self._check_package_format(package):
|
||||
raise R2EnvException("[x] Invalid package format.")
|
||||
try:
|
||||
@@ -106,17 +108,17 @@ class R2Env:
|
||||
@staticmethod
|
||||
def version():
|
||||
thispath = os.path.dirname(os.path.realpath(__file__))
|
||||
with open(thispath + "/version.txt", "r", encoding="utf-8") as version:
|
||||
return version.read()
|
||||
with open(f"{thispath}/version.txt", "r", encoding="utf-8") as version:
|
||||
print_console(version.read())
|
||||
|
||||
def shell(self, cmd="", **_kwargs):
|
||||
def shell(self, cmd=None, **_kwargs):
|
||||
bin_path = os.path.join(self._r2env_path, "bin")
|
||||
if host_platform() == "windows":
|
||||
os.system(f"set PATH={bin_path};%PATH% && cmd")
|
||||
return True
|
||||
pkgconfig_path = os.path.join(self._r2env_path, "lib", "pkgconfig")
|
||||
bin_path = os.path.join(self._r2env_path, "bin")
|
||||
export_ps1 = "export PS1=\"r2env\\$ \";"
|
||||
export_ps1 = f"export PS1=\"r2env ({self._get_current_version()})\\$ \";"
|
||||
export_pkg_config = f"export PKG_CONFIG_PATH=\"{pkgconfig_path}\";"
|
||||
export_path = f"export PATH=\"{bin_path}:$PATH\";"
|
||||
cmd_shell = "$SHELL -f"
|
||||
@@ -126,10 +128,11 @@ class R2Env:
|
||||
full_cmd = f"export LD_LIBRARY_PATH=\"{library_path}\";" + full_cmd
|
||||
if host_platform() == "osx":
|
||||
library_path = os.path.join(self._r2env_path, "lib")
|
||||
# XXX this doesnt work on sip-enabled macs, that's why we use install_name_tool after install
|
||||
full_cmd = f"export DYLD_LIBRARY_PATH=\"{library_path}\";" + full_cmd
|
||||
if cmd.strip() == "":
|
||||
return os.system(full_cmd)
|
||||
return os.system(full_cmd + " -c '" + cmd + "'")
|
||||
if cmd is None:
|
||||
return os.system(full_cmd) == 0
|
||||
return os.system(f"{full_cmd} -c '{cmd}'") == 0
|
||||
|
||||
@staticmethod
|
||||
def _load_config():
|
||||
@@ -167,6 +170,9 @@ class R2Env:
|
||||
with open(version_file, 'w', encoding="utf-8") as file_desc:
|
||||
file_desc.write(package)
|
||||
|
||||
def update_version_profiles(self):
|
||||
PackageManager.update_radare2_profiles(self._r2env_path)
|
||||
|
||||
def check_if_r2env_initialized(self):
|
||||
if not os.path.isdir(self._r2env_path):
|
||||
raise R2EnvException("Not r2env initialized. Execute 'r2env init' first.")
|
||||
+128
-21
@@ -5,8 +5,10 @@ import shutil
|
||||
import time
|
||||
from urllib.error import URLError
|
||||
import zipfile
|
||||
import json
|
||||
|
||||
import wget
|
||||
import requests
|
||||
|
||||
from r2env.exceptions import PackageManagerException
|
||||
from r2env.tools import load_json_file, git_fetch, git_clean, print_console, ERROR, exit_if_not_exists, host_distname
|
||||
@@ -19,7 +21,7 @@ class PackageManager:
|
||||
DOWNLOAD_URL = "https://github.com/radareorg/radare2/releases/download/"
|
||||
|
||||
def __init__(self, r2env_path):
|
||||
self._packages = self._load_profiles()
|
||||
self._packages = self._load_profiles(r2env_path)
|
||||
self._r2env_path = r2env_path
|
||||
|
||||
def get_package_path(self, package_name):
|
||||
@@ -38,13 +40,110 @@ class PackageManager:
|
||||
return res
|
||||
|
||||
@staticmethod
|
||||
def _load_profiles():
|
||||
filename = os.path.join(os.path.dirname(__file__), 'config', 'profiles.json')
|
||||
def _load_profiles(r2env_path):
|
||||
filename = os.path.join(r2env_path, 'profiles.json')
|
||||
# if profiles.json doesn't exist, generate it now
|
||||
if not os.path.exists(filename):
|
||||
print_console(f"NOTE: {filename} does not exist. Generating it now.")
|
||||
PackageManager.update_radare2_profiles(r2env_path)
|
||||
profiles = load_json_file(filename)
|
||||
if not profiles:
|
||||
raise PackageManagerException("No profiles configured.")
|
||||
return profiles
|
||||
|
||||
@staticmethod
|
||||
def update_radare2_profiles(r2env_path):
|
||||
gh_release_info_req = requests.get(
|
||||
"https://api.github.com/repos/radareorg/radare2/releases",
|
||||
{"headers": ["X-GitHub-Api-Version: 2022-11-28", "Accept: application/vnd.github+json"]},
|
||||
timeout=10 # 10-second timeout for API request
|
||||
)
|
||||
gh_release_info_req.raise_for_status() # raise an error if the request got a bad return code
|
||||
gh_release_info = gh_release_info_req.json()
|
||||
radare2_versions = [{'id': 'git', 'packages': {}}] # include the git version by default
|
||||
for release in gh_release_info:
|
||||
version = {'id': release['tag_name'], 'packages': {}}
|
||||
# generate a list of downloadable assets for this release that r2env can use
|
||||
for asset in release['assets']:
|
||||
# note: you're about to see 100 lines of hackery to deal with inconsistent naming schemes
|
||||
# the goal is to include as many valid assets as is reasonable without including any that are not valid
|
||||
# separate file extension
|
||||
asset_name, asset_ext = os.path.splitext(asset['name'])
|
||||
|
||||
# normalize 'seperators' before splitting into components
|
||||
asset_ref = asset_name.replace('_', '-').split('-')
|
||||
|
||||
# filter out things like r2ios_sdk and r2blob
|
||||
if asset_ref[0] != 'radare2':
|
||||
continue
|
||||
|
||||
# Some assets don't have the version number in the name, which breaks the following processing.
|
||||
# None of them are of interest anyway, so just skip them.
|
||||
if release['tag_name'] not in asset_ref:
|
||||
continue
|
||||
|
||||
# remove the beginning 'radare2'
|
||||
asset_ref.remove('radare2')
|
||||
|
||||
# we don't need to care about the release id when checking, so remove it
|
||||
asset_ref.remove(release['tag_name'])
|
||||
|
||||
# once "radare2" and the version number have been removed from asset_ref,
|
||||
# if all that's left matches a filter, save it.
|
||||
_VERSION_FILTERS = {
|
||||
'.zip': { # used for Windows builds among other things
|
||||
'w32': [['w32']],
|
||||
'w64': [['w64']]
|
||||
},
|
||||
'.deb': {
|
||||
'deb_i386': [['i386']],
|
||||
'deb_x64': [['amd64']]
|
||||
},
|
||||
'.pkg': { # macOS bundle
|
||||
'mac_arm64': [['m1']],
|
||||
'mac_x64': [[], ['amd64'], ['x64'], ['macos']]
|
||||
}
|
||||
}
|
||||
|
||||
if asset_ext in _VERSION_FILTERS:
|
||||
for platform, refs in _VERSION_FILTERS[asset_ext].items():
|
||||
if asset_ref in refs:
|
||||
version['packages'][platform] = asset['name']
|
||||
break
|
||||
|
||||
radare2_versions.append(version)
|
||||
|
||||
profiles = {
|
||||
'r2frida': {
|
||||
'source': 'https://github.com/nowsecure/r2frida',
|
||||
'versions': [{'id': 'git', 'packages': {}}]
|
||||
},
|
||||
'r2dec': {
|
||||
'source': 'https://github.com/wargio/r2dec-js',
|
||||
'versions': [{'id': 'git', 'packages': {}}]
|
||||
},
|
||||
'r2yara': {
|
||||
'source': 'https://github.com/radareorg/r2yara',
|
||||
'versions': [{'id': 'git', 'packages': {}}]
|
||||
},
|
||||
'r2ghidra': {
|
||||
'source': 'https://github.com/radareorg/r2ghidra',
|
||||
'versions': [{'id': 'git', 'packages': {}}]
|
||||
},
|
||||
'r0': {
|
||||
'source': 'https://github.com/radareorg/r0',
|
||||
'versions': [{'id': 'git', 'packages': {}}]
|
||||
},
|
||||
'radare2': {
|
||||
'source': 'https://github.com/radareorg/radare2',
|
||||
'versions': radare2_versions[::-1]
|
||||
}
|
||||
}
|
||||
if not os.path.isdir(r2env_path):
|
||||
os.makedirs(r2env_path)
|
||||
with open(os.path.join(r2env_path, 'profiles.json'), 'w', encoding='utf-8') as f:
|
||||
json.dump(profiles, f)
|
||||
|
||||
def install_package(self, profile, version, use_meson, use_dist):
|
||||
log_path = os.path.join(self._r2env_path, self.LOG_DIR)
|
||||
timestamp = round(time.monotonic() * 1000)
|
||||
@@ -57,11 +156,17 @@ class PackageManager:
|
||||
os.makedirs(source_path)
|
||||
if not os.path.isdir(dst_dir):
|
||||
os.makedirs(dst_dir)
|
||||
self._exit_if_package_not_available(profile, version)
|
||||
if self._if_package_not_available(profile, version):
|
||||
if os.path.isdir(dst_dir):
|
||||
shutil.rmtree(dst_dir)
|
||||
raise PackageManagerException(
|
||||
f"{profile}@{version} package not available. Use 'list' command to see available packages.")
|
||||
if use_dist:
|
||||
if self._install_from_dist(profile, version):
|
||||
print_console(f"[*] Binary package {profile}@{version} installed successfully")
|
||||
else:
|
||||
if os.path.isdir(dst_dir):
|
||||
shutil.rmtree(dst_dir)
|
||||
raise PackageManagerException(f"[x] Failed to install {profile}@{version}.")
|
||||
else:
|
||||
if self._build_from_source(profile, version, source_path, dst_dir, logfile, use_meson=use_meson):
|
||||
@@ -93,11 +198,12 @@ class PackageManager:
|
||||
raise PackageManagerException(f"[x] Unable to find installed package {package_name}")
|
||||
|
||||
def _get_pkgname(self, profile, version, cos):
|
||||
for pkgv in self._packages[profile]["versions"]:
|
||||
if pkgv["id"] == version:
|
||||
for pkgd in pkgv["packages"].keys():
|
||||
if pkgd == cos:
|
||||
return pkgv["packages"][pkgd]
|
||||
if profile in self._packages:
|
||||
for pkgv in self._packages[profile]["versions"]:
|
||||
if pkgv["id"] == version:
|
||||
for pkgd in pkgv["packages"].keys():
|
||||
if pkgd == cos:
|
||||
return pkgv["packages"][pkgd]
|
||||
return None
|
||||
|
||||
def _get_disturl(self, profile, version, cos):
|
||||
@@ -190,6 +296,8 @@ class PackageManager:
|
||||
@staticmethod
|
||||
def _build_using_acr(source_path, dst_path, logfile, r2env_path):
|
||||
"""Only works in Unix systems"""
|
||||
if host_distname() is not None and host_distname() in "w64":
|
||||
raise PackageManagerException("acr is not supported on Windows platform. Use meson instead.")
|
||||
exit_if_not_exists(['make'])
|
||||
print_console("[-] Building package using acr...")
|
||||
extra_flags = ""
|
||||
@@ -210,20 +318,19 @@ class PackageManager:
|
||||
exit_if_not_exists(['meson', 'ninja'])
|
||||
print_console("[-] Building package using meson ...")
|
||||
config_path = r2env_path + "/lib/pkgconfig"
|
||||
# TODO: ensure source_path logfile or dst_path have no spaces
|
||||
cmd = f"(export PKG_CONFIG_PATH=\"{config_path}\";" \
|
||||
f"cd {source_path} && rm -rf build && " \
|
||||
f"meson . build --buildtype=release --prefix={dst_path} -Dlocal=true 2>&1 && " \
|
||||
f"cd \"{source_path}\" && rm -rf build && " \
|
||||
f"meson build --buildtype=release --prefix={dst_path} -Dlocal=true 2>&1 && " \
|
||||
f"ninja -C build && " \
|
||||
f"ninja -C build install) > {logfile}"
|
||||
f"ninja -C build install) > {logfile} && " \
|
||||
f"for a in {dst_path}/bin/* ; do install_name_tool -add_rpath {dst_path}/lib $a ; done"
|
||||
print_console(f"Executing {cmd}")
|
||||
return os.system(cmd) == 0
|
||||
|
||||
def _exit_if_package_not_available(self, profile, version):
|
||||
pkg_found = False
|
||||
for available_version in self._packages[profile]["versions"]:
|
||||
if available_version['id'] == version:
|
||||
pkg_found = True
|
||||
break
|
||||
if not pkg_found:
|
||||
raise PackageManagerException(
|
||||
f"{profile}@{version} package not available. Use 'list' command to see available packages.")
|
||||
def _if_package_not_available(self, profile, version):
|
||||
if profile in self._packages:
|
||||
for available_version in self._packages[profile]["versions"]:
|
||||
if available_version['id'] == version:
|
||||
return False
|
||||
return True
|
||||
+9
-2
@@ -31,6 +31,7 @@ class REPL:
|
||||
list - list all packages available to r2env.
|
||||
shell - enter a new shell with PATH env var set.
|
||||
purge - remove ~/.r2env
|
||||
update - update list of available profiles
|
||||
|
||||
Environment
|
||||
|
||||
@@ -55,6 +56,7 @@ class REPL:
|
||||
"install": self._core.install,
|
||||
"installed": self._core.list_installed_packages,
|
||||
"uninstall": self._core.uninstall,
|
||||
"update": self._core.update_version_profiles,
|
||||
"rm": self._core.uninstall,
|
||||
"use": self._core.use,
|
||||
"purge": self._core.purge,
|
||||
@@ -65,9 +67,9 @@ class REPL:
|
||||
def show_help(self):
|
||||
print_console(self.HELP_MESSAGE)
|
||||
|
||||
def run_action(self, action_args):
|
||||
def run_action(self, action_args): # noqa: C901
|
||||
args = []
|
||||
if not action_args or len(action_args.args) == 0:
|
||||
if not action_args:
|
||||
self.show_help()
|
||||
raise ActionException("No action selected")
|
||||
if action_args.version:
|
||||
@@ -76,6 +78,9 @@ class REPL:
|
||||
if action_args.list:
|
||||
list_method = self.actions["list"]
|
||||
list_method()
|
||||
if len(action_args.args) == 0:
|
||||
self.show_help()
|
||||
raise ActionException("No action selected")
|
||||
if len(action_args.args) > 1:
|
||||
args = action_args.args[1:]
|
||||
action = action_args.args[0]
|
||||
@@ -89,6 +94,8 @@ class REPL:
|
||||
raise ActionException(f"Action {action} requires a package as an argument.")
|
||||
if action in self.actions_with_arguments:
|
||||
self.actions[action](args[0], use_meson=action_args.meson, use_dist=action_args.package)
|
||||
elif action in "shell" and len(args) > 0:
|
||||
self.actions[action](args[0])
|
||||
else:
|
||||
self.actions[action]()
|
||||
|
||||
|
||||
@@ -134,8 +134,8 @@ class TestCore(unittest.TestCase):
|
||||
@patch("r2env.core.R2Env.check_if_r2env_initialized")
|
||||
def test_install_successfully_failed(self, mock_initialized):
|
||||
mock_initialized.return_value = True
|
||||
package = "radare2"
|
||||
version = "5.3.0"
|
||||
package = "radare2@"
|
||||
version = ""
|
||||
with self.assertRaises(R2EnvException):
|
||||
R2Env().install(f"{package}{version}", use_dist=True)
|
||||
|
||||
@@ -262,7 +262,7 @@ class TestCore(unittest.TestCase):
|
||||
cmd = "r2 -v"
|
||||
R2Env().shell(cmd)
|
||||
mock_system.assert_called_with(f"export LD_LIBRARY_PATH=\"{r2env_path}/lib\";"
|
||||
f"export PS1=\"r2env\\$ \";"
|
||||
f"export PS1=\"r2env ()\\$ \";"
|
||||
f"export PKG_CONFIG_PATH=\"{r2env_path}/lib/pkgconfig\";"
|
||||
f"export PATH=\"{r2env_path}/bin:$PATH\";"
|
||||
f"$SHELL -f -c \'{cmd}\'")
|
||||
@@ -277,7 +277,7 @@ class TestCore(unittest.TestCase):
|
||||
cmd = "r2 -v"
|
||||
R2Env().shell(cmd)
|
||||
mock_system.assert_called_with(f"export DYLD_LIBRARY_PATH=\"{r2env_path}/lib\";"
|
||||
f"export PS1=\"r2env\\$ \";"
|
||||
f"export PS1=\"r2env ()\\$ \";"
|
||||
f"export PKG_CONFIG_PATH=\"{r2env_path}/lib/pkgconfig\";"
|
||||
f"export PATH=\"{r2env_path}/bin:$PATH\";"
|
||||
f"$SHELL -f -c \'{cmd}\'")
|
||||
@@ -291,7 +291,7 @@ class TestCore(unittest.TestCase):
|
||||
mock_load_json_file.return_value = {"r2env_path": r2env_path}
|
||||
cmd = "r2 -v"
|
||||
R2Env().shell(cmd)
|
||||
mock_system.assert_called_with(f"export PS1=\"r2env\\$ \";"
|
||||
mock_system.assert_called_with(f"export PS1=\"r2env ()\\$ \";"
|
||||
f"export PKG_CONFIG_PATH=\"{r2env_path}/lib/pkgconfig\";"
|
||||
f"export PATH=\"{r2env_path}/bin:$PATH\";"
|
||||
f"$SHELL -f -c \'{cmd}\'")
|
||||
@@ -395,3 +395,9 @@ class TestPackageManager(unittest.TestCase):
|
||||
mock_distname.return_value = "non_existent"
|
||||
with self.assertRaises(PackageManagerException):
|
||||
self.package_manager._uninstall_from_dist("radare2", "1.0.0")
|
||||
|
||||
@patch("r2env.package_manager.host_distname")
|
||||
def test_acr_not_supported_on_windows(self, mock_distname):
|
||||
mock_distname.return_value = "w64"
|
||||
with self.assertRaises(PackageManagerException):
|
||||
self.package_manager._build_using_acr("source", "dest", "logfile", "r2env")
|
||||
+7
-2
@@ -81,7 +81,12 @@ def git_fetch(url, version, source_path):
|
||||
f"Verify the source path is not dirty. Error: {err}") \
|
||||
from err
|
||||
if version != "git":
|
||||
repo.git.checkout(version)
|
||||
try:
|
||||
repo.git.checkout(version)
|
||||
except git.GitCommandError:
|
||||
# try again after pulling new tags from origin
|
||||
repo.git.fetch("origin", "--tags")
|
||||
repo.git.checkout(version)
|
||||
sms = repo.submodules
|
||||
for sm in sms:
|
||||
if not sm.module_exists():
|
||||
@@ -100,7 +105,7 @@ def exists(tool):
|
||||
def exit_if_not_exists(tools):
|
||||
for tool in tools:
|
||||
if not exists(tool):
|
||||
raise PackageManagerException("[x] {} is required. Please install it first")
|
||||
raise PackageManagerException(f"[x] {tool} is required. Please install it first")
|
||||
|
||||
|
||||
def load_json_file(filepath):
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
0.4.2
|
||||
0.5.9
|
||||
@@ -1,4 +1,5 @@
|
||||
dploy>=0.1.2
|
||||
colorama>=0.4.4
|
||||
wget
|
||||
requests
|
||||
GitPython
|
||||
@@ -35,6 +35,7 @@ install_requires=
|
||||
dploy >= 0.1.2
|
||||
colorama >= 0.4.4
|
||||
GitPython
|
||||
requests
|
||||
setup_requires =
|
||||
setuptools_scm >= 1.15
|
||||
include_package_data = True
|
||||
|
||||
@@ -5,5 +5,8 @@ from setuptools import setup
|
||||
setup(
|
||||
setup_requires=['pbr'],
|
||||
pbr=True,
|
||||
package_files=[('config', ['r2env/config/config.json', 'r2env/config/profiles.json'])]
|
||||
package_files=[
|
||||
('config', ['r2env/config/config.json']),
|
||||
('', ['version.txt'])
|
||||
]
|
||||
)
|
||||
@@ -3,10 +3,11 @@ envlist = py{38,39,310}-{tests},{py38,py39,310}-codecheck-{pylint,flake8,bandit}
|
||||
skipsdist = True
|
||||
|
||||
[testenv]
|
||||
allowlist_externals = bash
|
||||
deps = -r {toxinidir}/requirements/test.txt
|
||||
passenv = *
|
||||
commands =
|
||||
py{38,39,310}-tests: {toxinidir}/run_tests.sh unit
|
||||
py{38,39,310}-tests: bash {toxinidir}/run_tests.sh unit
|
||||
py{38,39,310}-codecheck-pylint: pylint r2env
|
||||
py{38,39,310}-codecheck-flake8: flake8 r2env
|
||||
py{38,39,310}-codecheck-bandit: bandit -c .bandit.yml -r r2env
|
||||
|
||||
Reference in new issue
Block a user