From a3e0c86263b905f731711093294163972ac7497d Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Thu, 19 May 2022 13:10:18 -0500 Subject: [PATCH 1/5] Adjust single sample to pull in sample assets using relative paths --- .../Renderers/ToolkitSampleRenderer.xaml.cs | 22 ++++++++++++++----- common/Labs.Head.props | 22 +++++++++++++++++-- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitSampleRenderer.xaml.cs b/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitSampleRenderer.xaml.cs index 8d10bf033..7a086c90a 100644 --- a/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitSampleRenderer.xaml.cs +++ b/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitSampleRenderer.xaml.cs @@ -197,10 +197,19 @@ private async Task LoadData() /// /// Compute path to a code file bundled in the app using type information. - /// Assumes file path in project matches namespace. + /// Assumes path to file within the included assembly folder matches the namespace. /// private static string GetRelativePathToFileWithoutExtension(Type type) { + // MSBuild uses wildcard to find the files, and the wildcards decide where they end up + // Single experiments use relative paths, the allExperiment head uses absolute paths that grab from all experiments + // The discrepency is accounted for manually. + // Logic here is the exact same that MSBuild uses to find and include the files we need. + var assemblyName = typeof(ToolkitSampleRenderer).Assembly.GetName().Name; + var isAllExperimentHead = assemblyName.StartsWith("CommunityToolkit.Labs.", StringComparison.OrdinalIgnoreCase); + var isProjectTemplateHead = assemblyName.StartsWith("ProjectTemplate"); + var isSingleExperimentHead = !isAllExperimentHead && !isProjectTemplateHead; + var simpleAssemblyName = type.Assembly.GetName().Name; var typeNamespace = type.Namespace; @@ -213,13 +222,16 @@ private static string GetRelativePathToFileWithoutExtension(Type type) var sampleName = simpleAssemblyName.Replace(".Sample", ""); var folderPath = typeNamespace.Replace(simpleAssemblyName, "").Trim('.').Replace('.', '/'); - if (folderPath.Length != 0) - { folderPath += "/"; - } - return $"SourceAssets/{sampleName}/samples/{simpleAssemblyName}/{folderPath}{type.Name}"; + if (isSingleExperimentHead || isProjectTemplateHead) + return $"SourceAssets/{simpleAssemblyName}/{folderPath}{type.Name}"; + + if (isAllExperimentHead) + return $"SourceAssets/{sampleName}/samples/{simpleAssemblyName}/{folderPath}{type.Name}"; + + throw new InvalidOperationException("Unable to determine if running in a single or all experiment solution."); } } } diff --git a/common/Labs.Head.props b/common/Labs.Head.props index a9fd67f9d..ea9225468 100644 --- a/common/Labs.Head.props +++ b/common/Labs.Head.props @@ -22,7 +22,13 @@ - + + true + true + true + + + @@ -34,7 +40,19 @@ - + + + + + + + + + + + + + From 39438101e5501a9df5096766eb21106d88f8847f Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Fri, 20 May 2022 19:30:06 -0500 Subject: [PATCH 2/5] Use relative paths to resolve single-experiment labs --- .../ToolkitSampleMetadataGenerator.Sample.cs | 2 +- .../ToolkitDocumentationRenderer.xaml.cs | 26 ++++++++++++++++++- .../Renderers/ToolkitSampleRenderer.xaml.cs | 6 +++-- common/Labs.Head.props | 20 +++----------- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/common/CommunityToolkit.Labs.Core.SourceGenerators/ToolkitSampleMetadataGenerator.Sample.cs b/common/CommunityToolkit.Labs.Core.SourceGenerators/ToolkitSampleMetadataGenerator.Sample.cs index ed16e99bb..1bd939912 100644 --- a/common/CommunityToolkit.Labs.Core.SourceGenerators/ToolkitSampleMetadataGenerator.Sample.cs +++ b/common/CommunityToolkit.Labs.Core.SourceGenerators/ToolkitSampleMetadataGenerator.Sample.cs @@ -121,7 +121,7 @@ void Execute(IncrementalValuesProvider types, bool skipDiagnostics = fa ); var docFrontMatter = GatherDocumentFrontMatter(ctx, markdownFileData); - + if (isExecutingInSampleProject && !skipDiagnostics) { ReportSampleDiagnostics(ctx, toolkitSampleAttributeData, optionsPaneAttribute, generatedOptionPropertyData); diff --git a/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml.cs b/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml.cs index 1cb67b47a..da6dcc915 100644 --- a/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml.cs +++ b/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml.cs @@ -153,7 +153,31 @@ private void SampleListHyperlink_Click(object sender, RoutedEventArgs e) private static async Task GetDocumentationFileContents(ToolkitFrontMatter metadata) { - var fileUri = new Uri($"ms-appx:///SourceAssets/{metadata.FilePath}"); + // MSBuild uses wildcard to find the files, and the wildcards decide where they end up + // Single experiments use relative paths, the allExperiment head uses absolute paths that grab from all experiments + // The wildcard captures decide the paths. This discrepency is accounted for manually. + // Logic here is the exact same that MSBuild uses to find and include the files we need. + var assemblyName = typeof(ToolkitSampleRenderer).Assembly.GetName().Name; + if (string.IsNullOrWhiteSpace(assemblyName)) + throw new InvalidOperationException(); + + var isAllExperimentHead = assemblyName.StartsWith("CommunityToolkit.Labs.", StringComparison.OrdinalIgnoreCase); + var isProjectTemplateHead = assemblyName.StartsWith("ProjectTemplate"); + var isSingleExperimentHead = !isAllExperimentHead && !isProjectTemplateHead; + + if (metadata.FilePath is null || string.IsNullOrWhiteSpace(metadata.FilePath)) + throw new InvalidOperationException("Missing or malformed path to markdown file. Unable to continue;"); + + var path = metadata.FilePath; + + if (isSingleExperimentHead || isProjectTemplateHead) + { + var experimentName = assemblyName.Split(".")[0]; + path = path.Split($"\\{experimentName}.Sample")[1]; + path = $"{experimentName}.Sample{path}"; + } + + var fileUri = new Uri($"ms-appx:///SourceAssets/{path}"); try { diff --git a/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitSampleRenderer.xaml.cs b/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitSampleRenderer.xaml.cs index 7a086c90a..b0fc09e16 100644 --- a/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitSampleRenderer.xaml.cs +++ b/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitSampleRenderer.xaml.cs @@ -89,7 +89,6 @@ public UIElement? SampleControlInstance set => SetValue(SampleControlInstanceProperty, value); } - /// /// The options pane for the sample being displayed. /// @@ -203,9 +202,12 @@ private static string GetRelativePathToFileWithoutExtension(Type type) { // MSBuild uses wildcard to find the files, and the wildcards decide where they end up // Single experiments use relative paths, the allExperiment head uses absolute paths that grab from all experiments - // The discrepency is accounted for manually. + // The wildcard captures decide the paths. This discrepency is accounted for manually. // Logic here is the exact same that MSBuild uses to find and include the files we need. var assemblyName = typeof(ToolkitSampleRenderer).Assembly.GetName().Name; + if (string.IsNullOrWhiteSpace(assemblyName)) + throw new InvalidOperationException(); + var isAllExperimentHead = assemblyName.StartsWith("CommunityToolkit.Labs.", StringComparison.OrdinalIgnoreCase); var isProjectTemplateHead = assemblyName.StartsWith("ProjectTemplate"); var isSingleExperimentHead = !isAllExperimentHead && !isProjectTemplateHead; diff --git a/common/Labs.Head.props b/common/Labs.Head.props index ea9225468..d813b4db9 100644 --- a/common/Labs.Head.props +++ b/common/Labs.Head.props @@ -25,10 +25,10 @@ true true - true + true - + @@ -40,7 +40,7 @@ - + @@ -49,19 +49,7 @@ - - - - - - - - - - - - - + From 2551f15ab21465316f1e0a4d4d8dcba22cf78f44 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Mon, 23 May 2022 15:05:58 -0500 Subject: [PATCH 3/5] Fixed compiler errors on NS2.0 --- .../Renderers/ToolkitDocumentationRenderer.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml.cs b/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml.cs index da6dcc915..7134ced91 100644 --- a/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml.cs +++ b/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml.cs @@ -172,8 +172,8 @@ private static async Task GetDocumentationFileContents(ToolkitFrontMatte if (isSingleExperimentHead || isProjectTemplateHead) { - var experimentName = assemblyName.Split(".")[0]; - path = path.Split($"\\{experimentName}.Sample")[1]; + var experimentName = assemblyName.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)[0]; + path = path.Split(new[] { $"\\{experimentName}.Sample" }, StringSplitOptions.RemoveEmptyEntries)[1]; path = $"{experimentName}.Sample{path}"; } From e7686e9219d89dc1c03e37f33d3b221e24223264 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Tue, 24 May 2022 12:30:09 -0500 Subject: [PATCH 4/5] Fixed WASM head using relative paths to props file instead of csproj --- common/Labs.Head.props | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/Labs.Head.props b/common/Labs.Head.props index d813b4db9..54569945d 100644 --- a/common/Labs.Head.props +++ b/common/Labs.Head.props @@ -42,11 +42,11 @@ - - + + - + From d42189ad0b7fe240daa52782c6b901ed6d9637fd Mon Sep 17 00:00:00 2001 From: Arlo Date: Mon, 6 Jun 2022 20:39:04 +0000 Subject: [PATCH 5/5] Added comment links to #142 --- .../ToolkitDocumentationRenderer.xaml.cs | 1 + .../Renderers/ToolkitSampleRenderer.xaml.cs | 1 + common/Labs.Head.props | 24 ++++++++++--------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml.cs b/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml.cs index 7134ced91..1acbd6be4 100644 --- a/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml.cs +++ b/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml.cs @@ -153,6 +153,7 @@ private void SampleListHyperlink_Click(object sender, RoutedEventArgs e) private static async Task GetDocumentationFileContents(ToolkitFrontMatter metadata) { + // TODO: https://github.com/CommunityToolkit/Labs-Windows/issues/142 // MSBuild uses wildcard to find the files, and the wildcards decide where they end up // Single experiments use relative paths, the allExperiment head uses absolute paths that grab from all experiments // The wildcard captures decide the paths. This discrepency is accounted for manually. diff --git a/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitSampleRenderer.xaml.cs b/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitSampleRenderer.xaml.cs index b0fc09e16..47890d869 100644 --- a/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitSampleRenderer.xaml.cs +++ b/common/CommunityToolkit.Labs.Shared/Renderers/ToolkitSampleRenderer.xaml.cs @@ -200,6 +200,7 @@ private async Task LoadData() /// private static string GetRelativePathToFileWithoutExtension(Type type) { + // TODO: https://github.com/CommunityToolkit/Labs-Windows/issues/142 // MSBuild uses wildcard to find the files, and the wildcards decide where they end up // Single experiments use relative paths, the allExperiment head uses absolute paths that grab from all experiments // The wildcard captures decide the paths. This discrepency is accounted for manually. diff --git a/common/Labs.Head.props b/common/Labs.Head.props index 54569945d..aa078866a 100644 --- a/common/Labs.Head.props +++ b/common/Labs.Head.props @@ -16,42 +16,44 @@ - + + true true true + - - + + - + - + + - - + + - + - + - + true