From e710425beb3de4adcf4d601da2f224503f876b6d Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 25 Dec 2023 18:35:41 +0100 Subject: Merge llvm-project main llvmorg-18-init-15692-g007ed0dccd6a This updates llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp to llvm-project main llvmorg-18-init-15692-g007ed0dccd6a. PR: 276104 MFC after: 1 month (cherry picked from commit cb14a3fe5122c879eae1fb480ed7ce82a699ddb6) --- contrib/llvm-project/llvm/lib/TextAPI/Utils.cpp | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 contrib/llvm-project/llvm/lib/TextAPI/Utils.cpp (limited to 'contrib/llvm-project/llvm/lib/TextAPI/Utils.cpp') diff --git a/contrib/llvm-project/llvm/lib/TextAPI/Utils.cpp b/contrib/llvm-project/llvm/lib/TextAPI/Utils.cpp new file mode 100644 index 000000000000..6d85083e0b54 --- /dev/null +++ b/contrib/llvm-project/llvm/lib/TextAPI/Utils.cpp @@ -0,0 +1,40 @@ +//===- Utils.cpp ----------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Implements utility functions for TextAPI Darwin operations. +// +//===----------------------------------------------------------------------===// + +#include "llvm/TextAPI/Utils.h" + +using namespace llvm; +using namespace llvm::MachO; + +void llvm::MachO::replace_extension(SmallVectorImpl &Path, + const Twine &Extension) { + StringRef P(Path.begin(), Path.size()); + auto ParentPath = sys::path::parent_path(P); + auto Filename = sys::path::filename(P); + + if (!ParentPath.ends_with(Filename.str() + ".framework")) { + sys::path::replace_extension(Path, Extension); + return; + } + // Framework dylibs do not have a file extension, in those cases the new + // extension is appended. e.g. given Path: "Foo.framework/Foo" and Extension: + // "tbd", the result is "Foo.framework/Foo.tbd". + SmallString<8> Storage; + StringRef Ext = Extension.toStringRef(Storage); + + // Append '.' if needed. + if (!Ext.empty() && Ext[0] != '.') + Path.push_back('.'); + + // Append extension. + Path.append(Ext.begin(), Ext.end()); +} -- cgit v1.2.3