Skip to content

Commit f05869a

Browse files
committed
m
1 parent 67ee069 commit f05869a

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

relenv/buildenv.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
"""
44
Helper for building libraries to install into a relenv environment.
55
"""
6+
import json
67
import logging
78
import sys
89

9-
from .common import MACOS_DEVELOPMENT_TARGET, RelenvException, get_triplet, work_dirs
10+
from .common import (
11+
MACOS_DEVELOPMENT_TARGET,
12+
RelenvException,
13+
get_toolchain,
14+
get_triplet,
15+
)
1016

1117
log = logging.getLogger()
1218

@@ -22,6 +28,12 @@ def setup_parser(subparsers):
2228
"buildenv", description="Relenv build environment"
2329
)
2430
subparser.set_defaults(func=main)
31+
subparser.add_argument(
32+
"--json",
33+
default=False,
34+
action="store_true",
35+
help=("Output json to stdout instead of export statments"),
36+
)
2537

2638

2739
def is_relenv():
@@ -43,9 +55,8 @@ def buildenv(relenv_path=None):
4355
if sys.platform != "linux":
4456
raise RelenvException("buildenv is only supported on Linux")
4557

46-
dirs = work_dirs()
4758
triplet = get_triplet()
48-
toolchain = dirs.toolchain / get_triplet()
59+
toolchain = get_toolchain()
4960
env = {
5061
"RELENV_BUILDENV": "1",
5162
"TOOLCHAIN_PATH": f"{toolchain}",
@@ -90,12 +101,13 @@ def main(args):
90101
if sys.platform != "linux":
91102
log.error("buildenv is only supported on Linux.")
92103

93-
# dirs = work_dirs()
94-
# triplet = get_triplet()
95-
# toolchain = dirs.toolchain / get_triplet()
104+
if args.json:
105+
print(json.dumps(buildenv()))
106+
sys.exit(0)
96107

97108
script = ""
98109
for k, v in buildenv().items():
99110
script += f'export {k}="{v}"\n'
100111

101112
print(script)
113+
sys.exit(0)

relenv/runtime.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,10 +839,12 @@ def install_cargo_config():
839839
toolchain = pathlib.Path(env["TOOLCHAIN_PATH"])
840840
else:
841841
debug("Unable to set CARGO_HOME ppbt package not installed")
842+
return
842843

843844
if not toolchain.exists():
844845
debug("Unable to set CARGO_HOME no toolchain exists")
845846
return
847+
846848
cargo_home = dirs.data / "cargo"
847849
if not cargo_home.exists():
848850
cargo_home.mkdir()

tests/test_verify_build.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
Verify relenv builds.
66
"""
7+
import json
78
import os
89
import pathlib
910
import platform
@@ -16,7 +17,7 @@
1617
import packaging
1718
import pytest
1819

19-
from relenv.common import DATA_DIR, build_arch, get_triplet
20+
from relenv.common import build_arch, get_triplet
2021

2122
from .conftest import get_build_version
2223

@@ -554,6 +555,17 @@ def test_pip_install_m2crypto_system_ssl(pipexec, pyexec):
554555

555556
@pytest.mark.skip_unless_on_linux
556557
def test_pip_install_m2crypto_relenv_ssl(pipexec, pyexec, build):
558+
p = subprocess.run(
559+
[
560+
pyexec,
561+
"-m",
562+
"relenv",
563+
"buildenv",
564+
"--json",
565+
],
566+
capture_output=True,
567+
)
568+
buildenv = json.loads(p.stdout)
557569
env = os.environ.copy()
558570
env["RELENV_BUILDENV"] = "yes"
559571
env["RELENV_DEBUG"] = "yes"
@@ -569,13 +581,7 @@ def test_pip_install_m2crypto_relenv_ssl(pipexec, pyexec, build):
569581
stderr=subprocess.PIPE,
570582
)
571583
assert p.returncode == 0, "Failed to pip install m2crypto"
572-
gcc = str(
573-
pathlib.Path(DATA_DIR)
574-
/ "toolchain"
575-
/ f"{get_triplet()}"
576-
/ "bin"
577-
/ f"{get_triplet()}-gcc"
578-
)
584+
gcc = str(pathlib.Path(buildenv["TOOLCHAIN_PATH"]) / "bin" / f"{get_triplet()}-gcc")
579585
include = str(pathlib.Path(build) / "include")
580586
found_include = False
581587
for _ in p.stderr.splitlines():
@@ -584,7 +590,7 @@ def test_pip_install_m2crypto_relenv_ssl(pipexec, pyexec, build):
584590
for arg in line.split():
585591
if arg == f"-I{include}":
586592
found_include = True
587-
assert found_include
593+
assert found_include, f"{include}\n{p.stderr.decode()}"
588594
p = subprocess.run(
589595
[str(pyexec), "-c", "import M2Crypto"],
590596
env=env,

0 commit comments

Comments
 (0)