[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -0,0 +1,7 @@ +// RUN: rm -rf %t && mkdir %t +// RUN: cp "%s" "%t/test.cpp" PeterChou1 wrote: Sorry, the reason why I kept using this pattern is because I copied the same test setups in the original test for clang-doc [here](https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/test/clang-doc/single-file.cpp#L4) and [here](https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/test/clang-doc/single-file-public.cpp#L4) https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 updated https://github.com/llvm/llvm-project/pull/93281 >From f3eec972f66576fdacc578eaea3f158efdf57128 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 04:28:08 -0400 Subject: [PATCH 01/13] clang-doc switched from using relative to absolute paths --- clang-tools-extra/clang-doc/assets/index.js | 72 ++--- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index 49818763a4393..c1d32d353ea36 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -1,48 +1,46 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); - } - - var Dir = CurrentDirectory; - var Result = ""; - while (Dir) { -if (Dir == FilePath) - break; -Dir = Dir.substring(0, Dir.lastIndexOf("/")); -Result = append(Result, "..") +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} } - Result = append(Result, FilePath.substring(Dir.length)) - return Result; -} - -function genLink(Ref, CurrentDirectory) { - var Path = computeRelativePath(Ref.Path, CurrentDirectory); - if (Ref.RefType == "namespace") -Path = append(Path, "index.html"); - else -Path = append(Path, Ref.Name + ".html") -ANode = document.createElement("a"); + ANode = document.createElement("a"); ANode.setAttribute("href", Path); var TextNode = document.createTextNode(Ref.Name); ANode.appendChild(TextNode); return ANode; } +function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { + // Out will store the HTML elements that Index requires to be generated + var Out = []; + if (Index.Name) { +var SpanNode = document.createElement("span"); +var TextNode = document.createTextNode(Index.Name); +SpanNode.appendChild(genLink(Index)); +Out.push(SpanNode); + } + if (Index.Children.length == 0) +return Out; + // Only the outermost list should use ol, the others should use ul + var ListNodeName = IsOutermostList ? "ol" : "ul"; + var ListNode = document.createElement(ListNodeName); + for (Child of Index.Children) { +var LiNode = document.createElement("li"); +ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); +for (Node of ChildNodes) + LiNode.appendChild(Node); +ListNode.appendChild(LiNode); + } + Out.push(ListNode); + return Out; +} + function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated var Out = []; >From 4d4197fb0ffc83bfe582fbb212ce3dbdf2cdced0 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 05:10:03 -0400 Subject: [PATCH 02/13] remove duplicate function --- clang-tools-extra/clang-doc/assets/index.js | 24 - 1 file changed, 24 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index c1d32d353ea36..afc89c7c29ad8 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -16,30 +16,6 @@ function genLink(Ref) { return ANode; } -function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { - // Out will store the HTML elements that Index requires to be generated - var Out = []; - if (Index.Name) { -var SpanNode = document.createElement("span"); -var TextNode = document.createTextNode(Index.Name); -SpanNode.appendChild(genLink(Index)); -Out.push(SpanNode); - } - if (Index.Children.length == 0) -return Out; - // Only the outermost list should use ol, the others should use ul - var ListNodeName = IsOutermostList ? "ol" : "ul"; - var ListNode = document.createElement(ListNodeName); - for (Child of Index.Children) { -var LiNode = document.createElement("li"); -ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); -for (Node of ChildNodes) - LiNode.appendChild(Node); -ListNode.appendChild(LiNode); - } - Out.push(ListNode); - return Out; -} function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated >From 61e9da04203f12515c23803c467b56a8dd5c9189 Mon Sep 17 00:00:00 2001 From: PeterChou1
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -0,0 +1,7 @@ +// RUN: rm -rf %t && mkdir %t +// RUN: cp "%s" "%t/test.cpp" ilovepi wrote: Looks like I missed this. Please don’t copy the test file around. To be blunt this pattern has been brought up in multiple PRs and even in previous incarnations of this one. Use the same conventions we’ve insisted on in other tests here. https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 updated https://github.com/llvm/llvm-project/pull/93281 >From f3eec972f66576fdacc578eaea3f158efdf57128 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 04:28:08 -0400 Subject: [PATCH 01/12] clang-doc switched from using relative to absolute paths --- clang-tools-extra/clang-doc/assets/index.js | 72 ++--- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index 49818763a4393..c1d32d353ea36 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -1,48 +1,46 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); - } - - var Dir = CurrentDirectory; - var Result = ""; - while (Dir) { -if (Dir == FilePath) - break; -Dir = Dir.substring(0, Dir.lastIndexOf("/")); -Result = append(Result, "..") +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} } - Result = append(Result, FilePath.substring(Dir.length)) - return Result; -} - -function genLink(Ref, CurrentDirectory) { - var Path = computeRelativePath(Ref.Path, CurrentDirectory); - if (Ref.RefType == "namespace") -Path = append(Path, "index.html"); - else -Path = append(Path, Ref.Name + ".html") -ANode = document.createElement("a"); + ANode = document.createElement("a"); ANode.setAttribute("href", Path); var TextNode = document.createTextNode(Ref.Name); ANode.appendChild(TextNode); return ANode; } +function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { + // Out will store the HTML elements that Index requires to be generated + var Out = []; + if (Index.Name) { +var SpanNode = document.createElement("span"); +var TextNode = document.createTextNode(Index.Name); +SpanNode.appendChild(genLink(Index)); +Out.push(SpanNode); + } + if (Index.Children.length == 0) +return Out; + // Only the outermost list should use ol, the others should use ul + var ListNodeName = IsOutermostList ? "ol" : "ul"; + var ListNode = document.createElement(ListNodeName); + for (Child of Index.Children) { +var LiNode = document.createElement("li"); +ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); +for (Node of ChildNodes) + LiNode.appendChild(Node); +ListNode.appendChild(LiNode); + } + Out.push(ListNode); + return Out; +} + function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated var Out = []; >From 4d4197fb0ffc83bfe582fbb212ce3dbdf2cdced0 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 05:10:03 -0400 Subject: [PATCH 02/12] remove duplicate function --- clang-tools-extra/clang-doc/assets/index.js | 24 - 1 file changed, 24 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index c1d32d353ea36..afc89c7c29ad8 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -16,30 +16,6 @@ function genLink(Ref) { return ANode; } -function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { - // Out will store the HTML elements that Index requires to be generated - var Out = []; - if (Index.Name) { -var SpanNode = document.createElement("span"); -var TextNode = document.createTextNode(Index.Name); -SpanNode.appendChild(genLink(Index)); -Out.push(SpanNode); - } - if (Index.Children.length == 0) -return Out; - // Only the outermost list should use ol, the others should use ul - var ListNodeName = IsOutermostList ? "ol" : "ul"; - var ListNode = document.createElement(ListNodeName); - for (Child of Index.Children) { -var LiNode = document.createElement("li"); -ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); -for (Node of ChildNodes) - LiNode.appendChild(Node); -ListNode.appendChild(LiNode); - } - Out.push(ListNode); - return Out; -} function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated >From 61e9da04203f12515c23803c467b56a8dd5c9189 Mon Sep 17 00:00:00 2001 From: PeterChou1
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
ilovepi wrote: Hmm, seems like tests are failing. PTAL. https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -0,0 +1,7 @@ +// RUN: rm -rf %t && mkdir %t +// RUN: cp "%s" "%t/test.cpp" +// RUN: clang-doc --format=html --executor=standalone -p %s --output=%t +// RUN: FileCheck %s -input-file=%t/index_json.js -check-prefix=JSON-INDEX +// RUN: rm -rf %t + +// JSON-INDEX: var RootPath = "{{.*}}"; ilovepi wrote: Is there a way to make this check more meaningful? Can we match nothing in the path itself? https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/ilovepi approved this pull request. LGTM, but can we improve the check for RootPath somehow? I feel like there should be something we can match there. https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/ilovepi edited https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 updated https://github.com/llvm/llvm-project/pull/93281 >From f3eec972f66576fdacc578eaea3f158efdf57128 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 04:28:08 -0400 Subject: [PATCH 01/11] clang-doc switched from using relative to absolute paths --- clang-tools-extra/clang-doc/assets/index.js | 72 ++--- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index 49818763a4393..c1d32d353ea36 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -1,48 +1,46 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); - } - - var Dir = CurrentDirectory; - var Result = ""; - while (Dir) { -if (Dir == FilePath) - break; -Dir = Dir.substring(0, Dir.lastIndexOf("/")); -Result = append(Result, "..") +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} } - Result = append(Result, FilePath.substring(Dir.length)) - return Result; -} - -function genLink(Ref, CurrentDirectory) { - var Path = computeRelativePath(Ref.Path, CurrentDirectory); - if (Ref.RefType == "namespace") -Path = append(Path, "index.html"); - else -Path = append(Path, Ref.Name + ".html") -ANode = document.createElement("a"); + ANode = document.createElement("a"); ANode.setAttribute("href", Path); var TextNode = document.createTextNode(Ref.Name); ANode.appendChild(TextNode); return ANode; } +function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { + // Out will store the HTML elements that Index requires to be generated + var Out = []; + if (Index.Name) { +var SpanNode = document.createElement("span"); +var TextNode = document.createTextNode(Index.Name); +SpanNode.appendChild(genLink(Index)); +Out.push(SpanNode); + } + if (Index.Children.length == 0) +return Out; + // Only the outermost list should use ol, the others should use ul + var ListNodeName = IsOutermostList ? "ol" : "ul"; + var ListNode = document.createElement(ListNodeName); + for (Child of Index.Children) { +var LiNode = document.createElement("li"); +ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); +for (Node of ChildNodes) + LiNode.appendChild(Node); +ListNode.appendChild(LiNode); + } + Out.push(ListNode); + return Out; +} + function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated var Out = []; >From 4d4197fb0ffc83bfe582fbb212ce3dbdf2cdced0 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 05:10:03 -0400 Subject: [PATCH 02/11] remove duplicate function --- clang-tools-extra/clang-doc/assets/index.js | 24 - 1 file changed, 24 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index c1d32d353ea36..afc89c7c29ad8 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -16,30 +16,6 @@ function genLink(Ref) { return ANode; } -function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { - // Out will store the HTML elements that Index requires to be generated - var Out = []; - if (Index.Name) { -var SpanNode = document.createElement("span"); -var TextNode = document.createTextNode(Index.Name); -SpanNode.appendChild(genLink(Index)); -Out.push(SpanNode); - } - if (Index.Children.length == 0) -return Out; - // Only the outermost list should use ol, the others should use ul - var ListNodeName = IsOutermostList ? "ol" : "ul"; - var ListNode = document.createElement(ListNodeName); - for (Child of Index.Children) { -var LiNode = document.createElement("li"); -ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); -for (Node of ChildNodes) - LiNode.appendChild(Node); -ListNode.appendChild(LiNode); - } - Out.push(ListNode); - return Out; -} function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated >From 61e9da04203f12515c23803c467b56a8dd5c9189 Mon Sep 17 00:00:00 2001 From: PeterChou1
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 updated https://github.com/llvm/llvm-project/pull/93281 >From f3eec972f66576fdacc578eaea3f158efdf57128 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 04:28:08 -0400 Subject: [PATCH 01/10] clang-doc switched from using relative to absolute paths --- clang-tools-extra/clang-doc/assets/index.js | 72 ++--- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index 49818763a4393..c1d32d353ea36 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -1,48 +1,46 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); - } - - var Dir = CurrentDirectory; - var Result = ""; - while (Dir) { -if (Dir == FilePath) - break; -Dir = Dir.substring(0, Dir.lastIndexOf("/")); -Result = append(Result, "..") +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} } - Result = append(Result, FilePath.substring(Dir.length)) - return Result; -} - -function genLink(Ref, CurrentDirectory) { - var Path = computeRelativePath(Ref.Path, CurrentDirectory); - if (Ref.RefType == "namespace") -Path = append(Path, "index.html"); - else -Path = append(Path, Ref.Name + ".html") -ANode = document.createElement("a"); + ANode = document.createElement("a"); ANode.setAttribute("href", Path); var TextNode = document.createTextNode(Ref.Name); ANode.appendChild(TextNode); return ANode; } +function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { + // Out will store the HTML elements that Index requires to be generated + var Out = []; + if (Index.Name) { +var SpanNode = document.createElement("span"); +var TextNode = document.createTextNode(Index.Name); +SpanNode.appendChild(genLink(Index)); +Out.push(SpanNode); + } + if (Index.Children.length == 0) +return Out; + // Only the outermost list should use ol, the others should use ul + var ListNodeName = IsOutermostList ? "ol" : "ul"; + var ListNode = document.createElement(ListNodeName); + for (Child of Index.Children) { +var LiNode = document.createElement("li"); +ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); +for (Node of ChildNodes) + LiNode.appendChild(Node); +ListNode.appendChild(LiNode); + } + Out.push(ListNode); + return Out; +} + function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated var Out = []; >From 4d4197fb0ffc83bfe582fbb212ce3dbdf2cdced0 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 05:10:03 -0400 Subject: [PATCH 02/10] remove duplicate function --- clang-tools-extra/clang-doc/assets/index.js | 24 - 1 file changed, 24 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index c1d32d353ea36..afc89c7c29ad8 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -16,30 +16,6 @@ function genLink(Ref) { return ANode; } -function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { - // Out will store the HTML elements that Index requires to be generated - var Out = []; - if (Index.Name) { -var SpanNode = document.createElement("span"); -var TextNode = document.createTextNode(Index.Name); -SpanNode.appendChild(genLink(Index)); -Out.push(SpanNode); - } - if (Index.Children.length == 0) -return Out; - // Only the outermost list should use ol, the others should use ul - var ListNodeName = IsOutermostList ? "ol" : "ul"; - var ListNode = document.createElement(ListNodeName); - for (Child of Index.Children) { -var LiNode = document.createElement("li"); -ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); -for (Node of ChildNodes) - LiNode.appendChild(Node); -ListNode.appendChild(LiNode); - } - Out.push(ListNode); - return Out; -} function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated >From 61e9da04203f12515c23803c467b56a8dd5c9189 Mon Sep 17 00:00:00 2001 From: PeterChou1
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
PeterChou1 wrote: > any progress here? I wanted to merge the test cases prs so we could view the regressions from the tests https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
ilovepi wrote: any progress here? https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -7,6 +7,7 @@ // RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Rectangle.html -check-prefix=HTML-RECTANGLE // RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Circle.html -check-prefix=HTML-CIRCLE +// JSON-INDEX: var RootPath = "{{.*}}"; ilovepi wrote: Oh, then I'm not 100% sure we want to replace all the `\` w/ `/`. I know you mentioned browser behavior, but I'm not 100% certain that's a great motivation. When I thought it was a URL, there's obviously no issue, but, for a file system path, I'm hesitant to say with confidence that there's no downside. Also, given the test updates, IDK if this check is particularly useful. I don't see much difference in the check as is, and just ``` // JSON-INDEX: var RootPath = ``` https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -0,0 +1,7 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: echo "CHECK: var RootPath = \"%/t/docs\";" > %t/check.txt +// RUN: cp "%s" "%t/test.cpp" +// RUN: clang-doc --format=html --executor=standalone -p %t %t/test.cpp --output=%t/docs ilovepi wrote: ```suggestion // RUN: clang-doc --format=html --executor=standalone %s --output=%t ``` I don't think you need `-p`, and I don't see a good reason why you need a subdirectory for `docs`. https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -0,0 +1,7 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: echo "CHECK: var RootPath = \"%/t/docs\";" > %t/check.txt +// RUN: cp "%s" "%t/test.cpp" +// RUN: clang-doc --format=html --executor=standalone -p %t %t/test.cpp --output=%t/docs +// RUN: FileCheck %t/check.txt -input-file=%t/docs/index_json.js ilovepi wrote: ```suggestion // RUN: FileCheck %s -input-file=%t/index_json.js --check-prefix=SOME_PREFIX ``` https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -0,0 +1,7 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: echo "CHECK: var RootPath = \"%/t/docs\";" > %t/check.txt +// RUN: cp "%s" "%t/test.cpp" ilovepi wrote: I see you're trying to work around the path inconsistency issues, but that's just an end-around our testing practices, and we shouldn't be doing it. Tests server as documentation, and generating a test w/ `CHECK` lines undermines that pretty significantly. IMO if the test isn't useful w/ the regular expression, it isn't useful. As it stands I also can't reason about how the behavior here is changing as a result of this patch, so I don' think this is a particularly good/useful check. If possible, it would be good to add these tests in another patch(e.g. pre-commit them testing the current behavior), and then update these to make them pass. That requires either stacking the PR using [spr](https://github.com/spacedentist/spr), or just managing the github PRs carefully yourself. Either is fine. https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -0,0 +1,8 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: cp "%s" "%t/test.cpp" +// RUN: clang-doc --doxygen --executor=standalone -p %t %t/test.cpp -output=../docs +// RUN: FileCheck %s -input-file=%t/docs/index_json.js +// RUN: rm -rf %t + +// CHECK: var RootPath = "{{.*}}../docs"; ilovepi wrote: You don't need this file. All the checks can go in the other file. You can separate them w/ different identifiers w/ `--check-prefixes=FOO` in `FileCheck` commands. If you look at almost any test folder in LLVM you'll see examples. Also, https://llvm.org/docs/CommandGuide/FileCheck.html#cmdoption-FileCheck-check-prefix. Also, don't copy files that aren't needed. `%s` is good enough for all the cases that I see. https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -0,0 +1,7 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: echo "CHECK: var RootPath = \"%t\";" > %t/check.txt +// RUN: cp "%s" "%t/test.cpp" +// RUN: clang-doc --doxygen --executor=standalone -p %t %t/test.cpp -output=%t/docs +// RUN: FileCheck %t/check.txt -input-file=%t/docs/index_json.js +// RUN: rm -rf %t ilovepi wrote: the `rm -rf` line should be first. It's very useful to be able to examine the test files you generate when they break. If you do it this way, its likely that they're deleted. Also, unless there's gong to be a need for multiple directories, I don't think you need anything but `%t`. https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -0,0 +1,7 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: echo "CHECK: var RootPath = \"%t\";" > %t/check.txt +// RUN: cp "%s" "%t/test.cpp" ilovepi wrote: what is this doing? `CHECK` lines belong in the test file, generally. If you need to split them up somehow, there is the `split-file` utility (https://llvm.org/docs/TestingGuide.html#extra-files). But in this case, you don't need that at all, since these lines can be in this file https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -0,0 +1,7 @@ +// RUN: rm -rf %t +// RUN: mkdir %t ilovepi wrote: nit: Can be one line w/ `&&` https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 updated https://github.com/llvm/llvm-project/pull/93281 >From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 04:28:08 -0400 Subject: [PATCH 1/8] clang-doc switched from using relative to absolute paths --- clang-tools-extra/clang-doc/assets/index.js | 72 ++--- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index a5ac90f2e06e7..fe35e706cc98d 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -1,48 +1,46 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); - } - - var Dir = CurrentDirectory; - var Result = ""; - while (Dir) { -if (Dir == FilePath) - break; -Dir = Dir.substring(0, Dir.lastIndexOf("/")); -Result = append(Result, "..") +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} } - Result = append(Result, FilePath.substring(Dir.length)) - return Result; -} - -function genLink(Ref, CurrentDirectory) { - var Path = computeRelativePath(Ref.Path, CurrentDirectory); - if (Ref.RefType == "namespace") -Path = append(Path, "index.html"); - else -Path = append(Path, Ref.Name + ".html") -ANode = document.createElement("a"); + ANode = document.createElement("a"); ANode.setAttribute("href", Path); var TextNode = document.createTextNode(Ref.Name); ANode.appendChild(TextNode); return ANode; } +function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { + // Out will store the HTML elements that Index requires to be generated + var Out = []; + if (Index.Name) { +var SpanNode = document.createElement("span"); +var TextNode = document.createTextNode(Index.Name); +SpanNode.appendChild(genLink(Index)); +Out.push(SpanNode); + } + if (Index.Children.length == 0) +return Out; + // Only the outermost list should use ol, the others should use ul + var ListNodeName = IsOutermostList ? "ol" : "ul"; + var ListNode = document.createElement(ListNodeName); + for (Child of Index.Children) { +var LiNode = document.createElement("li"); +ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); +for (Node of ChildNodes) + LiNode.appendChild(Node); +ListNode.appendChild(LiNode); + } + Out.push(ListNode); + return Out; +} + function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated var Out = []; >From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 05:10:03 -0400 Subject: [PATCH 2/8] remove duplicate function --- clang-tools-extra/clang-doc/assets/index.js | 24 - 1 file changed, 24 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index fe35e706cc98d..b013418c82093 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -16,30 +16,6 @@ function genLink(Ref) { return ANode; } -function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { - // Out will store the HTML elements that Index requires to be generated - var Out = []; - if (Index.Name) { -var SpanNode = document.createElement("span"); -var TextNode = document.createTextNode(Index.Name); -SpanNode.appendChild(genLink(Index)); -Out.push(SpanNode); - } - if (Index.Children.length == 0) -return Out; - // Only the outermost list should use ol, the others should use ul - var ListNodeName = IsOutermostList ? "ol" : "ul"; - var ListNode = document.createElement(ListNodeName); - for (Child of Index.Children) { -var LiNode = document.createElement("li"); -ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); -for (Node of ChildNodes) - LiNode.appendChild(Node); -ListNode.appendChild(LiNode); - } - Out.push(ListNode); - return Out; -} function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated >From be0fb1acdd97a07e665b61fbba44d32dd40e1b94 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date:
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 updated https://github.com/llvm/llvm-project/pull/93281 >From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 04:28:08 -0400 Subject: [PATCH 1/7] clang-doc switched from using relative to absolute paths --- clang-tools-extra/clang-doc/assets/index.js | 72 ++--- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index a5ac90f2e06e7..fe35e706cc98d 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -1,48 +1,46 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); - } - - var Dir = CurrentDirectory; - var Result = ""; - while (Dir) { -if (Dir == FilePath) - break; -Dir = Dir.substring(0, Dir.lastIndexOf("/")); -Result = append(Result, "..") +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} } - Result = append(Result, FilePath.substring(Dir.length)) - return Result; -} - -function genLink(Ref, CurrentDirectory) { - var Path = computeRelativePath(Ref.Path, CurrentDirectory); - if (Ref.RefType == "namespace") -Path = append(Path, "index.html"); - else -Path = append(Path, Ref.Name + ".html") -ANode = document.createElement("a"); + ANode = document.createElement("a"); ANode.setAttribute("href", Path); var TextNode = document.createTextNode(Ref.Name); ANode.appendChild(TextNode); return ANode; } +function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { + // Out will store the HTML elements that Index requires to be generated + var Out = []; + if (Index.Name) { +var SpanNode = document.createElement("span"); +var TextNode = document.createTextNode(Index.Name); +SpanNode.appendChild(genLink(Index)); +Out.push(SpanNode); + } + if (Index.Children.length == 0) +return Out; + // Only the outermost list should use ol, the others should use ul + var ListNodeName = IsOutermostList ? "ol" : "ul"; + var ListNode = document.createElement(ListNodeName); + for (Child of Index.Children) { +var LiNode = document.createElement("li"); +ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); +for (Node of ChildNodes) + LiNode.appendChild(Node); +ListNode.appendChild(LiNode); + } + Out.push(ListNode); + return Out; +} + function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated var Out = []; >From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 05:10:03 -0400 Subject: [PATCH 2/7] remove duplicate function --- clang-tools-extra/clang-doc/assets/index.js | 24 - 1 file changed, 24 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index fe35e706cc98d..b013418c82093 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -16,30 +16,6 @@ function genLink(Ref) { return ANode; } -function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { - // Out will store the HTML elements that Index requires to be generated - var Out = []; - if (Index.Name) { -var SpanNode = document.createElement("span"); -var TextNode = document.createTextNode(Index.Name); -SpanNode.appendChild(genLink(Index)); -Out.push(SpanNode); - } - if (Index.Children.length == 0) -return Out; - // Only the outermost list should use ol, the others should use ul - var ListNodeName = IsOutermostList ? "ol" : "ul"; - var ListNode = document.createElement(ListNodeName); - for (Child of Index.Children) { -var LiNode = document.createElement("li"); -ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); -for (Node of ChildNodes) - LiNode.appendChild(Node); -ListNode.appendChild(LiNode); - } - Out.push(ListNode); - return Out; -} function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated >From be0fb1acdd97a07e665b61fbba44d32dd40e1b94 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date:
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 updated https://github.com/llvm/llvm-project/pull/93281 >From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 04:28:08 -0400 Subject: [PATCH 1/6] clang-doc switched from using relative to absolute paths --- clang-tools-extra/clang-doc/assets/index.js | 72 ++--- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index a5ac90f2e06e7..fe35e706cc98d 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -1,48 +1,46 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); - } - - var Dir = CurrentDirectory; - var Result = ""; - while (Dir) { -if (Dir == FilePath) - break; -Dir = Dir.substring(0, Dir.lastIndexOf("/")); -Result = append(Result, "..") +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} } - Result = append(Result, FilePath.substring(Dir.length)) - return Result; -} - -function genLink(Ref, CurrentDirectory) { - var Path = computeRelativePath(Ref.Path, CurrentDirectory); - if (Ref.RefType == "namespace") -Path = append(Path, "index.html"); - else -Path = append(Path, Ref.Name + ".html") -ANode = document.createElement("a"); + ANode = document.createElement("a"); ANode.setAttribute("href", Path); var TextNode = document.createTextNode(Ref.Name); ANode.appendChild(TextNode); return ANode; } +function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { + // Out will store the HTML elements that Index requires to be generated + var Out = []; + if (Index.Name) { +var SpanNode = document.createElement("span"); +var TextNode = document.createTextNode(Index.Name); +SpanNode.appendChild(genLink(Index)); +Out.push(SpanNode); + } + if (Index.Children.length == 0) +return Out; + // Only the outermost list should use ol, the others should use ul + var ListNodeName = IsOutermostList ? "ol" : "ul"; + var ListNode = document.createElement(ListNodeName); + for (Child of Index.Children) { +var LiNode = document.createElement("li"); +ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); +for (Node of ChildNodes) + LiNode.appendChild(Node); +ListNode.appendChild(LiNode); + } + Out.push(ListNode); + return Out; +} + function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated var Out = []; >From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 05:10:03 -0400 Subject: [PATCH 2/6] remove duplicate function --- clang-tools-extra/clang-doc/assets/index.js | 24 - 1 file changed, 24 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index fe35e706cc98d..b013418c82093 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -16,30 +16,6 @@ function genLink(Ref) { return ANode; } -function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { - // Out will store the HTML elements that Index requires to be generated - var Out = []; - if (Index.Name) { -var SpanNode = document.createElement("span"); -var TextNode = document.createTextNode(Index.Name); -SpanNode.appendChild(genLink(Index)); -Out.push(SpanNode); - } - if (Index.Children.length == 0) -return Out; - // Only the outermost list should use ol, the others should use ul - var ListNodeName = IsOutermostList ? "ol" : "ul"; - var ListNode = document.createElement(ListNodeName); - for (Child of Index.Children) { -var LiNode = document.createElement("li"); -ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); -for (Node of ChildNodes) - LiNode.appendChild(Node); -ListNode.appendChild(LiNode); - } - Out.push(ListNode); - return Out; -} function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated >From be0fb1acdd97a07e665b61fbba44d32dd40e1b94 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date:
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 updated https://github.com/llvm/llvm-project/pull/93281 >From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 04:28:08 -0400 Subject: [PATCH 1/5] clang-doc switched from using relative to absolute paths --- clang-tools-extra/clang-doc/assets/index.js | 72 ++--- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index a5ac90f2e06e7..fe35e706cc98d 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -1,48 +1,46 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); - } - - var Dir = CurrentDirectory; - var Result = ""; - while (Dir) { -if (Dir == FilePath) - break; -Dir = Dir.substring(0, Dir.lastIndexOf("/")); -Result = append(Result, "..") +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} } - Result = append(Result, FilePath.substring(Dir.length)) - return Result; -} - -function genLink(Ref, CurrentDirectory) { - var Path = computeRelativePath(Ref.Path, CurrentDirectory); - if (Ref.RefType == "namespace") -Path = append(Path, "index.html"); - else -Path = append(Path, Ref.Name + ".html") -ANode = document.createElement("a"); + ANode = document.createElement("a"); ANode.setAttribute("href", Path); var TextNode = document.createTextNode(Ref.Name); ANode.appendChild(TextNode); return ANode; } +function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { + // Out will store the HTML elements that Index requires to be generated + var Out = []; + if (Index.Name) { +var SpanNode = document.createElement("span"); +var TextNode = document.createTextNode(Index.Name); +SpanNode.appendChild(genLink(Index)); +Out.push(SpanNode); + } + if (Index.Children.length == 0) +return Out; + // Only the outermost list should use ol, the others should use ul + var ListNodeName = IsOutermostList ? "ol" : "ul"; + var ListNode = document.createElement(ListNodeName); + for (Child of Index.Children) { +var LiNode = document.createElement("li"); +ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); +for (Node of ChildNodes) + LiNode.appendChild(Node); +ListNode.appendChild(LiNode); + } + Out.push(ListNode); + return Out; +} + function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated var Out = []; >From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 05:10:03 -0400 Subject: [PATCH 2/5] remove duplicate function --- clang-tools-extra/clang-doc/assets/index.js | 24 - 1 file changed, 24 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index fe35e706cc98d..b013418c82093 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -16,30 +16,6 @@ function genLink(Ref) { return ANode; } -function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { - // Out will store the HTML elements that Index requires to be generated - var Out = []; - if (Index.Name) { -var SpanNode = document.createElement("span"); -var TextNode = document.createTextNode(Index.Name); -SpanNode.appendChild(genLink(Index)); -Out.push(SpanNode); - } - if (Index.Children.length == 0) -return Out; - // Only the outermost list should use ol, the others should use ul - var ListNodeName = IsOutermostList ? "ol" : "ul"; - var ListNode = document.createElement(ListNodeName); - for (Child of Index.Children) { -var LiNode = document.createElement("li"); -ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); -for (Node of ChildNodes) - LiNode.appendChild(Node); -ListNode.appendChild(LiNode); - } - Out.push(ListNode); - return Out; -} function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated >From be0fb1acdd97a07e665b61fbba44d32dd40e1b94 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date:
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 edited https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 edited https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -7,6 +7,7 @@ // RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Rectangle.html -check-prefix=HTML-RECTANGLE // RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Circle.html -check-prefix=HTML-CIRCLE +// JSON-INDEX: var RootPath = "{{.*}}"; PeterChou1 wrote: This isn't a url, this variable is a path to the directory where clang-doc is built from. I wanted the html to still render properly when viewed via the local filesystem so I added this export variable. Most the changes that is reflected in this patch can only be seen once the browser loads the page and javascript generates the sidebar with the indexes, I don't think its possible to see the changes reflected unless we incorporate some sort javascript test framework. We could also just generate the indexes via the c++ html generator than we be able to see the changes. I've added some test that test the different behaviour when we generate clang-doc via a relative path or an absolute one, though https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -1,12 +1,19 @@ function genLink(Ref) { var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + var isFileProtocol = window.location.protocol.startsWith("file"); + // we treat the file paths different depending on if we're + // serving via a http server or viewing from a local + if (isFileProtocol) { +Path = `${window.location.protocol}//${RootPath}/${Ref.Path}`; + } if (Ref.RefType !== "namespace") { if (Ref.Path === "") { Path = `${Path}${Ref.Name}.html`; -} -else { +} else { Path = `${Path}/${Ref.Name}.html`; } + } else { +Path = `${Path}/index.html` } PeterChou1 wrote: I don't think this will make a meaningful performance difference either way. Although I agree for readability purposes this is much more concise I've updated the code to reflect this https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 updated https://github.com/llvm/llvm-project/pull/93281 >From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 04:28:08 -0400 Subject: [PATCH 1/4] clang-doc switched from using relative to absolute paths --- clang-tools-extra/clang-doc/assets/index.js | 72 ++--- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index a5ac90f2e06e7..fe35e706cc98d 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -1,48 +1,46 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); - } - - var Dir = CurrentDirectory; - var Result = ""; - while (Dir) { -if (Dir == FilePath) - break; -Dir = Dir.substring(0, Dir.lastIndexOf("/")); -Result = append(Result, "..") +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} } - Result = append(Result, FilePath.substring(Dir.length)) - return Result; -} - -function genLink(Ref, CurrentDirectory) { - var Path = computeRelativePath(Ref.Path, CurrentDirectory); - if (Ref.RefType == "namespace") -Path = append(Path, "index.html"); - else -Path = append(Path, Ref.Name + ".html") -ANode = document.createElement("a"); + ANode = document.createElement("a"); ANode.setAttribute("href", Path); var TextNode = document.createTextNode(Ref.Name); ANode.appendChild(TextNode); return ANode; } +function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { + // Out will store the HTML elements that Index requires to be generated + var Out = []; + if (Index.Name) { +var SpanNode = document.createElement("span"); +var TextNode = document.createTextNode(Index.Name); +SpanNode.appendChild(genLink(Index)); +Out.push(SpanNode); + } + if (Index.Children.length == 0) +return Out; + // Only the outermost list should use ol, the others should use ul + var ListNodeName = IsOutermostList ? "ol" : "ul"; + var ListNode = document.createElement(ListNodeName); + for (Child of Index.Children) { +var LiNode = document.createElement("li"); +ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); +for (Node of ChildNodes) + LiNode.appendChild(Node); +ListNode.appendChild(LiNode); + } + Out.push(ListNode); + return Out; +} + function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated var Out = []; >From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 05:10:03 -0400 Subject: [PATCH 2/4] remove duplicate function --- clang-tools-extra/clang-doc/assets/index.js | 24 - 1 file changed, 24 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index fe35e706cc98d..b013418c82093 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -16,30 +16,6 @@ function genLink(Ref) { return ANode; } -function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { - // Out will store the HTML elements that Index requires to be generated - var Out = []; - if (Index.Name) { -var SpanNode = document.createElement("span"); -var TextNode = document.createTextNode(Index.Name); -SpanNode.appendChild(genLink(Index)); -Out.push(SpanNode); - } - if (Index.Children.length == 0) -return Out; - // Only the outermost list should use ol, the others should use ul - var ListNodeName = IsOutermostList ? "ol" : "ul"; - var ListNode = document.createElement(ListNodeName); - for (Child of Index.Children) { -var LiNode = document.createElement("li"); -ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); -for (Node of ChildNodes) - LiNode.appendChild(Node); -ListNode.appendChild(LiNode); - } - Out.push(ListNode); - return Out; -} function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated >From be0fb1acdd97a07e665b61fbba44d32dd40e1b94 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date:
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -1,12 +1,19 @@ function genLink(Ref) { var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + var isFileProtocol = window.location.protocol.startsWith("file"); + // we treat the file paths different depending on if we're + // serving via a http server or viewing from a local + if (isFileProtocol) { +Path = `${window.location.protocol}//${RootPath}/${Ref.Path}`; + } if (Ref.RefType !== "namespace") { if (Ref.Path === "") { Path = `${Path}${Ref.Name}.html`; -} -else { +} else { Path = `${Path}/${Ref.Name}.html`; } + } else { +Path = `${Path}/index.html` } ilovepi wrote: I'm also wondering if we should reverse the logic here to be slightly easer to follow. ``` if(Ref.RefType === "namespace"){ Path = `${Path}/index.html` } else { //... } ``` It's not really any functional change, though. IIRC in JS the ordering of statements has some performance impact, so I guess the ordering should be determined by which case we think is more common? Then again, you'd hope anything that affects performance would hit the JIT and get optimized nicely, so maybe this whole point is moot in practice. I'll leave the final determination up to you, since you deal w/ JS and website performance more frequently than I do. https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -1,12 +1,19 @@ function genLink(Ref) { var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + var isFileProtocol = window.location.protocol.startsWith("file"); + // we treat the file paths different depending on if we're + // serving via a http server or viewing from a local + if (isFileProtocol) { +Path = `${window.location.protocol}//${RootPath}/${Ref.Path}`; + } ilovepi wrote: Maybe it makes sense to initialize `Path` w/ the ternary operator? Also, I'm now wondering if we really want `var` here or if this should be declared w/ `let`. This should improve the performance slightly, since `Path` is only initialized once, and saves at least 1 allocation on the JS heap. My JS is pretty weak though, so if I'm wrong on that, I'm happy to defer. ```suggestion let isFileProtocol = window.location.protocol.startsWith("file"); // We treat the file paths different depending on if we're // serving via a http server or viewing from a local. var Path = isFileProtocol ? `${window.location.protocol}//${RootPath}/${Ref.Path}` :`${window.location.protocol}//${window.location.host}/${Ref.Path}`; ``` https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/ilovepi edited https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -7,6 +7,7 @@ // RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Rectangle.html -check-prefix=HTML-RECTANGLE // RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Circle.html -check-prefix=HTML-CIRCLE +// JSON-INDEX: var RootPath = "{{.*}}"; ilovepi wrote: This is a URL, right? if so, is there a reason it wouldn't match, regardless of platform? I'm a bit surprised this is the only change required to the tests, so I'm wondering if we're doing a good job checking things in our existing HTML tests. https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -979,6 +980,17 @@ static llvm::Error serializeIndex(ClangDocContext ) { "error creating index file: " + FileErr.message()); } + llvm::SmallString<128> RootPath(CDCtx.OutDirectory); + if (llvm::sys::path::is_relative(RootPath)) { +llvm::sys::fs::make_absolute(RootPath); + } + // replace escape character with forward slash it shouldn't matter + // when viewing from the browser this helps with preventing javascript + // from escaping unwanted characters leading to bad paths ilovepi wrote: Can you use sentences and punctuation here? Maybe something along these lines? ```suggestion // Replace the escaped characters with a forward slash. It shouldn't matter // when rendering the webpage in a web browser. This helps to prevent the // JavaScript from escaping characters incorrectly, and introducing bad paths // in the URLs. ``` https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/ilovepi commented: This is almost there. I've left a few minor comments, but I'd like to see better testing here. I'm awfully surprised we don't need to update any test lines, other than the 1 JS check. It would really help to see how the output is changing, if that was captured in the tests. https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 updated https://github.com/llvm/llvm-project/pull/93281 >From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 04:28:08 -0400 Subject: [PATCH 1/3] clang-doc switched from using relative to absolute paths --- clang-tools-extra/clang-doc/assets/index.js | 72 ++--- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index a5ac90f2e06e7..fe35e706cc98d 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -1,48 +1,46 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); - } - - var Dir = CurrentDirectory; - var Result = ""; - while (Dir) { -if (Dir == FilePath) - break; -Dir = Dir.substring(0, Dir.lastIndexOf("/")); -Result = append(Result, "..") +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} } - Result = append(Result, FilePath.substring(Dir.length)) - return Result; -} - -function genLink(Ref, CurrentDirectory) { - var Path = computeRelativePath(Ref.Path, CurrentDirectory); - if (Ref.RefType == "namespace") -Path = append(Path, "index.html"); - else -Path = append(Path, Ref.Name + ".html") -ANode = document.createElement("a"); + ANode = document.createElement("a"); ANode.setAttribute("href", Path); var TextNode = document.createTextNode(Ref.Name); ANode.appendChild(TextNode); return ANode; } +function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { + // Out will store the HTML elements that Index requires to be generated + var Out = []; + if (Index.Name) { +var SpanNode = document.createElement("span"); +var TextNode = document.createTextNode(Index.Name); +SpanNode.appendChild(genLink(Index)); +Out.push(SpanNode); + } + if (Index.Children.length == 0) +return Out; + // Only the outermost list should use ol, the others should use ul + var ListNodeName = IsOutermostList ? "ol" : "ul"; + var ListNode = document.createElement(ListNodeName); + for (Child of Index.Children) { +var LiNode = document.createElement("li"); +ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); +for (Node of ChildNodes) + LiNode.appendChild(Node); +ListNode.appendChild(LiNode); + } + Out.push(ListNode); + return Out; +} + function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated var Out = []; >From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 05:10:03 -0400 Subject: [PATCH 2/3] remove duplicate function --- clang-tools-extra/clang-doc/assets/index.js | 24 - 1 file changed, 24 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index fe35e706cc98d..b013418c82093 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -16,30 +16,6 @@ function genLink(Ref) { return ANode; } -function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { - // Out will store the HTML elements that Index requires to be generated - var Out = []; - if (Index.Name) { -var SpanNode = document.createElement("span"); -var TextNode = document.createTextNode(Index.Name); -SpanNode.appendChild(genLink(Index)); -Out.push(SpanNode); - } - if (Index.Children.length == 0) -return Out; - // Only the outermost list should use ol, the others should use ul - var ListNodeName = IsOutermostList ? "ol" : "ul"; - var ListNode = document.createElement(ListNodeName); - for (Child of Index.Children) { -var LiNode = document.createElement("li"); -ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); -for (Node of ChildNodes) - LiNode.appendChild(Node); -ListNode.appendChild(LiNode); - } - Out.push(ListNode); - return Out; -} function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated >From be0fb1acdd97a07e665b61fbba44d32dd40e1b94 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date:
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 edited https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 edited https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 8823448807f3b1a1362d1417e062d763734e02f5 48ceff111ef4ce2bfd6c9dd4ec7df272b35f3872 -- clang-tools-extra/clang-doc/HTMLGenerator.cpp `` View the diff from clang-format here. ``diff diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index 81ad607bc9..1a99c0c063 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -16,8 +16,8 @@ #include "llvm/Support/JSON.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" -#include #include +#include #include using namespace llvm; `` https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 updated https://github.com/llvm/llvm-project/pull/93281 >From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 04:28:08 -0400 Subject: [PATCH 1/3] clang-doc switched from using relative to absolute paths --- clang-tools-extra/clang-doc/assets/index.js | 72 ++--- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index a5ac90f2e06e7..fe35e706cc98d 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -1,48 +1,46 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); - } - - var Dir = CurrentDirectory; - var Result = ""; - while (Dir) { -if (Dir == FilePath) - break; -Dir = Dir.substring(0, Dir.lastIndexOf("/")); -Result = append(Result, "..") +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} } - Result = append(Result, FilePath.substring(Dir.length)) - return Result; -} - -function genLink(Ref, CurrentDirectory) { - var Path = computeRelativePath(Ref.Path, CurrentDirectory); - if (Ref.RefType == "namespace") -Path = append(Path, "index.html"); - else -Path = append(Path, Ref.Name + ".html") -ANode = document.createElement("a"); + ANode = document.createElement("a"); ANode.setAttribute("href", Path); var TextNode = document.createTextNode(Ref.Name); ANode.appendChild(TextNode); return ANode; } +function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { + // Out will store the HTML elements that Index requires to be generated + var Out = []; + if (Index.Name) { +var SpanNode = document.createElement("span"); +var TextNode = document.createTextNode(Index.Name); +SpanNode.appendChild(genLink(Index)); +Out.push(SpanNode); + } + if (Index.Children.length == 0) +return Out; + // Only the outermost list should use ol, the others should use ul + var ListNodeName = IsOutermostList ? "ol" : "ul"; + var ListNode = document.createElement(ListNodeName); + for (Child of Index.Children) { +var LiNode = document.createElement("li"); +ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); +for (Node of ChildNodes) + LiNode.appendChild(Node); +ListNode.appendChild(LiNode); + } + Out.push(ListNode); + return Out; +} + function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated var Out = []; >From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 05:10:03 -0400 Subject: [PATCH 2/3] remove duplicate function --- clang-tools-extra/clang-doc/assets/index.js | 24 - 1 file changed, 24 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index fe35e706cc98d..b013418c82093 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -16,30 +16,6 @@ function genLink(Ref) { return ANode; } -function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { - // Out will store the HTML elements that Index requires to be generated - var Out = []; - if (Index.Name) { -var SpanNode = document.createElement("span"); -var TextNode = document.createTextNode(Index.Name); -SpanNode.appendChild(genLink(Index)); -Out.push(SpanNode); - } - if (Index.Children.length == 0) -return Out; - // Only the outermost list should use ol, the others should use ul - var ListNodeName = IsOutermostList ? "ol" : "ul"; - var ListNode = document.createElement(ListNodeName); - for (Child of Index.Children) { -var LiNode = document.createElement("li"); -ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); -for (Node of ChildNodes) - LiNode.appendChild(Node); -ListNode.appendChild(LiNode); - } - Out.push(ListNode); - return Out; -} function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated >From 48ceff111ef4ce2bfd6c9dd4ec7df272b35f3872 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date:
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -1,48 +1,22 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} ilovepi wrote: ```suggestion if (Ref.RefType !== "namespace") { if (Ref.Path === "") { Path = `${Path}${Ref.Name}.html`; } else { Path = `${Path}/${Ref.Name}.html`; } ``` I would still probably format it slightly differently though. https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
@@ -1,48 +1,22 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} ilovepi wrote: oh, the other path has a `/` ... I missed that. Its fine to ignore this comment. https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 edited https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 edited https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] clang-doc switched from using relative to absolute paths (PR #93281)
@@ -1,48 +1,22 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} ilovepi wrote: I don't think this can be right, can it? The `if` and `else` have the same body. These branches used to retuern `index.html` or `${Path}${Ref.Name}.html`. Either the old behavior was correct, or this should be simplified to: ```suggestion if (Ref.RefType !== "namespace") { Path = `${Path}${Ref.Name}.html`; ``` https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] clang-doc switched from using relative to absolute paths (PR #93281)
https://github.com/ilovepi requested changes to this pull request. I'm not completely sure we want to use absolute paths, but since this mostly seems related to URLs and not file system paths, its probably fine. Please add some tests for this. It's preferable if we can pre-commit tests with the existing behavior, and then can easily see how this patch modifies the old/undesirable behavior. Lastly, please update the title: ```[clang-doc] Use absolute paths in URLs ``` and update the description to describe what this fixes and how, and links to the GitHub issue using `fixes` or something equivalent from https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] clang-doc switched from using relative to absolute paths (PR #93281)
@@ -1,48 +1,22 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} } - var Dir = CurrentDirectory; - var Result = ""; - while (Dir) { -if (Dir == FilePath) - break; -Dir = Dir.substring(0, Dir.lastIndexOf("/")); -Result = append(Result, "..") - } - Result = append(Result, FilePath.substring(Dir.length)) - return Result; -} - -function genLink(Ref, CurrentDirectory) { - var Path = computeRelativePath(Ref.Path, CurrentDirectory); - if (Ref.RefType == "namespace") -Path = append(Path, "index.html"); - else -Path = append(Path, Ref.Name + ".html") - -ANode = document.createElement("a"); + ANode = document.createElement("a"); ANode.setAttribute("href", Path); var TextNode = document.createTextNode(Ref.Name); ANode.appendChild(TextNode); return ANode; } + ilovepi wrote: nit: unrelated new line https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] clang-doc switched from using relative to absolute paths (PR #93281)
https://github.com/ilovepi edited https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] clang-doc switched from using relative to absolute paths (PR #93281)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/93281 >From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 04:28:08 -0400 Subject: [PATCH 1/2] clang-doc switched from using relative to absolute paths --- clang-tools-extra/clang-doc/assets/index.js | 72 ++--- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index a5ac90f2e06e7..fe35e706cc98d 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -1,48 +1,46 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); - } - - var Dir = CurrentDirectory; - var Result = ""; - while (Dir) { -if (Dir == FilePath) - break; -Dir = Dir.substring(0, Dir.lastIndexOf("/")); -Result = append(Result, "..") +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} } - Result = append(Result, FilePath.substring(Dir.length)) - return Result; -} - -function genLink(Ref, CurrentDirectory) { - var Path = computeRelativePath(Ref.Path, CurrentDirectory); - if (Ref.RefType == "namespace") -Path = append(Path, "index.html"); - else -Path = append(Path, Ref.Name + ".html") -ANode = document.createElement("a"); + ANode = document.createElement("a"); ANode.setAttribute("href", Path); var TextNode = document.createTextNode(Ref.Name); ANode.appendChild(TextNode); return ANode; } +function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { + // Out will store the HTML elements that Index requires to be generated + var Out = []; + if (Index.Name) { +var SpanNode = document.createElement("span"); +var TextNode = document.createTextNode(Index.Name); +SpanNode.appendChild(genLink(Index)); +Out.push(SpanNode); + } + if (Index.Children.length == 0) +return Out; + // Only the outermost list should use ol, the others should use ul + var ListNodeName = IsOutermostList ? "ol" : "ul"; + var ListNode = document.createElement(ListNodeName); + for (Child of Index.Children) { +var LiNode = document.createElement("li"); +ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); +for (Node of ChildNodes) + LiNode.appendChild(Node); +ListNode.appendChild(LiNode); + } + Out.push(ListNode); + return Out; +} + function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated var Out = []; >From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 05:10:03 -0400 Subject: [PATCH 2/2] remove duplicate function --- clang-tools-extra/clang-doc/assets/index.js | 24 - 1 file changed, 24 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index fe35e706cc98d..b013418c82093 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -16,30 +16,6 @@ function genLink(Ref) { return ANode; } -function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { - // Out will store the HTML elements that Index requires to be generated - var Out = []; - if (Index.Name) { -var SpanNode = document.createElement("span"); -var TextNode = document.createTextNode(Index.Name); -SpanNode.appendChild(genLink(Index)); -Out.push(SpanNode); - } - if (Index.Children.length == 0) -return Out; - // Only the outermost list should use ol, the others should use ul - var ListNodeName = IsOutermostList ? "ol" : "ul"; - var ListNode = document.createElement(ListNodeName); - for (Child of Index.Children) { -var LiNode = document.createElement("li"); -ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); -for (Node of ChildNodes) - LiNode.appendChild(Node); -ListNode.appendChild(LiNode); - } - Out.push(ListNode); - return Out; -} function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated ___ cfe-commits mailing list cfe-commits@lists.llvm.org
[clang-tools-extra] clang-doc switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 updated https://github.com/llvm/llvm-project/pull/93281 >From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 04:28:08 -0400 Subject: [PATCH 1/2] clang-doc switched from using relative to absolute paths --- clang-tools-extra/clang-doc/assets/index.js | 72 ++--- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index a5ac90f2e06e7..fe35e706cc98d 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -1,48 +1,46 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); - } - - var Dir = CurrentDirectory; - var Result = ""; - while (Dir) { -if (Dir == FilePath) - break; -Dir = Dir.substring(0, Dir.lastIndexOf("/")); -Result = append(Result, "..") +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} } - Result = append(Result, FilePath.substring(Dir.length)) - return Result; -} - -function genLink(Ref, CurrentDirectory) { - var Path = computeRelativePath(Ref.Path, CurrentDirectory); - if (Ref.RefType == "namespace") -Path = append(Path, "index.html"); - else -Path = append(Path, Ref.Name + ".html") -ANode = document.createElement("a"); + ANode = document.createElement("a"); ANode.setAttribute("href", Path); var TextNode = document.createTextNode(Ref.Name); ANode.appendChild(TextNode); return ANode; } +function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { + // Out will store the HTML elements that Index requires to be generated + var Out = []; + if (Index.Name) { +var SpanNode = document.createElement("span"); +var TextNode = document.createTextNode(Index.Name); +SpanNode.appendChild(genLink(Index)); +Out.push(SpanNode); + } + if (Index.Children.length == 0) +return Out; + // Only the outermost list should use ol, the others should use ul + var ListNodeName = IsOutermostList ? "ol" : "ul"; + var ListNode = document.createElement(ListNodeName); + for (Child of Index.Children) { +var LiNode = document.createElement("li"); +ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); +for (Node of ChildNodes) + LiNode.appendChild(Node); +ListNode.appendChild(LiNode); + } + Out.push(ListNode); + return Out; +} + function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated var Out = []; >From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 05:10:03 -0400 Subject: [PATCH 2/2] remove duplicate function --- clang-tools-extra/clang-doc/assets/index.js | 24 - 1 file changed, 24 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index fe35e706cc98d..b013418c82093 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -16,30 +16,6 @@ function genLink(Ref) { return ANode; } -function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { - // Out will store the HTML elements that Index requires to be generated - var Out = []; - if (Index.Name) { -var SpanNode = document.createElement("span"); -var TextNode = document.createTextNode(Index.Name); -SpanNode.appendChild(genLink(Index)); -Out.push(SpanNode); - } - if (Index.Children.length == 0) -return Out; - // Only the outermost list should use ol, the others should use ul - var ListNodeName = IsOutermostList ? "ol" : "ul"; - var ListNode = document.createElement(ListNodeName); - for (Child of Index.Children) { -var LiNode = document.createElement("li"); -ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); -for (Node of ChildNodes) - LiNode.appendChild(Node); -ListNode.appendChild(LiNode); - } - Out.push(ListNode); - return Out; -} function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated ___ cfe-commits mailing list
[clang-tools-extra] clang-doc switched from using relative to absolute paths (PR #93281)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: None (PeterChou1) Changes issue: https://github.com/llvm/llvm-project/issues/92867 I solved the problem by making the js use absolute path instead relative I think this also makes it more permanent since there is no need to compute relative path anymore --- Full diff: https://github.com/llvm/llvm-project/pull/93281.diff 1 Files Affected: - (modified) clang-tools-extra/clang-doc/assets/index.js (+35-37) ``diff diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index a5ac90f2e06e7..fe35e706cc98d 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -1,48 +1,46 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); - } - - var Dir = CurrentDirectory; - var Result = ""; - while (Dir) { -if (Dir == FilePath) - break; -Dir = Dir.substring(0, Dir.lastIndexOf("/")); -Result = append(Result, "..") +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} } - Result = append(Result, FilePath.substring(Dir.length)) - return Result; -} - -function genLink(Ref, CurrentDirectory) { - var Path = computeRelativePath(Ref.Path, CurrentDirectory); - if (Ref.RefType == "namespace") -Path = append(Path, "index.html"); - else -Path = append(Path, Ref.Name + ".html") -ANode = document.createElement("a"); + ANode = document.createElement("a"); ANode.setAttribute("href", Path); var TextNode = document.createTextNode(Ref.Name); ANode.appendChild(TextNode); return ANode; } +function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { + // Out will store the HTML elements that Index requires to be generated + var Out = []; + if (Index.Name) { +var SpanNode = document.createElement("span"); +var TextNode = document.createTextNode(Index.Name); +SpanNode.appendChild(genLink(Index)); +Out.push(SpanNode); + } + if (Index.Children.length == 0) +return Out; + // Only the outermost list should use ol, the others should use ul + var ListNodeName = IsOutermostList ? "ol" : "ul"; + var ListNode = document.createElement(ListNodeName); + for (Child of Index.Children) { +var LiNode = document.createElement("li"); +ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); +for (Node of ChildNodes) + LiNode.appendChild(Node); +ListNode.appendChild(LiNode); + } + Out.push(ListNode); + return Out; +} + function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated var Out = []; `` https://github.com/llvm/llvm-project/pull/93281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] clang-doc switched from using relative to absolute paths (PR #93281)
https://github.com/PeterChou1 created https://github.com/llvm/llvm-project/pull/93281 issue: https://github.com/llvm/llvm-project/issues/92867 I solved the problem by making the js use absolute path instead relative I think this also makes it more permanent since there is no need to compute relative path anymore >From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 04:28:08 -0400 Subject: [PATCH] clang-doc switched from using relative to absolute paths --- clang-tools-extra/clang-doc/assets/index.js | 72 ++--- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index a5ac90f2e06e7..fe35e706cc98d 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -1,48 +1,46 @@ -// Append using posix-style a file name or directory to Base -function append(Base, New) { - if (!New) -return Base; - if (Base) -Base += "/"; - Base += New; - return Base; -} - -// Get relative path to access FilePath from CurrentDirectory -function computeRelativePath(FilePath, CurrentDirectory) { - var Path = FilePath; - while (Path) { -if (CurrentDirectory == Path) - return FilePath.substring(Path.length + 1); -Path = Path.substring(0, Path.lastIndexOf("/")); - } - - var Dir = CurrentDirectory; - var Result = ""; - while (Dir) { -if (Dir == FilePath) - break; -Dir = Dir.substring(0, Dir.lastIndexOf("/")); -Result = append(Result, "..") +function genLink(Ref) { + var Path = `${window.location.protocol}//${window.location.host}/${Ref.Path}`; + if (Ref.RefType !== "namespace") { +if (Ref.Path === "") { + Path = `${Path}${Ref.Name}.html`; +} +else { + Path = `${Path}/${Ref.Name}.html`; +} } - Result = append(Result, FilePath.substring(Dir.length)) - return Result; -} - -function genLink(Ref, CurrentDirectory) { - var Path = computeRelativePath(Ref.Path, CurrentDirectory); - if (Ref.RefType == "namespace") -Path = append(Path, "index.html"); - else -Path = append(Path, Ref.Name + ".html") -ANode = document.createElement("a"); + ANode = document.createElement("a"); ANode.setAttribute("href", Path); var TextNode = document.createTextNode(Ref.Name); ANode.appendChild(TextNode); return ANode; } +function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { + // Out will store the HTML elements that Index requires to be generated + var Out = []; + if (Index.Name) { +var SpanNode = document.createElement("span"); +var TextNode = document.createTextNode(Index.Name); +SpanNode.appendChild(genLink(Index)); +Out.push(SpanNode); + } + if (Index.Children.length == 0) +return Out; + // Only the outermost list should use ol, the others should use ul + var ListNodeName = IsOutermostList ? "ol" : "ul"; + var ListNode = document.createElement(ListNodeName); + for (Child of Index.Children) { +var LiNode = document.createElement("li"); +ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false); +for (Node of ChildNodes) + LiNode.appendChild(Node); +ListNode.appendChild(LiNode); + } + Out.push(ListNode); + return Out; +} + function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) { // Out will store the HTML elements that Index requires to be generated var Out = []; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits