Skip to content

[readtapi] Setup simple stubify support #76075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions llvm/include/llvm/TextAPI/Utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//===- llvm/TextAPI/Utils.h - TAPI Utils -----------------------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// Helper functionality used for Darwin specific operations.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TEXTAPI_UTILS_H
#define LLVM_TEXTAPI_UTILS_H

#include "llvm/ADT/Twine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"

#if !defined(PATH_MAX)
#define PATH_MAX 1024
#endif

namespace llvm::MachO {

using PathSeq = std::vector<std::string>;

/// Replace extension considering frameworks.
///
/// \param Path Location of file.
/// \param Extension File extension to update with.
void replace_extension(SmallVectorImpl<char> &Path, const Twine &Extension);
} // namespace llvm::MachO
#endif // LLVM_TEXTAPI_UTILS_H
1 change: 1 addition & 0 deletions llvm/lib/TextAPI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_llvm_component_library(LLVMTextAPI
TextAPIError.cpp
TextStub.cpp
TextStubCommon.cpp
Utils.cpp

ADDITIONAL_HEADER_DIRS
"${LLVM_MAIN_INCLUDE_DIR}/llvm/TextAPI"
Expand Down
40 changes: 40 additions & 0 deletions llvm/lib/TextAPI/Utils.cpp
Original file line number Diff line number Diff line change
@@ -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<char> &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());
}
Loading