1 //===- Utils.cpp ----------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // Implements utility functions for TextAPI Darwin operations.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/TextAPI/Utils.h"
16 using namespace llvm::MachO
;
18 void llvm::MachO::replace_extension(SmallVectorImpl
<char> &Path
,
19 const Twine
&Extension
) {
20 StringRef
P(Path
.begin(), Path
.size());
21 auto ParentPath
= sys::path::parent_path(P
);
22 auto Filename
= sys::path::filename(P
);
24 if (!ParentPath
.ends_with(Filename
.str() + ".framework")) {
25 sys::path::replace_extension(Path
, Extension
);
28 // Framework dylibs do not have a file extension, in those cases the new
29 // extension is appended. e.g. given Path: "Foo.framework/Foo" and Extension:
30 // "tbd", the result is "Foo.framework/Foo.tbd".
31 SmallString
<8> Storage
;
32 StringRef Ext
= Extension
.toStringRef(Storage
);
34 // Append '.' if needed.
35 if (!Ext
.empty() && Ext
[0] != '.')
39 Path
.append(Ext
.begin(), Ext
.end());