|
| 1 | +import glob |
| 2 | +import os |
| 3 | +from pathlib import Path |
| 4 | +from conans import CMake, ConanFile, RunEnvironment, tools |
| 5 | +from conans.tools import SystemPackageTool |
| 6 | + |
| 7 | + |
| 8 | +class ESMini(ConanFile): |
| 9 | + name = "esmini" |
| 10 | + version = "2.25.1" |
| 11 | + license = "Mozilla Public License Version 2.0" |
| 12 | + url = "https://github.com/esmini/esmini" |
| 13 | + description = "Basic OpenScenario player." |
| 14 | + topics = ("Environment Simulator", "OpenScenario", "OpenDrive") |
| 15 | + settings = "os", "compiler", "build_type", "arch" |
| 16 | + options = { |
| 17 | + "shared": [True, False], |
| 18 | + "fPIC": [True, False], |
| 19 | + "test": [True, False], |
| 20 | + "with_osg": [True, False], |
| 21 | + "with_osi": [True, False], |
| 22 | + "with_sumo": [True, False], |
| 23 | + } |
| 24 | + default_options = { |
| 25 | + "shared": True, |
| 26 | + "fPIC": True, |
| 27 | + "test": True, |
| 28 | + "with_osg": True, |
| 29 | + "with_osi": True, |
| 30 | + "with_sumo": False, |
| 31 | + } |
| 32 | + generators = "cmake" |
| 33 | + build_policy = "missing" |
| 34 | + no_copy_source = False |
| 35 | + requires = [] |
| 36 | + |
| 37 | + _patch_file = "patches/esmini_2_25_1.patch" |
| 38 | + |
| 39 | + _pkg_scenario_dir = "scenarios" |
| 40 | + |
| 41 | + exports_sources = [ |
| 42 | + "CMakeLists.txt", |
| 43 | + _patch_file, |
| 44 | + f"{_pkg_scenario_dir}/*", |
| 45 | + ] |
| 46 | + _git_url = "https://github.com/esmini/esmini.git" |
| 47 | + _git_dir = "esmini" |
| 48 | + _git_ref = "develop" if version == "latest" else f"v{version}" |
| 49 | + _sim_dir = "EnvironmentSimulator" |
| 50 | + _test_deps = [_sim_dir, "resources", "scripts"] |
| 51 | + _test_dir = f"{_git_dir}/{_sim_dir}/Unittest/" |
| 52 | + _lib_dir = f"{_git_dir}/{_sim_dir}/Libraries/" |
| 53 | + _bin_dir = f"{_git_dir}/{_sim_dir}/Applications/" |
| 54 | + _resources_dir = f"{_git_dir}/resources" |
| 55 | + |
| 56 | + _protobuf_dyn = True |
| 57 | + |
| 58 | + _cmake = None |
| 59 | + |
| 60 | + def configure(self): |
| 61 | + if self.options.with_osg: |
| 62 | + self.options.with_osi = True |
| 63 | + if self.options.with_osi: |
| 64 | + self.options["open-simulation-interface"].shared = self.options.shared |
| 65 | + self.options["protobuf"].shared = self._protobuf_dyn |
| 66 | + self.options["protobuf"].debug_suffix = False |
| 67 | + |
| 68 | + def source(self): |
| 69 | + git = tools.Git(folder=self._git_dir) |
| 70 | + git.clone(self._git_url, self._git_ref, shallow=True) |
| 71 | + |
| 72 | + def system_requirements(self): |
| 73 | + pkg_names = None |
| 74 | + if self.options.with_osg: |
| 75 | + pkg_names = [ |
| 76 | + "libfontconfig1-dev", |
| 77 | + "libgl-dev", |
| 78 | + "libxrandr-dev", |
| 79 | + "libxinerama-dev", |
| 80 | + ] # TODO: add all system requirements |
| 81 | + if pkg_names: |
| 82 | + installer = SystemPackageTool() |
| 83 | + for pkg in pkg_names: |
| 84 | + installer.install([pkg]) |
| 85 | + |
| 86 | + def requirements(self): |
| 87 | + if self.options.with_osi: |
| 88 | + self.requires("protobuf/[~=3.15.5]", override=True) |
| 89 | + self.requires("open-simulation-interface/3.3.1@cloe/stable") |
| 90 | + |
| 91 | + def _configure_cmake(self): |
| 92 | + if self._cmake: |
| 93 | + return self._cmake |
| 94 | + self._cmake = CMake(self) |
| 95 | + self._cmake.definitions["CMAKE_PROJECT_SUBDIR"] = self._git_dir |
| 96 | + self._cmake.definitions["CMAKE_PROJECT_VERSION"] = self.version |
| 97 | + self._cmake.definitions["CMAKE_EXPORT_COMPILE_COMMANDS"] = True |
| 98 | + self._cmake.definitions["BUILD_SHARED_LIBS"] = self.options.shared |
| 99 | + self._cmake.definitions["USE_OSG"] = self.options.with_osg |
| 100 | + self._cmake.definitions["USE_OSI"] = self.options.with_osi |
| 101 | + self._cmake.definitions["USE_SUMO"] = self.options.with_sumo |
| 102 | + self._cmake.definitions["USE_GTEST"] = self.options.test |
| 103 | + self._cmake.definitions["DYN_PROTOBUF"] = self._protobuf_dyn |
| 104 | + self._cmake.configure() |
| 105 | + return self._cmake |
| 106 | + |
| 107 | + def build(self): |
| 108 | + trg_path = self._git_dir |
| 109 | + patch_file = self._patch_file |
| 110 | + if not self.in_local_cache: |
| 111 | + trg_path = self.source_folder + "/" + trg_path |
| 112 | + patch_file = self.recipe_folder + "/" + patch_file |
| 113 | + tools.patch(base_path=trg_path, patch_file=patch_file) |
| 114 | + |
| 115 | + cmake = self._configure_cmake() |
| 116 | + cmake.build() |
| 117 | + if self.options.test: |
| 118 | + self._prepare_tests() |
| 119 | + with tools.chdir(self._test_dir): |
| 120 | + with tools.environment_append(RunEnvironment(self).vars): |
| 121 | + for test in glob.glob("*_test"): |
| 122 | + self.run(Path(test).resolve().as_posix()) |
| 123 | + self._cleanup_tests() |
| 124 | + |
| 125 | + def _prepare_tests(self): |
| 126 | + for d in self._test_deps: |
| 127 | + self.run(f"ln -sf {self.source_folder}/{self._git_dir}/{d}") |
| 128 | + |
| 129 | + def _cleanup_tests(self): |
| 130 | + for d in self._test_deps: |
| 131 | + if os.path.islink(d): |
| 132 | + self.run(f"rm -f {d}") |
| 133 | + |
| 134 | + def package(self): |
| 135 | + cmake = self._configure_cmake() |
| 136 | + cmake.install() |
| 137 | + self.copy( |
| 138 | + pattern="*.hpp", |
| 139 | + dst="include", |
| 140 | + src=f"{self.source_folder}/{self._lib_dir}", |
| 141 | + keep_path=False, |
| 142 | + ) |
| 143 | + self.copy(pattern="*.so", dst="lib", src=self._lib_dir, keep_path=False) |
| 144 | + self.copy(pattern="*.a", dst="lib", src=self._lib_dir, keep_path=False) |
| 145 | + apps = os.listdir(self._bin_dir) |
| 146 | + for app in apps: |
| 147 | + self.copy( |
| 148 | + pattern=app, dst="bin", src=f"{self._bin_dir}/{app}", keep_path=False |
| 149 | + ) |
| 150 | + self.copy( |
| 151 | + pattern="*", |
| 152 | + dst=self._pkg_scenario_dir, |
| 153 | + src=f"{self.source_folder}/{self._resources_dir}", |
| 154 | + ) |
| 155 | + assert Path(f"{self.package_folder}/{self._pkg_scenario_dir}/xosc").exists() |
| 156 | + self.copy( |
| 157 | + "*", |
| 158 | + dst=self._pkg_scenario_dir, |
| 159 | + src=f"{self.source_folder}/{self._pkg_scenario_dir}", |
| 160 | + ) |
| 161 | + |
| 162 | + def package_id(self): |
| 163 | + if self.options.with_osi: |
| 164 | + self.info.requires["open-simulation-interface"].full_package_mode() |
| 165 | + |
| 166 | + def package_info(self): |
| 167 | + self.cpp_info.set_property("cmake_find_mode", "both") |
| 168 | + self.cpp_info.set_property("cmake_file_name", self.name) |
| 169 | + self.cpp_info.set_property("pkg_config_name", self.name) |
| 170 | + |
| 171 | + self.cpp_info.libs = tools.collect_libs(self) |
| 172 | + self.runenv_info.define("ESMINI_XOSC_PATH", f"{self.package_folder}/{self._pkg_scenario_dir}/xosc") |
0 commit comments