2016-05-11 17:20:40 -07:00
using System ;
using System.IO ;
2016-02-02 10:04:50 -08:00
using System.Linq ;
using System.Runtime.InteropServices ;
2016-04-28 16:30:32 -07:00
using Microsoft.DotNet.Cli.Build.Framework ;
using Microsoft.DotNet.InternalAbstractions ;
2016-02-02 10:04:50 -08:00
namespace Microsoft.DotNet.Cli.Build
{
2016-03-16 15:54:02 -07:00
public class DotNetCli
2016-02-02 10:04:50 -08:00
{
public static readonly DotNetCli Stage0 = new DotNetCli ( GetStage0Path ( ) ) ;
2016-03-16 15:54:02 -07:00
public static readonly DotNetCli Stage1 = new DotNetCli ( Dirs . Stage1 ) ;
public static readonly DotNetCli Stage2 = new DotNetCli ( Dirs . Stage2 ) ;
2016-02-02 10:04:50 -08:00
public string BinPath { get ; }
public DotNetCli ( string binPath )
{
BinPath = binPath ;
}
public Command Exec ( string command , params string [ ] args )
{
2016-03-24 22:24:31 -07:00
var newArgs = args . ToList ( ) ;
newArgs . Insert ( 0 , command ) ;
if ( EnvVars . Verbose )
{
newArgs . Insert ( 0 , "-v" ) ;
}
return Command . Create ( Path . Combine ( BinPath , $"dotnet{Constants.ExeSuffix}" ) , newArgs ) ;
2016-02-02 10:04:50 -08:00
}
public Command Restore ( params string [ ] args ) = > Exec ( "restore" , args ) ;
public Command Build ( params string [ ] args ) = > Exec ( "build" , args ) ;
public Command Pack ( params string [ ] args ) = > Exec ( "pack" , args ) ;
public Command Test ( params string [ ] args ) = > Exec ( "test" , args ) ;
public Command Publish ( params string [ ] args ) = > Exec ( "publish" , args ) ;
2016-05-11 17:20:40 -07:00
public string GetRuntimeId ( )
{
string info = Exec ( "" , "--info" ) . CaptureStdOut ( ) . Execute ( ) . StdOut ;
string rid = Array . Find < string > ( info . Split ( Environment . NewLine . ToCharArray ( ) ) , ( e ) = > e . Contains ( "RID:" ) ) ? . Replace ( "RID:" , "" ) . Trim ( ) ;
if ( string . IsNullOrEmpty ( rid ) )
{
throw new BuildFailureException ( "Could not find the Runtime ID from Stage0 --info or --version" ) ;
}
return rid ;
}
2016-02-02 10:04:50 -08:00
private static string GetStage0Path ( )
{
if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
{
2016-02-23 18:04:49 -08:00
return Path . Combine ( Directory . GetCurrentDirectory ( ) , ".dotnet_stage0" ,
2016-04-28 16:30:32 -07:00
RuntimeEnvironment . OperatingSystemPlatform . ToString ( ) ,
RuntimeEnvironment . RuntimeArchitecture ) ;
2016-02-02 10:04:50 -08:00
}
else
{
2016-04-28 16:30:32 -07:00
return Path . Combine ( Directory . GetCurrentDirectory ( ) , ".dotnet_stage0" , RuntimeEnvironment . OperatingSystemPlatform . ToString ( ) ) ;
2016-02-02 10:04:50 -08:00
}
2016-03-03 11:35:47 -08:00
2016-02-02 10:04:50 -08:00
}
}
}