@@ -63,22 +63,10 @@ int RunCreate(IEnumerable<string> args)
63
63
}
64
64
65
65
// todo use the standard get or build code
66
- string ? binlogFilePath = null ;
67
- if ( extra . Count == 1 )
66
+ string binlogFilePath = GetLogFilePath ( extra ) ;
67
+ if ( PathUtil . Comparer . Equals ( ".complog" , Path . GetExtension ( binlogFilePath ) ) )
68
68
{
69
- binlogFilePath = extra [ 0 ] ;
70
- }
71
- else if ( extra . Count == 0 )
72
- {
73
- binlogFilePath = Directory
74
- . EnumerateFiles ( CurrentDirectory , "*.binlog" )
75
- . OrderBy ( x => Path . GetFileName ( x ) , PathUtil . Comparer )
76
- . FirstOrDefault ( ) ;
77
- }
78
-
79
- if ( binlogFilePath is null )
80
- {
81
- PrintUsage ( ) ;
69
+ WriteLine ( $ "Already a .complog file: { binlogFilePath } ") ;
82
70
return ExitFailure ;
83
71
}
84
72
@@ -87,11 +75,7 @@ int RunCreate(IEnumerable<string> args)
87
75
complogFilePath = Path . ChangeExtension ( binlogFilePath , ".complog" ) ;
88
76
}
89
77
90
- if ( ! Path . IsPathRooted ( complogFilePath ) )
91
- {
92
- complogFilePath = Path . Combine ( CurrentDirectory , complogFilePath ) ;
93
- }
94
-
78
+ complogFilePath = GetResolvedPath ( CurrentDirectory , complogFilePath ) ;
95
79
var diagnosticList = CompilerLogUtil . ConvertBinaryLog (
96
80
binlogFilePath ,
97
81
complogFilePath ,
@@ -583,66 +567,63 @@ Stream GetOrCreateCompilerLogStream(List<string> extra)
583
567
/// </summary>
584
568
string GetLogFilePath ( List < string > extra )
585
569
{
586
- string ? path ;
570
+ string ? logFilePath ;
571
+ IEnumerable < string > args = Array . Empty < string > ( ) ;
572
+ string baseDirectory = CurrentDirectory ;
587
573
if ( extra . Count == 0 )
588
574
{
589
- path = GetLogFilePathExisting ( CurrentDirectory ) ;
590
- if ( path is null )
575
+ logFilePath = FindLogFilePath ( baseDirectory ) ;
576
+ }
577
+ else
578
+ {
579
+ logFilePath = extra [ 0 ] ;
580
+ args = extra . Skip ( 1 ) ;
581
+ if ( string . IsNullOrEmpty ( Path . GetExtension ( logFilePath ) ) )
591
582
{
592
- throw CreateOptionException ( ) ;
583
+ baseDirectory = logFilePath ;
584
+ logFilePath = FindLogFilePath ( baseDirectory ) ;
593
585
}
594
-
595
- return path ;
596
586
}
597
587
598
- path = extra [ 0 ] ;
599
- if ( path == "--" )
588
+ if ( logFilePath is null )
600
589
{
601
- return GetLogFilePathAfterBuild ( CurrentDirectory , null , extra . Skip ( 1 ) ) ;
590
+ throw CreateOptionException ( ) ;
602
591
}
603
592
604
- switch ( Path . GetExtension ( path ) )
593
+ switch ( Path . GetExtension ( logFilePath ) )
605
594
{
606
595
case ".complog" :
607
596
case ".binlog" :
608
- if ( extra . Count > 1 )
597
+ if ( args . Any ( ) )
609
598
{
610
- throw new OptionException ( $ "Extra arguments: { string . Join ( ' ' , extra . Skip ( 1 ) ) } ", "log" ) ;
599
+ throw new OptionException ( $ "Extra arguments: { string . Join ( ' ' , args . Skip ( 1 ) ) } ", "log" ) ;
611
600
}
612
601
613
- return GetResolvedPath ( CurrentDirectory , path ) ;
602
+ return GetResolvedPath ( CurrentDirectory , logFilePath ) ;
614
603
case ".sln" :
615
604
case ".csproj" :
616
- return GetLogFilePathAfterBuild ( CurrentDirectory , path , extra . Skip ( 1 ) ) ;
605
+ case ".vbproj" :
606
+ return GetLogFilePathAfterBuild ( baseDirectory , logFilePath , args ) ;
617
607
default :
618
- throw new OptionException ( $ "Not a valid log file { path } ", "log" ) ;
608
+ throw new OptionException ( $ "Not a valid log file { logFilePath } ", "log" ) ;
619
609
}
620
610
621
- static string GetLogFilePathExisting ( string baseDirectory )
622
- {
623
- // Search the directory for valid log files
624
- var path = FindFirstFileWithPattern ( baseDirectory , "*.complog" , "*.binlog" ) ;
625
- if ( path is not null )
626
- {
627
- return path ;
628
- }
629
-
630
- throw CreateOptionException ( ) ;
631
- }
611
+ static string ? FindLogFilePath ( string baseDirectory ) =>
612
+ FindFirstFileWithPattern ( baseDirectory , "*.complog" , "*.binlog" , "*.sln" , "*.csproj" , ".vbproj" ) ;
632
613
633
614
static string GetLogFilePathAfterBuild ( string baseDirectory , string ? buildFileName , IEnumerable < string > buildArgs )
634
615
{
635
616
var path = buildFileName is not null
636
617
? GetResolvedPath ( baseDirectory , buildFileName )
637
- : FindFirstFileWithPattern ( "*.sln" , "*.csproj" ) ;
618
+ : FindFirstFileWithPattern ( baseDirectory , "*.sln" , "*.csproj" , ".vbproj ") ;
638
619
if ( path is null )
639
620
{
640
621
throw CreateOptionException ( ) ;
641
622
}
642
623
643
- // TODO: use a temp file for the binlog
644
- var args = $ "build { path } -bl:msbuild .binlog { string . Join ( ' ' , buildArgs ) } ";
645
- WriteLine ( "Building" ) ;
624
+ var tag = buildArgs . Any ( ) ? "" : "-t:Rebuild" ;
625
+ var args = $ "build { path } -bl:complog .binlog { tag } { string . Join ( ' ' , buildArgs ) } ";
626
+ WriteLine ( $ "Building { path } ") ;
646
627
WriteLine ( $ "dotnet { args } ") ;
647
628
var result = ProcessUtil . Run ( "dotnet" , args , baseDirectory ) ;
648
629
WriteLine ( result . StandardOut ) ;
@@ -652,8 +633,7 @@ static string GetLogFilePathAfterBuild(string baseDirectory, string? buildFileNa
652
633
throw new Exception ( "Build failed" ) ;
653
634
}
654
635
655
- // TODO: use a temp file for the binlog
656
- return Path . Combine ( baseDirectory , "msbuild.binlog" ) ;
636
+ return Path . Combine ( baseDirectory , "complog.binlog" ) ;
657
637
}
658
638
659
639
static OptionException CreateOptionException ( ) => new ( "Need a file to analyze" , "log" ) ;
0 commit comments