Skip to content

Commit

Permalink
Remove UserDefinedTypes feature flag (#11461)
Browse files Browse the repository at this point in the history
Resolves #4158 

This PR also updates the TemplateWriter to target a non-experimental ARM
languageVersion that allows type definitions (2.0). Templates using
experimental ARM features (e.g., extensibility and asserts) now target
the 2.1-experimental language version.

The languageVersion change entailed a large number of baseline changes.
These are included in this PR in a separate commit, and I'll go through
and flag any unexpected baseline change.
###### Microsoft Reviewers:
codeflow:open?pullrequest=https://github.com/Azure/bicep/pull/11461&drop=dogfoodAlpha
  • Loading branch information
jeskew committed Aug 10, 2023
1 parent 56142dc commit 3319ec7
Show file tree
Hide file tree
Showing 315 changed files with 1,851 additions and 2,037 deletions.
26 changes: 10 additions & 16 deletions src/Bicep.Cli/CliResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions src/Bicep.Cli/CliResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="SymbolicNamesDisclaimerMessage" xml:space="preserve">
<value>WARNING: Symbolic name support in ARM is experimental, and should be enabled for testing purposes only. Do not enable this setting for any production usage, or you may be unexpectedly broken at any time!</value>
</data>
<data name="ResourceTypesDisclaimerMessage" xml:space="preserve">
<value>WARNING: Resource-typed parameters and outputs in ARM are experimental, and should be enabled for testing purposes only. Do not enable this setting for any production usage, or you may be unexpectedly broken at any time!</value>
</data>
<data name="DecompilationFailedFormat" xml:space="preserve">
<value>{0}: Decompilation failed with fatal error "{1}"</value>
<comment>{0} json path {1} message string</comment>
Expand All @@ -147,4 +141,8 @@
<value>The specified input "{0}" was not recognized as a Bicep or Bicep Parameters file. Valid files must either the .bicep or .bicepparam extension.</value>
<comment>{0} input file path</comment>
</data>
<data name="ExperimentalFeaturesDisclaimerMessage" xml:space="preserve">
<value>WARNING: The following experimental Bicep features have been enabled: {0}. Experimental features should be enabled for testing purposes only. Do not enable these settings for any production usage, or you may be unexpectedly broken at any time!</value>
<comment>{0} comma-separated list of enabled experimental features</comment>
</data>
</root>
22 changes: 7 additions & 15 deletions src/Bicep.Cli/Commands/BuildCommand.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Linq;
using System.Threading.Tasks;
using Bicep.Cli.Arguments;
using Bicep.Cli.Helpers;
using Bicep.Cli.Logging;
using Bicep.Cli.Services;
using Bicep.Core.Configuration;
using Bicep.Core.Emit;
using Bicep.Core.Features;
using Bicep.Core.FileSystem;
using Bicep.Core.Workspaces;
using Microsoft.Extensions.Logging;

namespace Bicep.Cli.Commands
Expand Down Expand Up @@ -39,24 +38,17 @@ public BuildCommand(
public async Task<int> RunAsync(BuildArguments args)
{
var inputPath = PathHelper.ResolvePath(args.InputFile);
var features = featureProviderFactory.GetFeatureProvider(PathHelper.FilePathToFileUrl(inputPath));
var emitterSettings = new EmitterSettings(features, BicepSourceFileKind.BicepFile);

if (emitterSettings.EnableSymbolicNames)
{
logger.LogWarning(CliResources.SymbolicNamesDisclaimerMessage);
}

if (features.ResourceTypedParamsAndOutputsEnabled)
{
logger.LogWarning(CliResources.ResourceTypesDisclaimerMessage);
}

if (IsBicepFile(inputPath))
{
diagnosticLogger.SetupFormat(args.DiagnosticsFormat);
var compilation = await compilationService.CompileAsync(inputPath, args.NoRestore);

if (ExperimentalFeatureWarningProvider.TryGetEnabledExperimentalFeatureWarningMessage(compilation.SourceFileGrouping, featureProviderFactory) is {} warningMessage)
{
logger.LogWarning(warningMessage);
}

if (diagnosticLogger.ErrorCount < 1)
{
if (args.OutputToStdOut)
Expand Down
21 changes: 6 additions & 15 deletions src/Bicep.Cli/Commands/BuildParamsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

using System.Threading.Tasks;
using Bicep.Cli.Arguments;
using Bicep.Cli.Helpers;
using Bicep.Cli.Logging;
using Bicep.Cli.Services;
using Bicep.Core.Emit;
using Bicep.Core.Features;
using Bicep.Core.FileSystem;
using Bicep.Core.Workspaces;
using Microsoft.Extensions.Logging;

namespace Bicep.Cli.Commands
Expand Down Expand Up @@ -43,19 +42,6 @@ public async Task<int> RunAsync(BuildParamsArguments args)
var paramsInputPath = PathHelper.ResolvePath(args.ParamsFile);
var bicepFileArgPath = args.BicepFile != null ? PathHelper.ResolvePath(args.BicepFile) : null;

var features = featureProviderFactory.GetFeatureProvider(PathHelper.FilePathToFileUrl(paramsInputPath));
var emitterSettings = new EmitterSettings(features, BicepSourceFileKind.ParamsFile);

if (emitterSettings.EnableSymbolicNames)
{
logger.LogWarning(CliResources.SymbolicNamesDisclaimerMessage);
}

if (features.ResourceTypedParamsAndOutputsEnabled)
{
logger.LogWarning(CliResources.ResourceTypesDisclaimerMessage);
}

if (bicepFileArgPath != null && !IsBicepFile(bicepFileArgPath))
{
throw new CommandLineException($"{bicepFileArgPath} is not a bicep file");
Expand All @@ -69,6 +55,11 @@ public async Task<int> RunAsync(BuildParamsArguments args)

var paramsCompilation = await compilationService.CompileAsync(paramsInputPath, args.NoRestore);

if (ExperimentalFeatureWarningProvider.TryGetEnabledExperimentalFeatureWarningMessage(paramsCompilation.SourceFileGrouping, featureProviderFactory) is {} message)
{
logger.LogWarning(message);
}

var paramsSemanticModel = paramsCompilation.GetEntrypointSemanticModel();

//Failure scenario is ignored since a diagnostic for it would be emitted during semantic analysis
Expand Down
21 changes: 6 additions & 15 deletions src/Bicep.Cli/Commands/GenerateParametersFileCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// Licensed under the MIT License.

using Bicep.Cli.Arguments;
using Bicep.Cli.Helpers;
using Bicep.Cli.Logging;
using Bicep.Cli.Services;
using Bicep.Core.Emit;
using Bicep.Core.Emit.Options;
using Bicep.Core.Features;
using Bicep.Core.FileSystem;
using Bicep.Core.Workspaces;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;

Expand Down Expand Up @@ -42,18 +40,6 @@ public GenerateParametersFileCommand(
public async Task<int> RunAsync(GenerateParametersFileArguments args)
{
var inputPath = PathHelper.ResolvePath(args.InputFile);
var features = featureProviderFactory.GetFeatureProvider(PathHelper.FilePathToFileUrl(inputPath));
var emitterSettings = new EmitterSettings(features, BicepSourceFileKind.ParamsFile);

if (emitterSettings.EnableSymbolicNames)
{
logger.LogWarning(CliResources.SymbolicNamesDisclaimerMessage);
}

if (features.ResourceTypedParamsAndOutputsEnabled)
{
logger.LogWarning(CliResources.ResourceTypesDisclaimerMessage);
}

if (!IsBicepFile(inputPath))
{
Expand All @@ -63,6 +49,11 @@ public async Task<int> RunAsync(GenerateParametersFileArguments args)

var compilation = await compilationService.CompileAsync(inputPath, args.NoRestore);

if (ExperimentalFeatureWarningProvider.TryGetEnabledExperimentalFeatureWarningMessage(compilation.SourceFileGrouping, featureProviderFactory) is {} warningMessage)
{
logger.LogWarning(warningMessage);
}

if (diagnosticLogger.ErrorCount < 1)
{
if (args.OutputToStdOut)
Expand Down
23 changes: 6 additions & 17 deletions src/Bicep.Cli/Commands/TestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
using Bicep.Cli.Arguments;
using Bicep.Cli.Logging;
using Bicep.Cli.Services;
using Bicep.Core.Emit;
using Bicep.Core;
using Bicep.Core.Features;
using Bicep.Core.FileSystem;
using Bicep.Core.Workspaces;
using Microsoft.Extensions.Logging;

namespace Bicep.Cli.Commands
Expand Down Expand Up @@ -48,25 +47,16 @@ public async Task<int> RunAsync(TestArguments args)
{
var inputPath = PathHelper.ResolvePath(args.InputFile);
var features = featureProviderFactory.GetFeatureProvider(PathHelper.FilePathToFileUrl(inputPath));
var emitterSettings = new EmitterSettings(features, BicepSourceFileKind.BicepFile);

if (emitterSettings.EnableSymbolicNames)
{
logger.LogWarning(CliResources.SymbolicNamesDisclaimerMessage);
}

if (features.ResourceTypedParamsAndOutputsEnabled)
{
logger.LogWarning(CliResources.ResourceTypesDisclaimerMessage);
}

if(!features.TestFrameworkEnabled)
if(!features.TestFrameworkEnabled)
{
errorWriter.WriteLine("TestFrameWork not enabled");

return 1;
}

logger.LogWarning(string.Format(CliResources.ExperimentalFeaturesDisclaimerMessage, "TestFramework"));

if (IsBicepFile(inputPath))
{
diagnosticLogger.SetupFormat(args.DiagnosticsFormat);
Expand Down Expand Up @@ -107,12 +97,11 @@ private void LogResults(TestResults testResults){
{
outputWriter.WriteLine($"All {testResults.TotalEvaluations} evaluations passed!");
}
else
else
{
errorWriter.WriteLine($"Evaluation Summary: Failure!");
errorWriter.WriteLine($"Total: {testResults.TotalEvaluations} - Success: {testResults.SuccessfullEvaluations} - Skipped: {testResults.SkippedEvaluations} - Failed: {testResults.FailedEvaluations}");
}

}
}
}
25 changes: 25 additions & 0 deletions src/Bicep.Cli/Helpers/ExperimentalFeatureWarningProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Collections.Immutable;
using System.Linq;
using Bicep.Core.Features;
using Bicep.Core.Workspaces;

namespace Bicep.Cli.Helpers;

public static class ExperimentalFeatureWarningProvider
{
public static string? TryGetEnabledExperimentalFeatureWarningMessage(SourceFileGrouping sourceFileGrouping, IFeatureProviderFactory featureProviderFactory)
{
var experimentalFeaturesEnabled = sourceFileGrouping.SourceFiles
.Select(file => featureProviderFactory.GetFeatureProvider(file.FileUri))
.SelectMany(static features => features.EnabledFeatureMetadata.Where(f => f.impactsCompilation).Select(f => f.name))
.Distinct()
.ToImmutableArray();

return experimentalFeaturesEnabled.Any()
? string.Format(CliResources.ExperimentalFeaturesDisclaimerMessage, string.Join(", ", experimentalFeaturesEnabled))
: null;
}
}
18 changes: 12 additions & 6 deletions src/Bicep.Core.IntegrationTests/AssertTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,17 @@ param location string
result.Template.Should().DeepEqual(JToken.Parse(@"
{
""$schema"": ""https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#"",
""languageVersion"": ""1.10-experimental"",
""languageVersion"": ""2.1-experimental"",
""contentVersion"": ""1.0.0.0"",
""metadata"": {
""_EXPERIMENTAL_WARNING"": ""Symbolic name support in ARM is experimental, and should be enabled for testing purposes only. Do not enable this setting for any production usage, or you may be unexpectedly broken at any time!"",
""_EXPERIMENTAL_WARNING"": ""This template uses ARM features that are experimental and should be enabled for testing purposes only. Do not enable these settings for any production usage, or you may be unexpectedly broken at any time!"",
""_EXPERIMENTAL_FEATURES_ENABLED"": [
""Asserts""
],
""_generator"": {
""name"": ""bicep"",
""version"": ""dev"",
""templateHash"": ""17284967353931057894""
""templateHash"": ""1702433823331399255""
}
},
""parameters"": {
Expand Down Expand Up @@ -336,14 +339,17 @@ param location string
result.Template.Should().DeepEqual(JToken.Parse(@"
{
""$schema"": ""https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#"",
""languageVersion"": ""1.10-experimental"",
""languageVersion"": ""2.1-experimental"",
""contentVersion"": ""1.0.0.0"",
""metadata"": {
""_EXPERIMENTAL_WARNING"": ""Symbolic name support in ARM is experimental, and should be enabled for testing purposes only. Do not enable this setting for any production usage, or you may be unexpectedly broken at any time!"",
""_EXPERIMENTAL_WARNING"": ""This template uses ARM features that are experimental and should be enabled for testing purposes only. Do not enable these settings for any production usage, or you may be unexpectedly broken at any time!"",
""_EXPERIMENTAL_FEATURES_ENABLED"": [
""Asserts""
],
""_generator"": {
""name"": ""bicep"",
""version"": ""dev"",
""templateHash"": ""8822582252570074206""
""templateHash"": ""14932187055295885119""
}
},
""parameters"": {
Expand Down
8 changes: 4 additions & 4 deletions src/Bicep.Core.IntegrationTests/CompileTimeImportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Bicep.Core.IntegrationTests;
public class CompileTimeImportTests
{
private ServiceBuilder ServicesWithCompileTimeTypeImports => new ServiceBuilder()
.WithFeatureOverrides(new(TestContext, CompileTimeImportsEnabled: true, UserDefinedTypesEnabled: true));
.WithFeatureOverrides(new(TestContext, CompileTimeImportsEnabled: true));

[NotNull]
public TestContext? TestContext { get; set; }
Expand Down Expand Up @@ -147,7 +147,7 @@ public void Symbols_imported_from_ARM_json_should_have_declarations_injected_int
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"languageVersion": "1.10-experimental",
"languageVersion": "2.0",
"definitions": {
"foo": {
"metadata": {
Expand Down Expand Up @@ -203,7 +203,7 @@ public void Funky_ARM_allowedValues_survive_symbol_import_and_injection()
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"languageVersion": "1.10-experimental",
"languageVersion": "2.0",
"definitions": {
"foo": {
"metadata": {
Expand Down Expand Up @@ -497,7 +497,7 @@ public void Importing_the_same_symbol_from_json_template_under_two_separate_name
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"languageVersion": "1.10-experimental",
"languageVersion": "2.0",
"definitions": {
"foo": {
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Core.IntegrationTests/DecoratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void ParameterDecorator_MissingDeclaration_ExpectedParameterDeclaration()
{
template.Should().NotHaveValue();
diagnostics.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[] {
("BCP147", DiagnosticLevel.Error, "Expected a parameter declaration after the decorator."),
("BCP290", DiagnosticLevel.Error, "Expected a parameter or type declaration after the decorator."),
});
}
}
Expand Down
Loading

0 comments on commit 3319ec7

Please sign in to comment.