Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Look for matching Conan profile in a config file for the running VS configuration #100

Merged
merged 9 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Conan.VisualStudio.Core/Conan.VisualStudio.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
Expand Down
1 change: 1 addition & 0 deletions Conan.VisualStudio.Core/ConanConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace Conan.VisualStudio.Core
{
public class ConanConfiguration
{
public string VSName { get; set; }
public string Architecture { get; set; }
public string BuildType { get; set; }
public string CompilerToolset { get; set; }
Expand Down
15 changes: 15 additions & 0 deletions Conan.VisualStudio.Core/ConanPathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ public static string GetNearestConanfilePath(string path)
return path;
}

/// <summary>
/// Searches for conan.config.json in the directory or any of its' parent paths.
/// </summary>
/// <returns>Path to the nearest conan.config.json file</returns>
public static string GetNearestConanConfig(string path)
{
while (path != null)
{
string conan_config = Path.Combine(path, "conan.config.json");
if (File.Exists(conan_config)) return conan_config;
path = Directory.GetParent(path)?.FullName;
}
return path;
}

public static async Task<string> GetNearestConanfilePathAsync(string path) => await Task.Run(() =>
{
return GetNearestConanfilePath(path);
Expand Down
22 changes: 21 additions & 1 deletion Conan.VisualStudio.Core/ConanProject.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json.Linq;
using System;

namespace Conan.VisualStudio.Core
{
public class ConanProject
{
public string Path { get; set; }

public string ConfigFile { get; set; }
public List<ConanConfiguration> Configurations { get; } = new List<ConanConfiguration>();

public string getProfile(ConanConfiguration configuration)
{
if (!File.Exists(ConfigFile)) return null;
try
{
JObject jObject = JObject.Parse(File.ReadAllText(ConfigFile));
var configs = jObject["configurations"].ToObject<Dictionary<string, string>>();
configs.TryGetValue(configuration.VSName, out string conanProfile);
return conanProfile;
jgsogo marked this conversation as resolved.
Show resolved Hide resolved
}
catch (Exception)
{
// TODO: Check the error and log to user
return null;
jgsogo marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
12 changes: 11 additions & 1 deletion Conan.VisualStudio.Core/ConanRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@ public Task<Process> Install(ConanProject project, ConanConfiguration configurat
string ProcessArgument(string name, string value) => $"-s {name}={Escape(value)}";

var arguments = string.Empty;
if (_conanSettings != null)

string profile = project.getProfile(configuration);
if (profile != null)
{
string generatorName = generator.ToString();
arguments = $"install {Escape(project.Path)} " +
$"-g {generatorName} " +
$"--install-folder {Escape(configuration.InstallPath)} " +
$"--profile {Escape(profile)}";
jgsogo marked this conversation as resolved.
Show resolved Hide resolved
}
else if (_conanSettings != null)
{
var installConfig = _conanSettings.ConanCommands.FirstOrDefault(c => c.Name.Equals("install"));
arguments = installConfig.Args;
Expand Down
1 change: 1 addition & 0 deletions Conan.VisualStudio.Core/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net461" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
</packages>
4 changes: 3 additions & 1 deletion Conan.VisualStudio/Services/SolutionEventsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ private async System.Threading.Tasks.Task InspectAsync(EnvDTE.Project project)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

string projectConanConfig = ConanPathHelper.GetNearestConanConfig(project.FileName);
var conanProject = new ConanProject
{
Path = project.FileName
Path = project.FileName,
ConfigFile = projectConanConfig
};

await TaskScheduler.Default;
Expand Down
4 changes: 4 additions & 0 deletions Conan.VisualStudio/Services/VcProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ public ConanProject ExtractConanProject(VCProject vcProject, ISettingsService se
{
return null;
}

string projectConanConfig = ConanPathHelper.GetNearestConanConfig(vcProject.ProjectDirectory);
var project = new ConanProject
{
Path = projectPath,
ConfigFile = projectConanConfig
};

if (settingsService != null && settingsService.GetConanInstallOnlyActiveConfiguration())
Expand Down Expand Up @@ -150,6 +153,7 @@ private static ConanConfiguration ExtractConanConfiguration(ISettingsService set

return new ConanConfiguration
{
VSName = configuration.Name,
Architecture = GetArchitecture(configuration.Platform.Name),
BuildType = GetBuildType(configuration.ConfigurationName),
CompilerToolset = toolset,
Expand Down