FS-10725: [Build-System] Add DownloadPackageTask in order to use in props instead of using legacy util.vbs within projects. Get rid of lib v8 download project in favor of props on windows.

This commit is contained in:
Andrey Volk 2017-10-17 21:40:08 +03:00
parent a6417d06c2
commit 9c4fc2af12
6 changed files with 316 additions and 109 deletions

View File

@ -564,8 +564,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcbt", "libs\win32\libcbt
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_cielab_luts", "libs\spandsp\src\msvc\make_cielab_luts.2015.vcxproj", "{85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Download V8", "libs\win32\Download V8.2015.vcxproj", "{13077E43-E5DF-4EF6-9EB1-2A0B22E8DFAF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libv8", "libs\win32\v8\libv8.2015.vcxproj", "{AB03E82B-48B1-4374-B32A-A1AF83DDC6C2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Download OPUS", "libs\win32\Download OPUS.2015.vcxproj", "{092124C9-09ED-43C7-BD6D-4AE5D6B3C547}"
@ -2528,17 +2526,6 @@ Global
{85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|Win32.Build.0 = All|Win32
{85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|x64.ActiveCfg = All|Win32
{85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|x64.Build.0 = All|Win32
{13077E43-E5DF-4EF6-9EB1-2A0B22E8DFAF}.All|Win32.ActiveCfg = Release|Win32
{13077E43-E5DF-4EF6-9EB1-2A0B22E8DFAF}.All|Win32.Build.0 = Release|Win32
{13077E43-E5DF-4EF6-9EB1-2A0B22E8DFAF}.All|x64.ActiveCfg = Release|Win32
{13077E43-E5DF-4EF6-9EB1-2A0B22E8DFAF}.Debug|Win32.ActiveCfg = Debug|Win32
{13077E43-E5DF-4EF6-9EB1-2A0B22E8DFAF}.Debug|Win32.Build.0 = Debug|Win32
{13077E43-E5DF-4EF6-9EB1-2A0B22E8DFAF}.Debug|x64.ActiveCfg = Debug|Win32
{13077E43-E5DF-4EF6-9EB1-2A0B22E8DFAF}.Debug|x64.Build.0 = Debug|Win32
{13077E43-E5DF-4EF6-9EB1-2A0B22E8DFAF}.Release|Win32.ActiveCfg = Release|Win32
{13077E43-E5DF-4EF6-9EB1-2A0B22E8DFAF}.Release|Win32.Build.0 = Release|Win32
{13077E43-E5DF-4EF6-9EB1-2A0B22E8DFAF}.Release|x64.ActiveCfg = Release|Win32
{13077E43-E5DF-4EF6-9EB1-2A0B22E8DFAF}.Release|x64.Build.0 = Release|Win32
{AB03E82B-48B1-4374-B32A-A1AF83DDC6C2}.All|Win32.ActiveCfg = Debug|x64
{AB03E82B-48B1-4374-B32A-A1AF83DDC6C2}.All|x64.ActiveCfg = Debug|x64
{AB03E82B-48B1-4374-B32A-A1AF83DDC6C2}.All|x64.Build.0 = Debug|x64
@ -3228,7 +3215,6 @@ Global
{2386B892-35F5-46CF-A0F0-10394D2FBF9B} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B}
{77BC1DD2-C9A1-44D7-BFFA-1320370CACB9} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B}
{85F0CF8C-C7AB-48F6-BA19-CC94CF87F981} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B}
{13077E43-E5DF-4EF6-9EB1-2A0B22E8DFAF} = {C120A020-773F-4EA3-923F-B67AF28B750D}
{AB03E82B-48B1-4374-B32A-A1AF83DDC6C2} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B}
{092124C9-09ED-43C7-BD6D-4AE5D6B3C547} = {C120A020-773F-4EA3-923F-B67AF28B750D}
{ED2CA8B5-8E91-4296-A120-02BB0B674652} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B}

View File

@ -1,84 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>Download V8</ProjectName>
<ProjectGuid>{13077E43-E5DF-4EF6-9EB1-2A0B22E8DFAF}</ProjectGuid>
<RootNamespace>Download V8</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Utility</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Utility</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(SolutionDir)\w32\extdll.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\w32\v8-version.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\w32\v8-version.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(PlatformName)\V8\$(Configuration)\</IntDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(PlatformName)\V8\$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<BuildLog>
<Path>$(IntDir)BuildLog $(ProjectName).htm</Path>
</BuildLog>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<BuildLog>
<Path>$(IntDir)BuildLog $(ProjectName).htm</Path>
</BuildLog>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<CustomBuild Include="cleancount">
<FileType>Document</FileType>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Downloading V8.</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">if not exist "$(ProjectDir)..\v8-$(V8Version)" cscript /nologo "$(ProjectDir)util.vbs" GetUnzip http://files.freeswitch.org/downloads/libs/v8-$(V8Version).tar.bz2 "$(ProjectDir).."
if not exist "$(ProjectDir)..\v8-$(V8Version)\third_party\cygwin" cscript /nologo "$(ProjectDir)util.vbs" GetUnzip http://files.freeswitch.org/downloads/libs/v8-$(V8Version)-win.tar.bz2 "$(ProjectDir).."
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir)..\v8-$(V8Version);%(Outputs)</Outputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Downloading V8.</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">if not exist "$(ProjectDir)..\v8-$(V8Version)" cscript /nologo "$(ProjectDir)util.vbs" GetUnzip http://files.freeswitch.org/downloads/libs/v8-$(V8Version).tar.bz2 "$(ProjectDir).."
if not exist "$(ProjectDir)..\v8-$(V8Version)\third_party\cygwin" cscript /nologo "$(ProjectDir)util.vbs" GetUnzip http://files.freeswitch.org/downloads/libs/v8-$(V8Version)-win.tar.bz2 "$(ProjectDir).."
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir)..\v8-$(V8Version);%(Outputs)</Outputs>
</CustomBuild>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -51,24 +51,21 @@
<CLRSupport>false</CLRSupport>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(SolutionDir)\w32\v8.props" />
<Import Project="$(SolutionDir)\w32\extdll.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\w32\v8-version.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\w32\v8-version.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\w32\v8-version.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\w32\v8-version.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
@ -141,12 +138,6 @@
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir)..\..\v8-$(V8Version);%(Outputs)</Outputs>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Download V8.2015.vcxproj">
<Project>{13077E43-E5DF-4EF6-9EB1-2A0B22E8DFAF}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

