Skip to content

Commit 0d7728c

Browse files
authored
merge main into amd-staging (#629)
2 parents 304af5d + 6a3d6db commit 0d7728c

File tree

166 files changed

+12492
-10412
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+12492
-10412
lines changed

.github/workflows/commit-access-review.py

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -170,80 +170,6 @@ def get_num_commits(gh: github.Github, user: str, start_date: datetime.datetime)
170170
return count
171171

172172

173-
def is_new_committer_query_repo(
174-
gh: github.Github, user: str, start_date: datetime.datetime
175-
) -> bool:
176-
"""
177-
Determine if ``user`` is a new committer. A new committer can keep their
178-
commit access even if they don't meet the criteria.
179-
"""
180-
variables = {
181-
"user": user,
182-
}
183-
184-
user_query = """
185-
query ($user: String!) {
186-
user(login: $user) {
187-
id
188-
}
189-
}
190-
"""
191-
192-
res_header, res_data = gh._Github__requester.graphql_query(
193-
query=user_query, variables=variables
194-
)
195-
data = res_data["data"]
196-
variables["owner"] = "llvm"
197-
variables["user_id"] = data["user"]["id"]
198-
variables["start_date"] = start_date.strftime("%Y-%m-%dT%H:%M:%S")
199-
200-
query = """
201-
query ($owner: String!, $user_id: ID!){
202-
organization(login: $owner) {
203-
repository(name: "llvm-project") {
204-
ref(qualifiedName: "main") {
205-
target {
206-
... on Commit {
207-
history(author: {id: $user_id }, first: 5) {
208-
nodes {
209-
committedDate
210-
}
211-
}
212-
}
213-
}
214-
}
215-
}
216-
}
217-
}
218-
"""
219-
220-
res_header, res_data = gh._Github__requester.graphql_query(
221-
query=query, variables=variables
222-
)
223-
data = res_data["data"]
224-
repo = data["organization"]["repository"]
225-
commits = repo["ref"]["target"]["history"]["nodes"]
226-
if len(commits) == 0:
227-
return True
228-
committed_date = commits[-1]["committedDate"]
229-
if datetime.datetime.strptime(committed_date, "%Y-%m-%dT%H:%M:%SZ") < start_date:
230-
return False
231-
return True
232-
233-
234-
def is_new_committer(
235-
gh: github.Github, user: str, start_date: datetime.datetime
236-
) -> bool:
237-
"""
238-
Wrapper around is_new_commiter_query_repo to handle exceptions.
239-
"""
240-
try:
241-
return is_new_committer_query_repo(gh, user, start_date)
242-
except:
243-
pass
244-
return True
245-
246-
247173
def get_review_count(
248174
gh: github.Github, user: str, start_date: datetime.datetime
249175
) -> int:
@@ -383,13 +309,6 @@ def main():
383309

384310
print("After Commits:", len(triage_list), "triagers")
385311

386-
# Step 4 check for new committers
387-
for user in list(triage_list.keys()):
388-
print("Checking", user)
389-
if is_new_committer(gh, user, one_year_ago):
390-
print("Removing new committer: ", user)
391-
del triage_list[user]
392-
393312
print("Complete:", len(triage_list), "triagers")
394313

395314
with open("triagers.log", "w") as triagers_log:

.github/workflows/hlsl-test-all.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ jobs:
5252
repository: llvm/offload-golden-images
5353
ref: main
5454
path: golden-images
55-
- name: Setup Windows
56-
if: runner.os == 'Windows'
57-
uses: llvm/actions/setup-windows@5dd955034a6742a2e21d82bf165fcb1050ae7b49 # main
58-
with:
59-
arch: amd64
6055
- name: Build DXC
6156
run: |
6257
cd DXC

.github/workflows/libclang-abi-tests.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ jobs:
101101
ref: ${{ github.sha }}
102102
repo: ${{ github.repository }}
103103
steps:
104-
- name: Install Ninja
105-
uses: llvm/actions/install-ninja@5dd955034a6742a2e21d82bf165fcb1050ae7b49 # main
106104
- name: Download source code
107105
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
108106
with:

clang-tools-extra/clang-doc/Generators.cpp

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "Generators.h"
10+
#include "support/File.h"
11+
#include "llvm/Support/TimeProfiler.h"
1012

1113
LLVM_INSTANTIATE_REGISTRY(clang::doc::GeneratorRegistry)
1214

15+
using namespace llvm;
16+
using namespace llvm::json;
17+
using namespace llvm::mustache;
18+
1319
namespace clang {
1420
namespace doc {
1521

@@ -42,6 +48,136 @@ std::string getTagType(TagTypeKind AS) {
4248
llvm_unreachable("Unknown TagTypeKind");
4349
}
4450

51+
Error createFileOpenError(StringRef FileName, std::error_code EC) {
52+
return createFileError("cannot open file " + FileName, EC);
53+
}
54+
55+
Error MustacheGenerator::setupTemplate(
56+
std::unique_ptr<MustacheTemplateFile> &Template, StringRef TemplatePath,
57+
std::vector<std::pair<StringRef, StringRef>> Partials) {
58+
auto T = MustacheTemplateFile::createMustacheFile(TemplatePath);
59+
if (Error Err = T.takeError())
60+
return Err;
61+
Template = std::move(T.get());
62+
for (const auto &[Name, FileName] : Partials)
63+
if (auto Err = Template->registerPartialFile(Name, FileName))
64+
return Err;
65+
return Error::success();
66+
}
67+
68+
Error MustacheGenerator::generateDocumentation(
69+
StringRef RootDir, StringMap<std::unique_ptr<doc::Info>> Infos,
70+
const clang::doc::ClangDocContext &CDCtx, std::string DirName) {
71+
{
72+
llvm::TimeTraceScope TS("Setup Templates");
73+
if (auto Err = setupTemplateFiles(CDCtx))
74+
return Err;
75+
}
76+
77+
{
78+
llvm::TimeTraceScope TS("Generate JSON for Mustache");
79+
if (auto JSONGenerator = findGeneratorByName("json")) {
80+
if (Error Err = JSONGenerator.get()->generateDocumentation(
81+
RootDir, std::move(Infos), CDCtx))
82+
return Err;
83+
} else
84+
return JSONGenerator.takeError();
85+
}
86+
87+
SmallString<128> JSONPath;
88+
sys::path::native(RootDir.str() + "/json", JSONPath);
89+
90+
{
91+
llvm::TimeTraceScope TS("Iterate JSON files");
92+
std::error_code EC;
93+
sys::fs::recursive_directory_iterator JSONIter(JSONPath, EC);
94+
std::vector<json::Value> JSONFiles;
95+
JSONFiles.reserve(Infos.size());
96+
if (EC)
97+
return createStringError("Failed to create directory iterator.");
98+
99+
SmallString<128> DocsDirPath(RootDir.str() + '/' + DirName);
100+
sys::path::native(DocsDirPath);
101+
if (auto EC = sys::fs::create_directories(DocsDirPath))
102+
return createFileError(DocsDirPath, EC);
103+
while (JSONIter != sys::fs::recursive_directory_iterator()) {
104+
// create the same directory structure in the docs format dir
105+
if (JSONIter->type() == sys::fs::file_type::directory_file) {
106+
SmallString<128> DocsClonedPath(JSONIter->path());
107+
sys::path::replace_path_prefix(DocsClonedPath, JSONPath, DocsDirPath);
108+
if (auto EC = sys::fs::create_directories(DocsClonedPath)) {
109+
return createFileError(DocsClonedPath, EC);
110+
}
111+
}
112+
113+
if (EC)
114+
return createFileError("Failed to iterate: " + JSONIter->path(), EC);
115+
116+
auto Path = StringRef(JSONIter->path());
117+
if (!Path.ends_with(".json")) {
118+
JSONIter.increment(EC);
119+
continue;
120+
}
121+
122+
auto File = MemoryBuffer::getFile(Path);
123+
if (EC = File.getError(); EC) {
124+
// TODO: Buffer errors to report later, look into using Clang
125+
// diagnostics.
126+
llvm::errs() << "Failed to open file: " << Path << " " << EC.message()
127+
<< '\n';
128+
}
129+
130+
auto Parsed = json::parse((*File)->getBuffer());
131+
if (!Parsed)
132+
return Parsed.takeError();
133+
auto ValidJSON = Parsed.get();
134+
135+
std::error_code FileErr;
136+
SmallString<128> DocsFilePath(JSONIter->path());
137+
sys::path::replace_path_prefix(DocsFilePath, JSONPath, DocsDirPath);
138+
sys::path::replace_extension(DocsFilePath, DirName);
139+
raw_fd_ostream InfoOS(DocsFilePath, FileErr, sys::fs::OF_None);
140+
if (FileErr)
141+
return createFileOpenError(Path, FileErr);
142+
143+
auto RelativeRootPath = getRelativePathToRoot(DocsFilePath, DocsDirPath);
144+
auto InfoTypeStr =
145+
getInfoTypeStr(Parsed->getAsObject(), sys::path::stem(DocsFilePath));
146+
if (!InfoTypeStr)
147+
return InfoTypeStr.takeError();
148+
if (Error Err = generateDocForJSON(*Parsed, InfoOS, CDCtx,
149+
InfoTypeStr.get(), RelativeRootPath))
150+
return Err;
151+
JSONIter.increment(EC);
152+
}
153+
}
154+
155+
return Error::success();
156+
}
157+
158+
Expected<std::string> MustacheGenerator::getInfoTypeStr(Object *Info,
159+
StringRef Filename) {
160+
auto StrValue = (*Info)["InfoType"];
161+
if (StrValue.kind() != json::Value::Kind::String)
162+
return createStringError("JSON file '%s' does not contain key: 'InfoType'.",
163+
Filename.str().c_str());
164+
auto ObjTypeStr = StrValue.getAsString();
165+
if (!ObjTypeStr.has_value())
166+
return createStringError(
167+
"JSON file '%s' does not contain 'InfoType' field as a string.",
168+
Filename.str().c_str());
169+
return ObjTypeStr.value().str();
170+
}
171+
172+
SmallString<128>
173+
MustacheGenerator::getRelativePathToRoot(StringRef PathToFile,
174+
StringRef DocsRootPath) {
175+
SmallString<128> PathVec(PathToFile);
176+
// Remove filename, or else the relative path will have an extra "../"
177+
sys::path::remove_filename(PathVec);
178+
return computeRelativePath(DocsRootPath, PathVec);
179+
}
180+
45181
llvm::Error Generator::createResources(ClangDocContext &CDCtx) {
46182
return llvm::Error::success();
47183
}

clang-tools-extra/clang-doc/Generators.h

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include "Representation.h"
1616
#include "llvm/Support/Error.h"
17+
#include "llvm/Support/JSON.h"
18+
#include "llvm/Support/Mustache.h"
1719
#include "llvm/Support/Registry.h"
1820

1921
namespace clang {
@@ -27,10 +29,9 @@ class Generator {
2729

2830
// Write out the decl info for the objects in the given map in the specified
2931
// format.
30-
virtual llvm::Error
31-
generateDocs(StringRef RootDir,
32-
llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
33-
const ClangDocContext &CDCtx) = 0;
32+
virtual llvm::Error generateDocumentation(
33+
StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
34+
const ClangDocContext &CDCtx, std::string DirName = "") = 0;
3435

3536
// This function writes a file with the index previously constructed.
3637
// It can be overwritten by any of the inherited generators.
@@ -52,6 +53,85 @@ findGeneratorByName(llvm::StringRef Format);
5253

5354
std::string getTagType(TagTypeKind AS);
5455

56+
llvm::Error createFileOpenError(StringRef FileName, std::error_code EC);
57+
58+
class MustacheTemplateFile {
59+
llvm::BumpPtrAllocator Allocator;
60+
llvm::StringSaver Saver;
61+
llvm::mustache::MustacheContext Ctx;
62+
llvm::mustache::Template T;
63+
std::unique_ptr<llvm::MemoryBuffer> Buffer;
64+
65+
public:
66+
static Expected<std::unique_ptr<MustacheTemplateFile>>
67+
createMustacheFile(StringRef FileName) {
68+
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> BufferOrError =
69+
llvm::MemoryBuffer::getFile(FileName);
70+
if (auto EC = BufferOrError.getError())
71+
return createFileOpenError(FileName, EC);
72+
return std::make_unique<MustacheTemplateFile>(
73+
std::move(BufferOrError.get()));
74+
}
75+
76+
llvm::Error registerPartialFile(StringRef Name, StringRef FileName) {
77+
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> BufferOrError =
78+
llvm::MemoryBuffer::getFile(FileName);
79+
if (auto EC = BufferOrError.getError())
80+
return createFileOpenError(FileName, EC);
81+
82+
std::unique_ptr<llvm::MemoryBuffer> Buffer = std::move(BufferOrError.get());
83+
StringRef FileContent = Buffer->getBuffer();
84+
T.registerPartial(Name.str(), FileContent.str());
85+
return llvm::Error::success();
86+
}
87+
88+
void render(llvm::json::Value &V, raw_ostream &OS) { T.render(V, OS); }
89+
90+
MustacheTemplateFile(std::unique_ptr<llvm::MemoryBuffer> &&B)
91+
: Saver(Allocator), Ctx(Allocator, Saver), T(B->getBuffer(), Ctx),
92+
Buffer(std::move(B)) {}
93+
};
94+
95+
struct MustacheGenerator : public Generator {
96+
Expected<std::string> getInfoTypeStr(llvm::json::Object *Info,
97+
StringRef Filename);
98+
99+
/// Used to find the relative path from the file to the format's docs root.
100+
/// Mainly used for the HTML resource paths.
101+
SmallString<128> getRelativePathToRoot(StringRef PathToFile,
102+
StringRef DocsRootPath);
103+
virtual ~MustacheGenerator() = default;
104+
105+
/// Initializes the template files from disk and calls setupTemplate to
106+
/// register partials
107+
virtual llvm::Error setupTemplateFiles(const ClangDocContext &CDCtx) = 0;
108+
109+
/// Populates templates with data from JSON and calls any specifics for the
110+
/// format. For example, for HTML it will render the paths for CSS and JS.
111+
virtual llvm::Error generateDocForJSON(llvm::json::Value &JSON,
112+
llvm::raw_fd_ostream &OS,
113+
const ClangDocContext &CDCtx,
114+
StringRef ObjectTypeStr,
115+
StringRef RelativeRootPath) = 0;
116+
117+
/// Registers partials to templates.
118+
llvm::Error
119+
setupTemplate(std::unique_ptr<MustacheTemplateFile> &Template,
120+
StringRef TemplatePath,
121+
std::vector<std::pair<StringRef, StringRef>> Partials);
122+
123+
/// \brief The main orchestrator for Mustache-based documentation.
124+
///
125+
/// 1. Initializes templates files from disk by calling setupTemplateFiles.
126+
/// 2. Calls the JSON generator to write JSON to disk.
127+
/// 3. Iterates over the JSON files, recreates the directory structure from
128+
/// JSON, and calls generateDocForJSON for each file.
129+
/// 4. A file of the desired format is created.
130+
llvm::Error generateDocumentation(
131+
StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
132+
const clang::doc::ClangDocContext &CDCtx, std::string DirName) override;
133+
};
134+
55135
// This anchor is used to force the linker to link in the generated object file
56136
// and thus register the generators.
57137
extern volatile int YAMLGeneratorAnchorSource;

0 commit comments

Comments
 (0)