1//===- Library.cpp --------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "clang/InstallAPI/Library.h"
10
11using namespace llvm;
12namespace clang::installapi {
13
14const Regex Rule("(.+)/(.+)\\.framework/");
15StringRef Library::getFrameworkNameFromInstallName(StringRef InstallName) {
16 assert(InstallName.contains(".framework") && "expected a framework");
17 SmallVector<StringRef, 3> Match;
18 Rule.match(String: InstallName, Matches: &Match);
19 if (Match.empty())
20 return "";
21 return Match.back();
22}
23
24StringRef Library::getName() const {
25 assert(!IsUnwrappedDylib && "expected a framework");
26 StringRef Path = BaseDirectory;
27
28 // Return the framework name extracted from path.
29 while (!Path.empty()) {
30 if (Path.ends_with(Suffix: ".framework"))
31 return sys::path::filename(path: Path);
32 Path = sys::path::parent_path(path: Path);
33 }
34
35 // Otherwise, return the name of the BaseDirectory.
36 Path = BaseDirectory;
37 return sys::path::filename(path: Path.rtrim(Chars: "/"));
38}
39
40} // namespace clang::installapi
41