266
w32/downloadpackage.task Normal file
View File

@ -0,0 +1,266 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets">
<Import Project="basedir.props" Condition=" '$(BaseDirImported)' == ''"/>
</ImportGroup>
<UsingTask TaskName="DownloadPackageTask"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
<ParameterGroup>
<package Required="true" />
<expectfileordirectory Required="true" />
<outputfolder />
<outputfilename />
<extractto />
</ParameterGroup>
<Task>
<Reference Include="Microsoft.Build" />
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Utilities.Core" />
<Code Type="Class" Language="cs">
<![CDATA[
using System;
using System.IO;
using System.Threading;
using Microsoft.Build.Framework;
using System.Reflection;
using Microsoft.Build.Execution;
using System.Net;
using System.ComponentModel;
using System.Diagnostics;
public class DownloadPackageTask : Microsoft.Build.Utilities.Task, Microsoft.Build.Framework.ICancelableTask
{
public class State
{
public string filename;
public int progress;
}
protected ManualResetEvent TaskCanceled { get; private set; }
public void Cancel()
{
TaskCanceled.Set();
}
private string basedir;
[Required]
public string package { get; set; }
[Required]
public string expectfileordirectory { get; set; }
public string outputfolder { get; set; }
public string outputfilename { get; set; }
public string extractto { get; set; }
internal static bool FileOrDirectoryExists(string name)
{
return (Directory.Exists(name) || File.Exists(name));
}
public override bool Execute()
{
basedir = Path.GetFullPath(@"$(BaseDir)");
TaskCanceled = new ManualResetEvent(false);
Log.LogMessage(MessageImportance.High,
"Checking for package \"" + package + "\".");
//Log.LogMessage(MessageImportance.High,
// "BaseDir \"" + basedir + "\"");
//Log.LogMessage(MessageImportance.High,
// "expectfileordirectory \"" + expectfileordirectory + "\"");
string librarypath = Path.Combine(basedir, "libs");
Mutex m = new Mutex(false, Path.Combine(librarypath, package).Replace(":", "/").Replace("\\","/"));
m.WaitOne();
if (FileOrDirectoryExists(expectfileordirectory))
{
Log.LogMessage(MessageImportance.High,
"Package \"" + package + "\" exists. Do nothing.");
}
else
{
Log.LogMessage(MessageImportance.High,
"Start downloading package \"" + package + "\".");
using (var client = new System.Net.WebClient())
{
Uri uri = new Uri(package);
string urifilename = Path.GetFileName(uri.LocalPath);
string output = Path.Combine(outputfolder ?? librarypath, (outputfilename ?? urifilename));
//if (!File.Exists(output)) // Uncomment to skip download if exists
{
var syncObject = new State
{
filename = urifilename,
progress = -1
};
lock (syncObject)
{
client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted);
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);
client.DownloadFileAsync(uri, output, syncObject);
while (!Monitor.Wait(syncObject, 1000))
{
if (TaskCanceled.WaitOne(0))
{
client.CancelAsync();
Monitor.Wait(syncObject);
if (File.Exists(output))
{
Log.LogMessage(MessageImportance.High,
"Deleting incomplete file " + output + " for package \"" + package + "\".");
File.Delete(output);
}
Log.LogMessage(MessageImportance.High,
"Downloading canceled for package \"" + package + "\".");
break;
}
}
}
}
if (File.Exists(output))
{
// Successful download.
if (Path.GetExtension(output) != ".exe")
{
Extract(output);
string filename = Path.Combine(Path.GetDirectoryName(output), Path.GetFileNameWithoutExtension(output));
Log.LogMessage(MessageImportance.High,
"Filename \"" + filename + "\".");
if (File.Exists(filename))
{
Extract(filename);
File.Delete(filename);
}
}
}
}
if (!TaskCanceled.WaitOne(0))
{
Log.LogMessage(MessageImportance.High,
"Downloading finished for package \"" + package + "\".");
}
}
m.ReleaseMutex();
return true;
}
private void Extract(string filename)
{
string extracttofolder = Path.GetFullPath((extractto ?? Path.GetDirectoryName(filename)) + "/");
string arctool = Path.Combine(new string[] { basedir, "libs", "win32", "7za1701.exe" });
string args = " x \"" + filename + "\" -y -o\"" + extracttofolder + "\"";
Log.LogMessage(MessageImportance.High,
"arctool : " + arctool);
Log.LogMessage(MessageImportance.High,
"args : " + args);
Log.LogMessage(MessageImportance.High,
"WorkingDirectory : " + Path.GetDirectoryName(arctool));
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = arctool,
Arguments = args,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true,
WorkingDirectory = Path.GetDirectoryName(arctool)
}
};
proc.Start();
while (!proc.StandardOutput.EndOfStream)
{
string line = proc.StandardOutput.ReadLine();
Log.LogMessage(MessageImportance.High,
Path.GetFileName(filename) + " : " + line);
if (TaskCanceled.WaitOne(0))
{
proc.Kill();
break;
}
}
proc.WaitForExit();
}
private void DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
lock (e.UserState)
{
//releases blocked thread
Monitor.Pulse(e.UserState);
}
}
private string humanSize(double len)
{
string[] sizes = { "B", "KB", "MB", "GB", "TB" };
int order = 0;
while (len >= 1024 && order < sizes.Length - 1)
{
order++;
len = len / 1024;
}
return String.Format("{0:0.##} {1}", len, sizes[order]);
}
private void DownloadProgressCallback(object sender, DownloadProgressChangedEventArgs e)
{
if (((State)e.UserState).progress < e.ProgressPercentage)
{
((State)e.UserState).progress = e.ProgressPercentage;
// Displays the transfer progress.
Log.LogMessage(MessageImportance.High, ((State)e.UserState).filename + " : downloaded " + humanSize(e.BytesReceived) + " of " + humanSize(e.TotalBytesToReceive) + " " + e.ProgressPercentage + " % complete...");
}
}
}
]]>
</Code>
</Task>
</UsingTask>
<Target Name="7za" BeforeTargets="Build">
<DownloadPackageTask
package="http://files.freeswitch.org/downloads/win32/7za1701.exe"
expectfileordirectory="$(BaseDir)libs/win32/7za1701.exe"
outputfolder="$(BaseDir)libs/win32/"
outputfilename="7za1701.exe"
extractto=""
/>
</Target>
<PropertyGroup>
<downloadpackagetask_Imported>true</downloadpackagetask_Imported>
</PropertyGroup>
</Project>

