Skip to content

Commit

Permalink
Avoid doing changes to projects that may not want to use Conan (#256)
Browse files Browse the repository at this point in the history
* avoid doing changes if not conandata in project

* minor changes
  • Loading branch information
czoido authored Nov 19, 2024
1 parent f184506 commit 864ffa7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
23 changes: 19 additions & 4 deletions BuildEventsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,22 @@ public BuildEventsHandler(DTE dte)
_buildEvents.OnBuildProjConfigDone += OnBuildProjConfigDone;
}

private bool IsConanEnabledForProject(string projectName)
{
ThreadHelper.ThrowIfNotOnUIThread();
var project = ProjectConfigurationManager.GetProjectByName(_dte, projectName);
return project != null && ProjectConfigurationManager.conandataFileExists(project);
}

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

if (!IsConanEnabledForProject(Project))
{
return;
}

Project invokedProject = ProjectConfigurationManager.GetProjectByName(_dte, Project);
_profiles_manager.GenerateProfilesForProject(invokedProject);

Expand All @@ -40,8 +51,12 @@ private void OnBuildProjConfigBegin(string Project, string ProjectConfig, string
private void OnBuildProjConfigDone(string Project, string ProjectConfig, string Platform, string SolutionConfig, bool Success)
{
ThreadHelper.ThrowIfNotOnUIThread();
var message = "OnBuildProjConfigDone";
System.Diagnostics.Debug.WriteLine(message);

if (!IsConanEnabledForProject(Project))
{
return;
}

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
Expand Down
5 changes: 3 additions & 2 deletions ProjectConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ProjectConfigurationManager()
{
}

static private bool conandataFileExists(Project project)
public static bool conandataFileExists(Project project)
{
ThreadHelper.ThrowIfNotOnUIThread();
string projectDirectory = System.IO.Path.GetDirectoryName(project.FullName);
Expand Down Expand Up @@ -214,14 +214,15 @@ private static async Task SaveConanPrebuildEventAsync(Project project, VCConfigu
public static async Task SaveConanPrebuildEventsAllConfigAsync(Project project)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
await GenerateConanInstallScriptAsync(project); // all the config share the same script

if (!conandataFileExists(project))
{
System.Diagnostics.Debug.WriteLine("conandata.yml not found. Skipping Conan PreBuildEvent.");
return;
}

await GenerateConanInstallScriptAsync(project); // all the config share the same script

VCProject vcProject = project.Object as VCProject;
foreach (VCConfiguration vcConfig in (IEnumerable)vcProject.Configurations)
{
Expand Down

0 comments on commit 864ffa7

Please sign in to comment.