Skip to content

Commit 955a980

Browse files
committed
vtd: Add vtd-setups to conan package
1 parent 5712175 commit 955a980

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

plugins/vtd/bin/vtd-launch

+23-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import shlex
66
import shutil
77
import subprocess
88
import sys
9+
import tarfile
910
from pathlib import Path
1011
from typing import Dict, List, Optional
1112

@@ -159,7 +160,16 @@ def teardown_runtime(runtime_dir: Path) -> None:
159160
"-s",
160161
"--vtd-setup",
161162
type=click.Path(exists=True, file_okay=True, dir_okay=True),
162-
help="VTD setup to use, default to currently symlinked.",
163+
help="Path to VTD setup to use, default to currently symlinked.",
164+
)
165+
@click.option(
166+
"-S",
167+
"--vtd-setup-cloe",
168+
type=click.Choice(
169+
[Path(s).stem for s in os.listdir(os.getenv("VTD_SETUP_DIR"))],
170+
case_sensitive=False,
171+
),
172+
help="VTD setup to use from (env: $VTD_SETUP_DIR). Default from VTD.",
163173
)
164174
@click.option(
165175
"-p",
@@ -195,6 +205,7 @@ def start(
195205
opt,
196206
skip_setup: bool,
197207
vtd_setup: str,
208+
vtd_setup_cloe: str,
198209
vtd_project: str,
199210
vtd_external_models: List[str],
200211
no_start: bool,
@@ -228,6 +239,17 @@ def start(
228239
os.remove(dst)
229240
shutil.copytree(vtd_setup, dst, symlinks=True)
230241

242+
elif vtd_setup_cloe is not None:
243+
vtd_setup_cloe = Path(os.getenv("VTD_SETUP_DIR")) / f"{vtd_setup_cloe}.tgz"
244+
logging.info(f"Use setup: {vtd_setup_cloe}")
245+
with tarfile.open(vtd_setup_cloe, "r:gz") as tar:
246+
dst = opt.runtime_dir / "Data" / "Setups" / "Current"
247+
if dst.exists():
248+
os.remove(dst)
249+
if not Path(vtd_setup_cloe.stem).exists():
250+
tar.extractall(path=dst.parent)
251+
os.symlink(vtd_setup_cloe.stem, dst)
252+
231253
if vtd_project is not None:
232254
logging.info(f"Select project: {vtd_project}")
233255
if Path(vtd_project).exists():

plugins/vtd/conanfile.py

+29
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from pathlib import Path
2+
import os
3+
from shutil import rmtree
4+
import tarfile
25
from conans import CMake, ConanFile, tools
36

47

@@ -30,6 +33,7 @@ class CloeSimulatorVTD(ConanFile):
3033
"vtd-api/2.2.0@cloe/stable",
3134
]
3235

36+
_setup_folder = "contrib/setups"
3337
_cmake = None
3438

3539
def requirements(self):
@@ -40,6 +44,25 @@ def build_requirements(self):
4044
if self.options.test:
4145
self.build_requires("gtest/[~1.10]")
4246

47+
def _compress_and_remove(self, dir):
48+
if not dir.is_dir():
49+
return
50+
with tarfile.open(f"{dir.name}.tgz", "w:gz") as tar:
51+
tar.add(dir.path, arcname=os.path.basename(dir.path))
52+
rmtree(dir.path)
53+
54+
def _compress_setups(self):
55+
cwd = os.getcwd()
56+
os.chdir(f"{self.export_sources_folder}/{self._setup_folder}")
57+
with os.scandir() as scan:
58+
for dir in scan:
59+
self._compress_and_remove(dir)
60+
os.chdir(cwd)
61+
62+
def export_sources(self):
63+
self.copy("*", dst=self._setup_folder, src=self._setup_folder, symlinks=True)
64+
self._compress_setups()
65+
4366
def _configure_cmake(self):
4467
if self._cmake:
4568
return self._cmake
@@ -64,6 +87,11 @@ def package(self):
6487
cmake = self._configure_cmake()
6588
cmake.install()
6689
self.copy("vtd-launch", dst="bin", src=f"{self.source_folder}/bin")
90+
self.copy(
91+
"*.tgz",
92+
dst=self._setup_folder,
93+
src=f"{self.source_folder}/{self._setup_folder}",
94+
)
6795

6896
def package_id(self):
6997
# Changes in a dependency's package_id need to be accounted for since
@@ -75,3 +103,4 @@ def package_id(self):
75103

76104
def package_info(self):
77105
self.env_info.VTD_LAUNCH = f"{self.package_folder}/bin/vtd-launch"
106+
self.env_info.VTD_SETUP_DIR = f"{self.package_folder}/{self._setup_folder}"

tests/bootstrap_vtd.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"args": [
1515
"-l", "/tmp/vtd.log",
1616
"start",
17-
"--vtd-setup", "${THIS_STACKFILE_DIR}/../plugins/vtd/contrib/setups/Cloe.noGUInoIG",
17+
"--vtd-setup-cloe", "Cloe.noGUInoIG",
1818
"--vtd-project", "${THIS_STACKFILE_DIR}/../plugins/vtd/contrib/projects/cloe_tests"
1919
]
2020
}

0 commit comments

Comments
 (0)