View File

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<ImportGroup Label="PropertySheets">
<Import Project="basedir.props" Condition=" '$(BaseDirImported)' == ''"/>
</ImportGroup>
<PropertyGroup Label="UserMacros">
<V8Version>5.6.326</V8Version>
</PropertyGroup>

View File

@ -3,7 +3,53 @@
<ImportGroup Label="PropertySheets">
<Import Project="curl.props" Condition=" '$(CurlPropsImported)' == '' "/>
<Import Project="v8-version.props" Condition=" '$(V8VersionImported)' == '' "/>
<Import Project="downloadpackage.task" Condition=" '$(downloadpackagetask_Imported)' == '' " />
</ImportGroup>
<PropertyGroup Label="UserMacros">
<V8libDir>$(BaseDir)libs\v8-$(V8Version)</V8libDir>
</PropertyGroup>
<!--
Download Target.
Name must be unique.
By design, targets are executed only once per project.
Usage:
package: URI
expectfileordirectory: Skips the download and extraction if exists
outputfolder: Folder to store a downloaded file.
By default "$(BaseDir)libs", if empty
outputfilename: If not empty, overrides filename from URI.
.exe files don't get extracted
extractto: Folder to extract an archive to
-->
<Target Name="v8libTarget" BeforeTargets="CustomBuild" DependsOnTargets="7za">
<DownloadPackageTask
package="http://files.freeswitch.org/downloads/libs/v8-$(V8Version).tar.bz2"
expectfileordirectory="$(V8libDir)\include\v8.h"
outputfolder=""
outputfilename=""
extractto="$(BaseDir)libs"
/>
</Target>
<Target Name="v8libwinTarget" BeforeTargets="CustomBuild" DependsOnTargets="7za">
<DownloadPackageTask
package="http://files.freeswitch.org/downloads/libs/v8-$(V8Version)-win.tar.bz2"
expectfileordirectory="$(V8libDir)\third_party\cygwin"
outputfolder=""
outputfilename=""
extractto="$(BaseDir)libs"
/>
</Target>
<ItemDefinitionGroup>
<ClCompile>
<WarningLevel>Level3</WarningLevel>