-
Notifications
You must be signed in to change notification settings - Fork 34
/
BuildEventsHandler.cs
67 lines (59 loc) · 2.96 KB
/
BuildEventsHandler.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
66
67
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.VCProjectEngine;
namespace conan_vs_extension
{
public class BuildEventsHandler
{
private readonly DTE _dte;
private readonly BuildEvents _buildEvents;
private ConanProfilesManager _profiles_manager;
public BuildEventsHandler(DTE dte)
{
ThreadHelper.ThrowIfNotOnUIThread();
_dte = dte;
_buildEvents = _dte.Events.BuildEvents;
_profiles_manager = new ConanProfilesManager();
// Subscribe to compilation events
_buildEvents.OnBuildDone += OnBuildDone;
_buildEvents.OnBuildProjConfigBegin += OnBuildProjConfigBegin;
_buildEvents.OnBuildProjConfigDone += OnBuildProjConfigDone;
}
private void OnBuildProjConfigBegin(string Project, string ProjectConfig, string Platform, string SolutionConfig)
{
ThreadHelper.ThrowIfNotOnUIThread();
// here we generate profiles for all projects but we probably should only generate profiles for
// the project marked as startup project
Project invokedProject = ProjectConfigurationManager.GetProjectByName(_dte, Project);
_profiles_manager.GenerateProfilesForProject(invokedProject);
// We always overrwrite the script for the prebuild event
// the ps1 is always overwritten but the event is only added if no conan_install.ps1 is found
// in the prebuild events
_ = ProjectConfigurationManager.SaveConanPrebuildEventsAllConfigAsync(invokedProject);
}
private void OnBuildProjConfigDone(string Project, string ProjectConfig, string Platform, string SolutionConfig, bool Success)
{
ThreadHelper.ThrowIfNotOnUIThread();
var message = "OnBuildProjConfigDone";
System.Diagnostics.Debug.WriteLine(message);
Project invokedProject = ProjectConfigurationManager.GetProjectByName(_dte, Project);
VCConfiguration config = ProjectConfigurationManager.GetVCConfig(invokedProject, ProjectConfig, Platform);
// FIXME: the problem with this is that the first time you build
// the build is started before this step finishes
// maybe we can inject the dependency to the project via a prebuild event?
// with a script?
_ = ProjectConfigurationManager.InjectConanDepsAsync(invokedProject, config);
}
private void OnBuildDone(vsBuildScope Scope, vsBuildAction Action)
{
var message = "OnBuildDone";
System.Diagnostics.Debug.WriteLine(message);
}
public void Dispose()
{
ThreadHelper.ThrowIfNotOnUIThread();
_buildEvents.OnBuildDone -= OnBuildDone;
_buildEvents.OnBuildProjConfigBegin -= OnBuildProjConfigBegin;
_buildEvents.OnBuildProjConfigDone -= OnBuildProjConfigDone; }
}
}