| 1224 | } |
| 1225 | |
| 1226 | bool HandleReadElfCommand(std::vector<std::string> const& args, |
| 1227 | cmExecutionStatus& status) |
| 1228 | { |
| 1229 | if (args.size() < 4) { |
| 1230 | status.SetError("READ_ELF must be called with at least three additional " |
| 1231 | "arguments."); |
| 1232 | return false; |
| 1233 | } |
| 1234 | |
| 1235 | std::string const& fileNameArg = args[1]; |
| 1236 | |
| 1237 | struct Arguments |
| 1238 | { |
| 1239 | std::string RPath; |
| 1240 | std::string RunPath; |
| 1241 | std::string Error; |
| 1242 | }; |
| 1243 | |
| 1244 | static auto const parser = cmArgumentParser<Arguments>{} |
| 1245 | .Bind("RPATH"_s, &Arguments::RPath) |
| 1246 | .Bind("RUNPATH"_s, &Arguments::RunPath) |
| 1247 | .Bind("CAPTURE_ERROR"_s, &Arguments::Error); |
| 1248 | Arguments const arguments = parser.Parse(cmMakeRange(args).advance(2), |
| 1249 | /*unparsedArguments=*/nullptr); |
| 1250 | |
| 1251 | if (!cmSystemTools::FileExists(fileNameArg, true)) { |
| 1252 | status.SetError(cmStrCat("READ_ELF given FILE \"", fileNameArg, |
| 1253 | "\" that does not exist.")); |
| 1254 | return false; |
| 1255 | } |
| 1256 | |
| 1257 | cmELF elf(fileNameArg.c_str()); |
| 1258 | if (!elf) { |
| 1259 | if (arguments.Error.empty()) { |
| 1260 | status.SetError(cmStrCat("READ_ELF given FILE:\n ", fileNameArg, |
| 1261 | "\nthat is not a valid ELF file.")); |
| 1262 | return false; |
| 1263 | } |
| 1264 | status.GetMakefile().AddDefinition(arguments.Error, |
| 1265 | "not a valid ELF file"); |
| 1266 | return true; |
| 1267 | } |
| 1268 | |
| 1269 | if (!arguments.RPath.empty()) { |
| 1270 | if (cmELF::StringEntry const* se_rpath = elf.GetRPath()) { |
| 1271 | std::string rpath(se_rpath->Value); |
| 1272 | std::replace(rpath.begin(), rpath.end(), ':', ';'); |
| 1273 | status.GetMakefile().AddDefinition(arguments.RPath, rpath); |
| 1274 | } |
| 1275 | } |
| 1276 | if (!arguments.RunPath.empty()) { |
| 1277 | if (cmELF::StringEntry const* se_runpath = elf.GetRunPath()) { |
| 1278 | std::string runpath(se_runpath->Value); |
| 1279 | std::replace(runpath.begin(), runpath.end(), ':', ';'); |
| 1280 | status.GetMakefile().AddDefinition(arguments.RunPath, runpath); |
| 1281 | } |
| 1282 | } |
| 1283 |
nothing calls this directly
no test coverage detected
searching dependent graphs…