Skip to content

Commit

Permalink
Added batch installer, Based on hMSBuild logic and includes GetNuTool…
Browse files Browse the repository at this point in the history
… core - #38
  • Loading branch information
3F committed Jul 30, 2017
1 parent 536bfbc commit 6641d7e
Show file tree
Hide file tree
Showing 20 changed files with 955 additions and 74 deletions.
135 changes: 130 additions & 5 deletions .vssbe

Large diffs are not rendered by default.

38 changes: 28 additions & 10 deletions Wizard/DllExportCfgTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using net.r_eg.DllExport.Wizard.Extensions;
using net.r_eg.MvsSln.Log;

namespace net.r_eg.DllExport.Wizard
Expand All @@ -33,54 +34,70 @@ public class DllExportCfgTask: Task, ITask, IWizardConfig
{
private object synch = new object();

/// <summary>
/// Optional root path of user paths.
/// Affects on wSlnFile, wSlnDir, wPkgPath.
/// </summary>
public string RootPath
{
get => _rootPath;
set => _rootPath = value.DirectoryPathFormat();
}
private string _rootPath;

/// <summary>
/// Path to directory with .sln files to be processed.
/// </summary>
[Required]
public string SlnDir
{
get;
set;
get => _slnDir;
set => _slnDir = value.DirectoryPathFormat(RootPath);
}
private string _slnDir;

/// <summary>
/// Optional predefined .sln file to process via the restore operations etc.
/// </summary>
public string SlnFile
{
get;
set;
get => _slnFile;
set => _slnFile = value.FilePathFormat(RootPath);
}
private string _slnFile;

/// <summary>
/// Root path of the DllExport package.
/// </summary>
[Required]
public string PkgPath
{
get;
set;
get => _pkgPath;
set => _pkgPath = value.DirectoryPathFormat(RootPath);
}
private string _pkgPath;

/// <summary>
/// Relative path from PkgPath to DllExport meta library.
/// </summary>
[Required]
public string MetaLib
{
get;
set;
get => _metaLib;
set => _metaLib = value.FilePathFormat();
}
private string _metaLib;

/// <summary>
/// Path to .target file of the DllExport.
/// </summary>
[Required]
public string DxpTarget
{
get;
set;
get => _dxpTarget;
set => _dxpTarget = value.FilePathFormat();
}
private string _dxpTarget;

/// <summary>
/// Raw type of operation via ActionType.
Expand Down Expand Up @@ -146,6 +163,7 @@ internal bool TryExecute(IExecutor exec, Action act)
LSender.Send(this, $"PkgPath: '{PkgPath}'", Message.Level.Warn);
LSender.Send(this, $"MetaLib: '{MetaLib}'", Message.Level.Warn);
LSender.Send(this, $"DxpTarget: '{DxpTarget}'", Message.Level.Warn);
LSender.Send(this, $"RootPath: '{RootPath}'", Message.Level.Warn);
LSender.Send(this, $"Action: '{Type}'", Message.Level.Warn);
#if DEBUG
LSender.Send(this, $"Stack trace: {ex.StackTrace}", Message.Level.Error);
Expand Down
22 changes: 6 additions & 16 deletions Wizard/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

namespace net.r_eg.DllExport.Wizard
{
public class Executor: IExecutor, IDisposable
public class Executor: IExecutor, IConfigInitializer, IDisposable
{
protected Dictionary<string, Sln> solutions = new Dictionary<string, Sln>();

Expand Down Expand Up @@ -75,7 +75,7 @@ public IEnumerable<string> SlnFiles
/// <returns></returns>
public IEnumerable<IProject> ProjectsBy(string sln)
{
return GetEnv(sln)?.Projects?.Select(p => new Project(p, GetUserConfig(p)));
return GetEnv(sln)?.Projects?.Select(p => new Project(p, this));
}

/// <summary>
Expand All @@ -85,7 +85,7 @@ public IEnumerable<IProject> ProjectsBy(string sln)
/// <returns></returns>
public IEnumerable<IProject> UniqueProjectsBy(string sln)
{
return GetEnv(sln)?.UniqueByGuidProjects?.Select(p => new Project(p, GetUserConfig(p)));
return GetEnv(sln)?.UniqueByGuidProjects?.Select(p => new Project(p, this));
}

/// <summary>
Expand All @@ -103,15 +103,14 @@ public void Configure()
{
if(Config.Type == ActionType.Configure)
{
using(var frm = new UI.ConfiguratorForm(this)) {
frm.ShowDialog();
}
UI.App.RunSTA(new UI.ConfiguratorForm(this));
return;
}

if(Config.Type == ActionType.Restore)
{
var sln = String.IsNullOrWhiteSpace(Config.SlnFile) ? SlnFiles.FirstOrDefault() : Config.SlnFile;
var sln = String.IsNullOrWhiteSpace(Config.SlnFile) ?
SlnFiles?.FirstOrDefault() : Config.SlnFile;
if(sln == null)
{
throw new ArgumentException(
Expand All @@ -134,15 +133,6 @@ public Executor(IWizardConfig cfg)
Config = cfg ?? throw new ArgumentNullException(nameof(cfg));
}

protected virtual IUserConfig GetUserConfig(IXProject project)
{
return new UserConfig(Config, project) {
NSBuffer = DDNS.NSBuffer,
DDNS = DDNS,
Log = Log,
};
}

protected IEnvironment GetEnv(string file)
{
if(String.IsNullOrWhiteSpace(file)) {
Expand Down
52 changes: 52 additions & 0 deletions Wizard/Extensions/StringExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

using System;
using System.IO;

namespace net.r_eg.DllExport.Wizard.Extensions
{
Expand Down Expand Up @@ -70,5 +71,56 @@ public static int ToInteger(this string value)

return Int32.Parse(value);
}

/// <summary>
/// To open value from double quotes.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string OpenDoubleQuotes(this string value)
{
if(String.IsNullOrWhiteSpace(value)) {
return value;
}

// leave trailing and leading whitespaces inside double quotes
return value.Trim().Trim(new[] { '"' });
}

/// <summary>
/// Formatting of the path to directory.
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static string DirectoryPathFormat(this string path, string root = null)
{
return CombineRootPath(
MvsSln.Extensions.StringExtension.DirectoryPathFormat(OpenDoubleQuotes(path)),
root
);
}

/// <summary>
/// Formatting file path.
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static string FilePathFormat(this string path, string root = null)
{
return CombineRootPath(OpenDoubleQuotes(path)?.Trim(), root);
}

public static string CombineRootPath(string path, string root)
{
if(String.IsNullOrWhiteSpace(path) || Path.IsPathRooted(path)) {
return path;
}

if(String.IsNullOrWhiteSpace(root)) {
return path;
}

return Path.Combine(root, path);
}
}
}
47 changes: 47 additions & 0 deletions Wizard/IConfigInitializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 Denis Kuzmin < entry.reg@gmail.com > :: github.com/3F
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using net.r_eg.DllExport.NSBin;
using net.r_eg.MvsSln.Log;

namespace net.r_eg.DllExport.Wizard
{
public interface IConfigInitializer
{
/// <summary>
/// Access to wizard configuration.
/// </summary>
IWizardConfig Config { get; }

/// <summary>
/// ddNS feature core.
/// </summary>
IDDNS DDNS { get; }

/// <summary>
/// Access to logger.
/// </summary>
ISender Log { get; }
}
}
3 changes: 2 additions & 1 deletion Wizard/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public enum Platform
Default,
x86,
x64,
AnyCPU
AnyCPU,
x86x64 = AnyCPU,
}
}
24 changes: 20 additions & 4 deletions Wizard/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ public bool Configure(ActionType type)
}

/// <param name="xproject"></param>
/// <param name="cfg"></param>
public Project(IXProject xproject, IUserConfig cfg)
/// <param name="init"></param>
public Project(IXProject xproject, IConfigInitializer init)
{
XProject = xproject ?? throw new ArgumentNullException(nameof(xproject));
Config = cfg ?? throw new ArgumentNullException(nameof(cfg));
Config = GetUserConfig(xproject, init);

Config.AddTopNamespace(ProjectNamespace);

Expand All @@ -186,6 +186,22 @@ public Project(IXProject xproject, IUserConfig cfg)
);
}

protected IUserConfig GetUserConfig(IXProject project, IConfigInitializer cfg)
{
if(Installed) {
return new UserConfig(cfg, project);
}

return new UserConfig(cfg)
{
UseCecil = true,
Platform = Platform.x86x64,
Compiler = new CompilerCfg() {
ordinalsBase = 1
},
};
}

/// <summary>
/// Saves the project to the file system, if modified.
/// </summary>
Expand Down Expand Up @@ -336,7 +352,7 @@ protected void RemoveProperties(params string[] names)
}
}

protected virtual string GetProperty(string name)
protected string GetProperty(string name)
{
return XProject?.GetProperty(name).evaluatedValue;
}
Expand Down
Loading

0 comments on commit 6641d7e

Please sign in to comment.