-
Notifications
You must be signed in to change notification settings - Fork 756
/
BicepCompiler.cs
65 lines (59 loc) · 2.77 KB
/
BicepCompiler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Threading.Tasks;
using Bicep.Core.Analyzers.Interfaces;
using Bicep.Core.Analyzers.Linter.ApiVersions;
using Bicep.Core.Configuration;
using Bicep.Core.Features;
using Bicep.Core.FileSystem;
using Bicep.Core.Registry;
using Bicep.Core.Semantics;
using Bicep.Core.Semantics.Namespaces;
using Bicep.Core.Workspaces;
namespace Bicep.Core;
public class BicepCompiler
{
private readonly IFeatureProviderFactory featureProviderFactory;
private readonly INamespaceProvider namespaceProvider;
private readonly IConfigurationManager configurationManager;
private readonly IApiVersionProviderFactory apiVersionProviderFactory;
private readonly IBicepAnalyzer bicepAnalyzer;
private readonly IFileResolver fileResolver;
private readonly IModuleDispatcher moduleDispatcher;
public BicepCompiler(
IFeatureProviderFactory featureProviderFactory,
INamespaceProvider namespaceProvider,
IConfigurationManager configurationManager,
IApiVersionProviderFactory apiVersionProviderFactory,
IBicepAnalyzer bicepAnalyzer,
IFileResolver fileResolver,
IModuleDispatcher moduleDispatcher)
{
this.featureProviderFactory = featureProviderFactory;
this.namespaceProvider = namespaceProvider;
this.configurationManager = configurationManager;
this.apiVersionProviderFactory = apiVersionProviderFactory;
this.bicepAnalyzer = bicepAnalyzer;
this.fileResolver = fileResolver;
this.moduleDispatcher = moduleDispatcher;
}
public async Task<Compilation> CreateCompilation(Uri bicepUri, bool skipRestore = false, IReadOnlyWorkspace? workspace = null)
{
workspace ??= new Workspace();
var sourceFileGrouping = SourceFileGroupingBuilder.Build(fileResolver, moduleDispatcher, workspace, bicepUri, false);
if (!skipRestore)
{
// module references in the file may be malformed
// however we still want to surface as many errors as we can for the module refs that are valid
// so we will try to restore modules with valid refs and skip everything else
// (the diagnostics will be collected during compilation)
if (await moduleDispatcher.RestoreModules(moduleDispatcher.GetValidModuleReferences(sourceFileGrouping.GetModulesToRestore())))
{
// modules had to be restored - recompile
sourceFileGrouping = SourceFileGroupingBuilder.Rebuild(moduleDispatcher, workspace, sourceFileGrouping);
}
}
return new Compilation(featureProviderFactory, namespaceProvider, sourceFileGrouping, configurationManager, apiVersionProviderFactory, bicepAnalyzer);
}
}