2016-03-09 13:26:37 -08: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-09 13:26:37 -08:00
using static Microsoft . DotNet . Cli . Build . Framework . BuildHelpers ;
namespace Microsoft.DotNet.Cli.Build
{
public class PkgTargets
{
2016-03-17 13:19:27 -07:00
public static string PkgsIntermediateDir { get ; set ; }
2016-03-25 14:46:04 -07:00
public static string SharedHostComponentId { get ; set ; }
public static string SharedFxComponentId { get ; set ; }
public static string SharedFxPkgId { get ; set ; }
public static string SharedFrameworkNugetVersion { get ; set ; }
public static string CLISdkComponentId { get ; set ; }
public static string CLISdkPkgId { get ; set ; }
public static string CLISdkNugetVersion { get ; set ; }
2016-03-17 13:19:27 -07:00
[Target]
[BuildPlatforms(BuildPlatform.OSX)]
public static BuildTargetResult InitPkg ( BuildTargetContext c )
{
PkgsIntermediateDir = Path . Combine ( Dirs . Packages , "intermediate" ) ;
Directory . CreateDirectory ( PkgsIntermediateDir ) ;
2016-03-25 14:46:04 -07:00
var hostVersion = c . BuildContext . Get < BuildVersion > ( "BuildVersion" ) . ProductionVersion ;
SharedHostComponentId = $"com.microsoft.dotnet.sharedhost.{hostVersion}.component.osx.x64" ;
string sharedFrameworkNugetName = Monikers . SharedFrameworkName ;
SharedFrameworkNugetVersion = c . BuildContext . Get < string > ( "SharedFrameworkNugetVersion" ) ;
SharedFxComponentId = $"com.microsoft.dotnet.sharedframework.{sharedFrameworkNugetName}.{SharedFrameworkNugetVersion}.component.osx.x64" ;
SharedFxPkgId = $"com.microsoft.dotnet.{sharedFrameworkNugetName}.{SharedFrameworkNugetVersion}.osx.x64" ;
CLISdkNugetVersion = c . BuildContext . Get < BuildVersion > ( "BuildVersion" ) . NuGetVersion ;
CLISdkComponentId = $"com.microsoft.dotnet.dev.{CLISdkNugetVersion}.component.osx.x64" ;
CLISdkPkgId = $"com.microsoft.dotnet.dev.{CLISdkNugetVersion}.osx.x64" ;
2016-03-17 13:19:27 -07:00
return c . Success ( ) ;
}
[Target(nameof(InitPkg), nameof(GenerateSharedFrameworkProductArchive), nameof(GenerateCLISdkProductArchive))]
2016-03-09 13:26:37 -08:00
[BuildPlatforms(BuildPlatform.OSX)]
public static BuildTargetResult GeneratePkgs ( BuildTargetContext c )
{
return c . Success ( ) ;
}
2016-03-17 13:19:27 -07:00
[Target(nameof(GenerateCLISdkPkg))]
[BuildPlatforms(BuildPlatform.OSX)]
public static BuildTargetResult GenerateCLISdkProductArchive ( BuildTargetContext c )
{
2016-03-23 17:59:59 -07:00
string resourcePath = Path . Combine ( Dirs . RepoRoot , "packaging" , "osx" , "clisdk" , "resources" ) ;
2016-03-17 13:19:27 -07:00
string outFilePath = Path . Combine ( Dirs . Packages , c . BuildContext . Get < string > ( "CombinedFrameworkSDKHostInstallerFile" ) ) ;
string inputDistTemplatePath = Path . Combine (
Dirs . RepoRoot ,
"packaging" ,
"osx" ,
"clisdk" ,
"Distribution-Template" ) ;
string distTemplate = File . ReadAllText ( inputDistTemplatePath ) ;
string distributionPath = Path . Combine ( PkgsIntermediateDir , "CLI-SDK-Formatted-Distribution-Template.xml" ) ;
string formattedDistContents =
2016-03-25 14:46:04 -07:00
distTemplate . Replace ( "{SharedFxComponentId}" , SharedFxComponentId )
. Replace ( "{SharedHostComponentId}" , SharedHostComponentId )
2016-03-31 10:02:12 -07:00
. Replace ( "{CLISdkComponentId}" , CLISdkComponentId )
2016-04-27 17:20:52 -07:00
. Replace ( "{CLISdkNugetVersion}" , CLISdkNugetVersion )
. Replace ( "{CLISdkBrandName}" , Monikers . CLISdkBrandName )
. Replace ( "{SharedFxBrandName}" , Monikers . SharedFxBrandName )
. Replace ( "{SharedHostBrandName}" , Monikers . SharedHostBrandName ) ;
2016-03-17 13:19:27 -07:00
File . WriteAllText ( distributionPath , formattedDistContents ) ;
Cmd ( "productbuild" ,
2016-03-25 14:46:04 -07:00
"--version" , CLISdkNugetVersion ,
"--identifier" , CLISdkPkgId ,
2016-03-17 13:19:27 -07:00
"--package-path" , PkgsIntermediateDir ,
"--resources" , resourcePath ,
"--distribution" , distributionPath ,
outFilePath )
. Execute ( )
. EnsureSuccessful ( ) ;
return c . Success ( ) ;
}
2016-03-09 13:26:37 -08:00
[Target]
[BuildPlatforms(BuildPlatform.OSX)]
2016-03-17 13:19:27 -07:00
public static BuildTargetResult GenerateCLISdkPkg ( BuildTargetContext c )
2016-03-09 13:26:37 -08:00
{
2016-03-25 14:46:04 -07:00
string outFilePath = Path . Combine ( PkgsIntermediateDir , CLISdkComponentId + ".pkg" ) ;
2016-03-17 13:19:27 -07:00
string installLocation = "/usr/local/share/dotnet" ;
string scriptsLocation = Path . Combine ( Dirs . RepoRoot , "packaging" , "osx" , "clisdk" , "scripts" ) ;
Cmd ( "pkgbuild" ,
"--root" , c . BuildContext . Get < string > ( "CLISDKRoot" ) ,
2016-03-25 14:46:04 -07:00
"--identifier" , CLISdkComponentId ,
"--version" , CLISdkNugetVersion ,
2016-03-17 13:19:27 -07:00
"--install-location" , installLocation ,
"--scripts" , scriptsLocation ,
outFilePath )
. Execute ( )
. EnsureSuccessful ( ) ;
2016-03-09 13:26:37 -08:00
return c . Success ( ) ;
}
[Target(nameof(GenerateSharedFrameworkPkg), nameof(GenerateSharedHostPkg))]
[BuildPlatforms(BuildPlatform.OSX)]
public static BuildTargetResult GenerateSharedFrameworkProductArchive ( BuildTargetContext c )
{
2016-03-23 17:59:59 -07:00
string resourcePath = Path . Combine ( Dirs . RepoRoot , "packaging" , "osx" , "sharedframework" , "resources" ) ;
2016-03-17 13:19:27 -07:00
string outFilePath = Path . Combine ( PkgsIntermediateDir , c . BuildContext . Get < string > ( "CombinedFrameworkHostInstallerFile" ) ) ;
2016-03-09 13:26:37 -08:00
string inputDistTemplatePath = Path . Combine (
Dirs . RepoRoot ,
"packaging" ,
"osx" ,
"sharedframework" ,
"shared-framework-distribution-template.xml" ) ;
string distTemplate = File . ReadAllText ( inputDistTemplatePath ) ;
2016-03-17 13:19:27 -07:00
string distributionPath = Path . Combine ( PkgsIntermediateDir , "shared-framework-formatted-distribution.xml" ) ;
2016-03-16 17:54:44 -07:00
string formattedDistContents =
2016-03-25 14:46:04 -07:00
distTemplate . Replace ( "{SharedFxComponentId}" , SharedFxComponentId )
2016-03-31 10:02:12 -07:00
. Replace ( "{SharedHostComponentId}" , SharedHostComponentId )
. Replace ( "{SharedFrameworkNugetName}" , Monikers . SharedFrameworkName )
2016-04-27 17:20:52 -07:00
. Replace ( "{SharedFrameworkNugetVersion}" , SharedFrameworkNugetVersion )
. Replace ( "{SharedFxBrandName}" , Monikers . SharedFxBrandName )
. Replace ( "{SharedHostBrandName}" , Monikers . SharedHostBrandName ) ;
2016-03-09 13:26:37 -08:00
File . WriteAllText ( distributionPath , formattedDistContents ) ;
Cmd ( "productbuild" ,
2016-03-25 14:46:04 -07:00
"--version" , SharedFrameworkNugetVersion ,
"--identifier" , SharedFxPkgId ,
2016-03-17 13:19:27 -07:00
"--package-path" , PkgsIntermediateDir ,
2016-03-16 17:54:44 -07:00
"--resources" , resourcePath ,
2016-03-09 13:26:37 -08:00
"--distribution" , distributionPath ,
2016-03-10 15:19:54 -08:00
outFilePath )
2016-03-09 13:26:37 -08:00
. Execute ( )
. EnsureSuccessful ( ) ;
return c . Success ( ) ;
}
[Target]
[BuildPlatforms(BuildPlatform.OSX)]
public static BuildTargetResult GenerateSharedFrameworkPkg ( BuildTargetContext c )
{
2016-03-25 14:46:04 -07:00
string outFilePath = Path . Combine ( PkgsIntermediateDir , SharedFxComponentId + ".pkg" ) ;
2016-03-09 13:26:37 -08:00
string installLocation = "/usr/local/share/dotnet" ;
string scriptsLocation = Path . Combine ( Dirs . RepoRoot , "packaging" , "osx" , "sharedframework" , "scripts" ) ;
Cmd ( "pkgbuild" ,
"--root" , c . BuildContext . Get < string > ( "SharedFrameworkPublishRoot" ) ,
2016-03-25 14:46:04 -07:00
"--identifier" , SharedFxComponentId ,
"--version" , SharedFrameworkNugetVersion ,
2016-03-09 13:26:37 -08:00
"--install-location" , installLocation ,
"--scripts" , scriptsLocation ,
outFilePath )
. Execute ( )
. EnsureSuccessful ( ) ;
return c . Success ( ) ;
}
[Target]
[BuildPlatforms(BuildPlatform.OSX)]
public static BuildTargetResult GenerateSharedHostPkg ( BuildTargetContext c )
{
2016-03-25 14:46:04 -07:00
string version = c . BuildContext . Get < BuildVersion > ( "BuildVersion" ) . NuGetVersion ;
string outFilePath = Path . Combine ( PkgsIntermediateDir , SharedHostComponentId + ".pkg" ) ;
2016-03-09 13:26:37 -08:00
string installLocation = "/usr/local/share/dotnet" ;
string scriptsLocation = Path . Combine ( Dirs . RepoRoot , "packaging" , "osx" , "sharedhost" , "scripts" ) ;
Cmd ( "pkgbuild" ,
"--root" , c . BuildContext . Get < string > ( "SharedHostPublishRoot" ) ,
2016-03-25 14:46:04 -07:00
"--identifier" , SharedHostComponentId ,
2016-03-09 13:26:37 -08:00
"--version" , version ,
"--install-location" , installLocation ,
"--scripts" , scriptsLocation ,
outFilePath )
. Execute ( )
. EnsureSuccessful ( ) ;
return c . Success ( ) ;
}
}
2016-03-17 13:19:27 -07:00
}