Skip to content
Snippets Groups Projects
Commit 6d926f1b authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Export armarx bin dir to PATH

parent 351afffc
No related branches found
No related tags found
1 merge request!20Resolve "Offer to add ArmarX binaries / scripts to PATH"
import os import os
import dataclasses as dc import dataclasses as dc
from typing import Optional from typing import Dict, Optional
from armarx_setup.core import error
from armarx_setup.core.module.context import Hook from armarx_setup.core.module.context import Hook
from armarx_setup.core.util import cli, commands, environ_context as env_ctx from armarx_setup.core.util import commands, environ_context as env_ctx
from armarx_setup import console from armarx_setup import console
@dc.dataclass class CMake(Hook):
class Install(Hook):
def install(self):
build_dir = self.ctx.build_dir
if not os.path.isdir(build_dir):
raise IOError(f"Build directory '{build_dir}' does not exist.")
with env_ctx.EnvironContext(self.ctx.env, verbose=self.ctx.verbose):
commands.run("cmake --install . ", cwd=build_dir)
class CMake(Hook): class Env(Hook):
def install(self): def __init__(self, ctx=None, **kwargs):
build_dir = self.ctx.build_dir super().__init__(ctx=ctx)
if not os.path.isdir(build_dir):
raise IOError(f"Build directory '{build_dir}' does not exist.")
with env_ctx.EnvironContext(self.ctx.env, verbose=self.ctx.verbose): self.env: Dict[str, str] = kwargs
commands.run("cmake --install . ", cwd=build_dir) for k, v in self.env.items():
if not (isinstance(k, str) and isinstance(v, str)):
raise error.ArmarXSetupError(f"Invalid env entry: '{k}': '{v}'")
def install(self):
for k, v in self.env.items():
self.ctx.module.ws.env_file.add(k, v, write=False)
self.ctx.module.ws.env_file.write()
@dc.dataclass
class Install(Hook):
cmake: Optional[CMake] = None cmake: Optional[CMake] = None
env: Optional[Env] = None
def __post_init__(self): def __post_init__(self):
from armarx_setup.core.util.dataclass import sanitize_type from armarx_setup.core.util.dataclass import sanitize_type
self.cmake = sanitize_type(self.cmake, self.CMake, ctx=self.ctx) self.cmake = sanitize_type(self.cmake, CMake, ctx=self.ctx)
self.env = sanitize_type(self.env, Env, ctx=self.ctx)
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs):
if self.cmake is not None: for step in [self.cmake, self.env]:
self.cmake.install() if step is not None:
else: step.install()
raise TypeError("No install step configured.")
...@@ -29,6 +29,7 @@ class Workspace: ...@@ -29,6 +29,7 @@ class Workspace:
self.config = config or Config() self.config = config or Config()
self.env_file = EnvFile(ws_path=self.path) self.env_file = EnvFile(ws_path=self.path)
self.env_file.add(ARMARX_WORKSPACE_ENV_VAR, path)
self._module_graph: Optional[ModuleGraph] = None self._module_graph: Optional[ModuleGraph] = None
......
...@@ -17,6 +17,13 @@ ...@@ -17,6 +17,13 @@
}, },
"build": "cmake", "build": "cmake",
"install": {
"env": {
"PATH": "$ArmarXCore_DIR/bin/:$PATH"
}
},
"required_modules": { "required_modules": {
"apt/ice": {}, "apt/ice": {},
"apt/jsoncpp": {}, "apt/jsoncpp": {},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment