Skip to content

Commit

Permalink
Fixed generation of exp + .lib via MS Library Manager for VS2017 - #37
Browse files Browse the repository at this point in the history
Now it also includes processing through VsDevCmd & VcVarsAll initializer scripts. Use the folowing msbuild properties to override values by default:

* $(DllExportVcVarsAll)
* $(DllExportVsDevCmd

+also fixes possible problem with multiple properties that contains *Undefined* word, e.g.: *Undefined*\path1;C:\path2 ...
  • Loading branch information
3F committed Jun 13, 2017
1 parent 2b18ae5 commit 8f75a86
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 74 deletions.
3 changes: 3 additions & 0 deletions RGiesecke.DllExport.MSBuild/MSBuild/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,7 @@
<data name="AssemblyRedirection_for_0_has_not_been_setup_" xml:space="preserve">
<value>{0} has not been setup.</value>
</data>
<data name="Cannot_find_0_" xml:space="preserve">
<value>Cannot find '{0}'.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,28 @@ public string FrameworkPath
}
}

public string VsDevCmd
{
get {
return _ExportTaskImplementation.VsDevCmd;
}

set {
_ExportTaskImplementation.VsDevCmd = value;
}
}

public string VcVarsAll
{
get {
return _ExportTaskImplementation.VcVarsAll;
}

set {
_ExportTaskImplementation.VcVarsAll = value;
}
}

public string LibToolPath
{
get {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,28 @@ public string FrameworkPath
}
}

public string VsDevCmd
{
get {
return _ExportTaskImplementation.VsDevCmd;
}

set {
_ExportTaskImplementation.VsDevCmd = value;
}
}

public string VcVarsAll
{
get {
return _ExportTaskImplementation.VcVarsAll;
}

set {
_ExportTaskImplementation.VcVarsAll = value;
}
}

public string LibToolPath
{
get {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,28 @@ public string FrameworkPath
}
}

public string VsDevCmd
{
get {
return _Values.VsDevCmd;
}

set {
_Values.VsDevCmd = value;
}
}

public string VcVarsAll
{
get {
return _Values.VcVarsAll;
}

set {
_Values.VcVarsAll = value;
}
}

public string LibToolPath
{
get {
Expand Down Expand Up @@ -500,6 +522,9 @@ private static MessageImportance GetMessageImportance(int severity)

private bool ValidateInputValues()
{
VsDevCmd = ValidateCmdScript(VsDevCmd);
VcVarsAll = ValidateCmdScript(VcVarsAll);

ValidateLibToolPath();
bool flag = ValidateFrameworkPath() & ValidateSdkPath();

Expand Down Expand Up @@ -848,11 +873,26 @@ private bool ValidateSdkPath()

private static bool PropertyHasValue(string propertyValue)
{
if(!string.IsNullOrEmpty(propertyValue))
{
return !propertyValue.Contains("*Undefined*");
if(String.IsNullOrWhiteSpace(propertyValue)) {
return false;
}
return false;
//return !propertyValue.Contains("*Undefined*"); // *Undefined*\path1;C:\path2 ...
//TODO: for something like this - Path.GetFullPath("*Undefined*\\..\\path") it will return absolute path to current folder + level up instead of exception.
return !propertyValue.Trim().Equals("*Undefined*", StringComparison.InvariantCulture);
}

private string ValidateCmdScript(string data)
{
if(!PropertyHasValue(data)) {
return null;
}

string ret;
if(TrySearchToolPath(data, String.Empty, out ret)) {
return ret;
}
_ActualTask.Log.LogMessage(MessageImportance.Normal, Resources.Cannot_find_0_, data);
return null;
}

private bool ValidateLibToolPath()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions RGiesecke.DllExport/IInputValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ string MethodAttributes
set;
}

string VsDevCmd
{
get;
set;
}

string VcVarsAll
{
get;
set;
}

string LibToolPath
{
get;
Expand Down
12 changes: 12 additions & 0 deletions RGiesecke.DllExport/InputValuesCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ public string MethodAttributes
set;
}

public string VsDevCmd
{
get;
set;
}

public string VcVarsAll
{
get;
set;
}

public string LibToolPath
{
get;
Expand Down
79 changes: 65 additions & 14 deletions RGiesecke.DllExport/Parsing/ILAsm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,62 @@ private int RunCore(CpuPlatform cpu, string fileName, string ressourceParam, str

private int RunLibTool(CpuPlatform cpu, string fileName, string directory)
{
if(!InputValues.GenExpLib || String.IsNullOrWhiteSpace(InputValues.LibToolPath)) {
if(!InputValues.GenExpLib) {
return 0;
}

string libraryFileNameRoot = IlAsm.GetLibraryFileNameRoot(fileName);
string defFile = CreateDefFile(cpu, directory, libraryFileNameRoot);
string libFileRoot = IlAsm.GetLibraryFileNameRoot(fileName);
string defFile = CreateDefFile(cpu, directory, libFileRoot);
string path = Path.Combine(directory, Path.GetFileNameWithoutExtension(InputValues.OutputFileName)) + ".lib";
string cfg = $"\"/def:{defFile}\" /machine:{cpu} \"/out:{path}\"";

try
{
return RunLibToolCore(cpu, directory, defFile);
if(!String.IsNullOrWhiteSpace(InputValues.VsDevCmd))
{
int code = RunLibToolCore(
"cmd",
$"/C \"\"{InputValues.VsDevCmd}\" -no_logo -arch={(cpu == CpuPlatform.X64 ? "amd64" : "x86")} && lib.exe {cfg}\""
);

if(code != -1) {
return code;
}
}

if(!String.IsNullOrWhiteSpace(InputValues.LibToolPath))
{
string reqPath = (String.IsNullOrEmpty(InputValues.LibToolDllPath) || !Directory.Exists(InputValues.LibToolDllPath)) ? null : InputValues.LibToolDllPath;
int code = RunLibToolCore("Lib.exe", cfg, InputValues.LibToolPath, reqPath);
if(code != -1) {
return code;
}
}

if(!String.IsNullOrWhiteSpace(InputValues.VcVarsAll))
{
int code = RunLibToolCore(
"cmd",
$"/C \"\"{InputValues.VcVarsAll}\" {(cpu == CpuPlatform.X64 ? "x64" : "x86")} && lib.exe {cfg}\""
);

if(code != -1) {
return code;
}
}

int ret = RunLibToolCore("lib.exe", cfg, String.Empty, InputValues.LibToolDllPath);
if(ret != -1) {
return ret;
}

throw new Exception();
}
catch(Exception ex)
{
if(File.Exists(path)) {
File.Delete(path);
}
Notifier.Notify(1, DllExportLogginCodes.LibToolLooging, Resources.An_error_occurred_while_calling_0_1_, "lib.exe", ex.Message);
return -1;
}
Expand All @@ -205,20 +248,28 @@ private int RunLibTool(CpuPlatform cpu, string fileName, string directory)
}

[Localizable(false)]
private int RunLibToolCore(CpuPlatform cpu, string directory, string defFileName)
private int RunLibToolCore(string tool, string args, string path = "", string reqPath = null)
{
string path = Path.Combine(directory, Path.GetFileNameWithoutExtension(this.InputValues.OutputFileName)) + ".lib";
try
{
return IlParser.RunIlTool(this.InputValues.LibToolPath, "Lib.exe", string.IsNullOrEmpty(this.InputValues.LibToolDllPath) || !Directory.Exists(this.InputValues.LibToolDllPath) ? (string)null : this.InputValues.LibToolDllPath, (string)null, "LibToolPath", string.Format("\"/def:{0}\" /machine:{1} \"/out:{2}\"", (object)defFileName, (object)cpu, (object)path), DllExportLogginCodes.LibToolLooging, DllExportLogginCodes.LibToolVerboseLooging, this.Notifier, this.Timeout, (Func<string, bool>)null);
return IlParser.RunIlTool
(
path,
tool,
reqPath,
null,
"LibToolPath",
args,
DllExportLogginCodes.LibToolLooging,
DllExportLogginCodes.LibToolVerboseLooging,
Notifier,
Timeout,
null
);
}
catch
{
if(File.Exists(path))
{
File.Delete(path);
}
throw;
catch(Exception ex) {
Notifier.Notify(-1, DllExportLogginCodes.LibToolLooging, Resources.An_error_occurred_while_calling_0_1_, $" {tool} {args} ", ex.Message);
return -1;
}
}

Expand Down
5 changes: 1 addition & 4 deletions RGiesecke.DllExport/Parsing/IlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,7 @@ private static string GetExePath(string toolFileName, string installPath, string
path = Path.Combine(Path.Combine(Path.GetFullPath(installPath), "Bin"), toolFileName);
}
}
else if(!string.IsNullOrEmpty((Settings.Default[settingsName] as string).NullSafeTrim()))
{
path = Settings.Default.ILDasmPath;
}

if(string.IsNullOrEmpty(path) || !File.Exists(path))
{
path = toolFileName;
Expand Down
48 changes: 0 additions & 48 deletions RGiesecke.DllExport/Properties/Settings.Designer.cs

This file was deleted.

5 changes: 3 additions & 2 deletions RGiesecke.DllExport/RGiesecke.DllExport.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
<Compile Include="Parsing\Actions\ParserStateActionAttribute.cs" />
<Compile Include="Parsing\Actions\ParserStateValues.cs" />
<Compile Include="Properties\Resources.Designer.cs" />
<Compile Include="Properties\Settings.Designer.cs" />
<Compile Include="DllExportVersion.cs" />
<Compile Include="IDllExportNotifier.cs" />
<Compile Include="CpuPlatform.cs" />
Expand All @@ -113,7 +112,9 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Parsing\Regexes.resx" />
<EmbeddedResource Include="Properties\Resources.resx" />
<EmbeddedResource Include="Properties\Resources.resx">
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="key.snk" />
Expand Down
Loading

0 comments on commit 8f75a86

Please sign in to comment.