| 467 | } |
| 468 | |
| 469 | cm::optional<cmPkgConfigResult> ReadPackage(std::string const& package, |
| 470 | ImportEnv& imEnv, |
| 471 | cmPkgConfigEnv& pcEnv) |
| 472 | { |
| 473 | cm::optional<cmPkgConfigResult> result; |
| 474 | cm::filesystem::path path{ package }; |
| 475 | |
| 476 | if (path.extension() == ".pc") { |
| 477 | if (!cmSystemTools::FileExists(path.string())) { |
| 478 | return result; |
| 479 | } |
| 480 | } else { |
| 481 | |
| 482 | if (pcEnv.DisableUninstalled && !*pcEnv.DisableUninstalled) { |
| 483 | auto uninstalled = path; |
| 484 | uninstalled.concat("-uninstalled.pc"); |
| 485 | uninstalled = |
| 486 | cmSystemTools::FindFile(uninstalled.string(), pcEnv.search, true); |
| 487 | if (uninstalled.empty()) { |
| 488 | path = cmSystemTools::FindFile(path.concat(".pc").string(), |
| 489 | pcEnv.search, true); |
| 490 | if (path.empty()) { |
| 491 | return result; |
| 492 | } |
| 493 | } else { |
| 494 | path = uninstalled; |
| 495 | } |
| 496 | } else { |
| 497 | path = cmSystemTools::FindFile(path.concat(".pc").string(), pcEnv.search, |
| 498 | true); |
| 499 | if (path.empty()) { |
| 500 | return result; |
| 501 | } |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | auto len = cmSystemTools::FileLength(path.string()); |
| 506 | |
| 507 | // Windows requires this weird string -> c_str dance |
| 508 | cmsys::ifstream ifs(path.string().c_str(), std::ios::binary); |
| 509 | |
| 510 | if (!ifs) { |
| 511 | warn_or_error(cmStrCat("Could not open file '", path.string(), '\''), |
| 512 | imEnv); |
| 513 | return result; |
| 514 | } |
| 515 | |
| 516 | std::unique_ptr<char[]> buf(new char[len]); |
| 517 | ifs.read(buf.get(), len); |
| 518 | |
| 519 | // Shouldn't have hit eof on previous read, should hit eof now |
| 520 | if (ifs.fail() || ifs.eof() || ifs.get() != EOF) { |
| 521 | warn_or_error(cmStrCat("Error while reading file '", path.string(), '\''), |
| 522 | imEnv); |
| 523 | return result; |
| 524 | } |
| 525 | |
| 526 | using StrictnessType = CommonArguments::StrictnessType; |
no test coverage detected
searching dependent graphs…