2016-03-15 16:41:18 -07:00
using System ;
using System.Collections.Generic ;
using System.IO ;
using System.IO.Compression ;
using System.Runtime.InteropServices ;
using Microsoft.DotNet.Cli.Build.Framework ;
2016-04-28 16:30:32 -07:00
using Microsoft.DotNet.InternalAbstractions ;
2016-03-15 16:41:18 -07:00
using static Microsoft . DotNet . Cli . Build . Framework . BuildHelpers ;
2016-06-27 18:26:57 -07:00
using Microsoft.Build.Utilities ;
2016-03-15 16:41:18 -07:00
namespace Microsoft.DotNet.Cli.Build
{
2016-06-27 18:26:57 -07:00
public class DebTargets : Task
2016-03-15 16:41:18 -07:00
{
2016-06-27 18:26:57 -07:00
public override bool Execute ( )
{
BuildContext context = new BuildSetup ( "MSBuild" ) . UseAllTargetsFromAssembly < DebTargets > ( ) . CreateBuildContext ( ) ;
BuildTargetContext c = new BuildTargetContext ( context , null , null ) ;
return GenerateDebs ( c ) . Success ;
}
2016-03-15 16:41:18 -07:00
public static BuildTargetResult GenerateDebs ( BuildTargetContext c )
{
2016-06-24 13:06:13 -05:00
if ( CurrentPlatform . IsPlatform ( BuildPlatform . Ubuntu ) )
{
2016-06-27 18:26:57 -07:00
PrepareTargets . Init ( c ) ;
2016-06-24 13:06:13 -05:00
GenerateSdkDeb ( c ) ;
}
2016-03-15 16:41:18 -07:00
return c . Success ( ) ;
}
public static BuildTargetResult GenerateSdkDeb ( BuildTargetContext c )
{
2016-06-24 13:06:13 -05:00
if ( CurrentPlatform . IsPlatform ( BuildPlatform . Ubuntu ) )
2016-06-13 19:08:54 -07:00
{
2016-06-24 13:06:13 -05:00
InstallSharedFramework ( c ) ;
// Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools
// So we need to skip this target if the tools aren't present.
// https://github.com/dotnet/core-setup/issues/167
if ( DebuildNotPresent ( ) )
{
c . Info ( "Debuild not present, skipping target: {nameof(RemovePackages)}" ) ;
return c . Success ( ) ;
}
var channel = c . BuildContext . Get < string > ( "Channel" ) . ToLower ( ) ;
var packageName = CliMonikers . GetSdkDebianPackageName ( c ) ;
var version = c . BuildContext . Get < BuildVersion > ( "BuildVersion" ) . NuGetVersion ;
var debFile = c . BuildContext . Get < string > ( "SdkInstallerFile" ) ;
var manPagesDir = Path . Combine ( Dirs . RepoRoot , "Documentation" , "manpages" ) ;
var previousVersionURL = $"https://dotnetcli.blob.core.windows.net/dotnet/{channel}/Installers/Latest/dotnet-ubuntu-x64.latest.deb" ;
var sdkPublishRoot = c . BuildContext . Get < string > ( "CLISDKRoot" ) ;
var sharedFxDebianPackageName = Monikers . GetDebianSharedFrameworkPackageName ( CliDependencyVersions . SharedFrameworkVersion ) ;
var objRoot = Path . Combine ( Dirs . Output , "obj" , "debian" , "sdk" ) ;
if ( Directory . Exists ( objRoot ) )
{
Directory . Delete ( objRoot , true ) ;
}
Directory . CreateDirectory ( objRoot ) ;
Cmd ( Path . Combine ( Dirs . RepoRoot , "scripts" , "package" , "package-debian.sh" ) ,
"-v" , version ,
"-i" , sdkPublishRoot ,
"-o" , debFile ,
"-p" , packageName ,
"-b" , Monikers . CLISdkBrandName ,
"-m" , manPagesDir ,
"--framework-debian-package-name" , sharedFxDebianPackageName ,
"--framework-nuget-name" , Monikers . SharedFrameworkName ,
"--framework-nuget-version" , CliDependencyVersions . SharedFrameworkVersion ,
"--previous-version-url" , previousVersionURL ,
"--obj-root" , objRoot )
. Execute ( )
. EnsureSuccessful ( ) ;
2016-03-15 16:41:18 -07:00
}
return c . Success ( ) ;
}
public static BuildTargetResult TestDebInstaller ( BuildTargetContext c )
{
2016-06-24 13:06:13 -05:00
if ( CurrentPlatform . IsPlatform ( BuildPlatform . Ubuntu ) )
{
InstallSDK ( c ) ;
RunE2ETest ( c ) ;
RemovePackages ( c ) ;
}
2016-03-15 16:41:18 -07:00
return c . Success ( ) ;
}
2016-03-18 00:43:45 -07:00
public static BuildTargetResult InstallSharedHost ( BuildTargetContext c )
2016-03-15 16:41:18 -07:00
{
2016-06-13 19:08:54 -07:00
// Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools
// So we need to skip this target if the tools aren't present.
// https://github.com/dotnet/core-setup/issues/167
if ( DebuildNotPresent ( ) )
{
c . Info ( "Debuild not present, skipping target: {nameof(RemovePackages)}" ) ;
return c . Success ( ) ;
}
2016-03-18 00:43:45 -07:00
InstallPackage ( c . BuildContext . Get < string > ( "SharedHostInstallerFile" ) ) ;
2016-03-15 16:41:18 -07:00
2016-03-18 00:43:45 -07:00
return c . Success ( ) ;
}
2016-06-13 14:40:11 -07:00
public static BuildTargetResult InstallHostFxr ( BuildTargetContext c )
{
2016-06-24 13:06:13 -05:00
InstallSharedHost ( c ) ;
2016-06-13 19:08:54 -07:00
// Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools
// So we need to skip this target if the tools aren't present.
// https://github.com/dotnet/core-setup/issues/167
if ( DebuildNotPresent ( ) )
{
c . Info ( "Debuild not present, skipping target: {nameof(RemovePackages)}" ) ;
return c . Success ( ) ;
}
2016-06-13 14:40:11 -07:00
InstallPackage ( c . BuildContext . Get < string > ( "HostFxrInstallerFile" ) ) ;
return c . Success ( ) ;
}
2016-03-18 00:43:45 -07:00
public static BuildTargetResult InstallSharedFramework ( BuildTargetContext c )
{
2016-06-24 13:06:13 -05:00
InstallHostFxr ( c ) ;
2016-06-13 19:08:54 -07:00
// Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools
// So we need to skip this target if the tools aren't present.
// https://github.com/dotnet/core-setup/issues/167
if ( DebuildNotPresent ( ) )
{
c . Info ( "Debuild not present, skipping target: {nameof(RemovePackages)}" ) ;
return c . Success ( ) ;
}
2016-03-18 00:43:45 -07:00
InstallPackage ( c . BuildContext . Get < string > ( "SharedFrameworkInstallerFile" ) ) ;
return c . Success ( ) ;
}
public static BuildTargetResult InstallSDK ( BuildTargetContext c )
{
2016-06-24 13:06:13 -05:00
InstallSharedFramework ( c ) ;
2016-06-13 19:08:54 -07:00
// Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools
// So we need to skip this target if the tools aren't present.
// https://github.com/dotnet/core-setup/issues/167
if ( DebuildNotPresent ( ) )
{
c . Info ( "Debuild not present, skipping target: {nameof(RemovePackages)}" ) ;
return c . Success ( ) ;
}
2016-03-18 00:43:45 -07:00
InstallPackage ( c . BuildContext . Get < string > ( "SdkInstallerFile" ) ) ;
2016-03-15 16:41:18 -07:00
return c . Success ( ) ;
}
public static BuildTargetResult RunE2ETest ( BuildTargetContext c )
{
2016-06-24 13:06:13 -05:00
if ( CurrentPlatform . IsPlatform ( BuildPlatform . Ubuntu ) )
2016-06-13 19:08:54 -07:00
{
2016-06-24 13:06:13 -05:00
// Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools
// So we need to skip this target if the tools aren't present.
// https://github.com/dotnet/core-setup/issues/167
if ( DebuildNotPresent ( ) )
{
c . Info ( "Debuild not present, skipping target: {nameof(RemovePackages)}" ) ;
return c . Success ( ) ;
}
Directory . SetCurrentDirectory ( Path . Combine ( Dirs . RepoRoot , "test" , "EndToEnd" ) ) ;
Cmd ( "dotnet" , "build" )
. Execute ( )
. EnsureSuccessful ( ) ;
2016-06-13 19:08:54 -07:00
2016-06-24 13:06:13 -05:00
var testResultsPath = Path . Combine ( Dirs . Output , "obj" , "debian" , "test" , "debian-endtoend-testResults.xml" ) ;
Cmd ( "dotnet" , "test" , "-xml" , testResultsPath )
. Execute ( )
. EnsureSuccessful ( ) ;
}
2016-03-15 16:41:18 -07:00
return c . Success ( ) ;
}
public static BuildTargetResult RemovePackages ( BuildTargetContext c )
{
2016-06-24 13:06:13 -05:00
if ( CurrentPlatform . IsPlatform ( BuildPlatform . Ubuntu ) )
2016-03-15 16:41:18 -07:00
{
2016-06-24 13:06:13 -05:00
// Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools
// So we need to skip this target if the tools aren't present.
// https://github.com/dotnet/core-setup/issues/167
if ( DebuildNotPresent ( ) )
{
c . Info ( "Debuild not present, skipping target: {nameof(RemovePackages)}" ) ;
return c . Success ( ) ;
}
IEnumerable < string > orderedPackageNames = new List < string > ( )
{
CliMonikers . GetSdkDebianPackageName ( c ) ,
Monikers . GetDebianSharedFrameworkPackageName ( CliDependencyVersions . SharedFrameworkVersion ) ,
Monikers . GetDebianHostFxrPackageName ( CliDependencyVersions . HostFxrVersion ) ,
Monikers . GetDebianSharedHostPackageName ( c )
} ;
foreach ( var packageName in orderedPackageNames )
{
RemovePackage ( packageName ) ;
}
2016-03-15 16:41:18 -07:00
}
return c . Success ( ) ;
}
2016-03-18 00:43:45 -07:00
private static void InstallPackage ( string packagePath )
{
Cmd ( "sudo" , "dpkg" , "-i" , packagePath )
. Execute ( )
. EnsureSuccessful ( ) ;
}
private static void RemovePackage ( string packageName )
{
Cmd ( "sudo" , "dpkg" , "-r" , packageName )
. Execute ( )
. EnsureSuccessful ( ) ;
}
2016-06-13 19:08:54 -07:00
private static bool DebuildNotPresent ( )
{
return Cmd ( "/usr/bin/env" , "debuild" , "-h" ) . Execute ( ) . ExitCode ! = 0 ;
}
2016-03-15 16:41:18 -07:00
}
}