@@ -8,103 +8,57 @@ namespace Avalonia.Build.Tasks
8
8
{
9
9
public class CompileAvaloniaXamlTask : ITask
10
10
{
11
+ public const string AvaloniaCompileOutputMetadataName = "AvaloniaCompileOutput" ;
12
+
11
13
public bool Execute ( )
12
14
{
13
15
Enum . TryParse ( ReportImportance , true , out MessageImportance outputImportance ) ;
14
- var writtenFilePaths = new List < string > ( ) ;
15
-
16
- OutputPath ??= AssemblyFile ;
17
- RefOutputPath ??= RefAssemblyFile ;
18
- var outputPdb = GetPdbPath ( OutputPath ) ;
19
- var input = AssemblyFile ;
20
- var refInput = RefOutputPath ;
21
- var inputPdb = GetPdbPath ( input ) ;
22
- // Make a copy and delete the original file to prevent MSBuild from thinking that everything is OK
23
- if ( OriginalCopyPath != null )
24
- {
25
- var originalCopyPathRef = Path . ChangeExtension ( OriginalCopyPath , ".ref.dll" ) ;
16
+
17
+ var outputPath = AssemblyFile . GetMetadata ( AvaloniaCompileOutputMetadataName ) ;
18
+ var refOutputPath = RefAssemblyFile ? . GetMetadata ( AvaloniaCompileOutputMetadataName ) ;
26
19
27
- File . Copy ( AssemblyFile , OriginalCopyPath , true ) ;
28
- writtenFilePaths . Add ( OriginalCopyPath ) ;
29
- input = OriginalCopyPath ;
30
- File . Delete ( AssemblyFile ) ;
31
-
32
- if ( File . Exists ( inputPdb ) )
33
- {
34
- var copyPdb = GetPdbPath ( OriginalCopyPath ) ;
35
- File . Copy ( inputPdb , copyPdb , true ) ;
36
- writtenFilePaths . Add ( copyPdb ) ;
37
- File . Delete ( inputPdb ) ;
38
- inputPdb = copyPdb ;
39
- }
40
-
41
- if ( ! string . IsNullOrWhiteSpace ( RefAssemblyFile ) && File . Exists ( RefAssemblyFile ) )
42
- {
43
- // We also copy ref assembly just for case if needed later for testing.
44
- // But do not remove the original one, as MSBuild actually complains about it with multi-thread compiling.
45
- File . Copy ( RefAssemblyFile , originalCopyPathRef , true ) ;
46
- writtenFilePaths . Add ( originalCopyPathRef ) ;
47
- refInput = originalCopyPathRef ;
48
- }
20
+ Directory . CreateDirectory ( Path . GetDirectoryName ( outputPath ) ) ;
21
+ if ( ! string . IsNullOrEmpty ( refOutputPath ) )
22
+ {
23
+ Directory . CreateDirectory ( Path . GetDirectoryName ( refOutputPath ) ) ;
49
24
}
50
25
51
- var msg = $ "CompileAvaloniaXamlTask -> AssemblyFile:{ AssemblyFile } , ProjectDirectory:{ ProjectDirectory } , OutputPath:{ OutputPath } ";
26
+ var msg = $ "CompileAvaloniaXamlTask -> AssemblyFile:{ AssemblyFile } , ProjectDirectory:{ ProjectDirectory } , OutputPath:{ outputPath } ";
52
27
BuildEngine . LogMessage ( msg , outputImportance < MessageImportance . Low ? MessageImportance . High : outputImportance ) ;
53
28
54
29
var res = XamlCompilerTaskExecutor . Compile ( BuildEngine ,
55
- input , OutputPath ,
56
- refInput , RefOutputPath ,
57
- File . ReadAllLines ( ReferencesFilePath ) . Where ( l => ! string . IsNullOrWhiteSpace ( l ) ) . ToArray ( ) ,
30
+ AssemblyFile . ItemSpec , outputPath ,
31
+ RefAssemblyFile ? . ItemSpec , refOutputPath ,
32
+ References ? . Select ( i => i . ItemSpec ) . ToArray ( ) ?? Array . Empty < string > ( ) ,
58
33
ProjectDirectory , VerifyIl , DefaultCompileBindings , outputImportance ,
59
34
new XamlCompilerDiagnosticsFilter ( AnalyzerConfigFiles ) ,
60
35
( SignAssembly && ! DelaySign ) ? AssemblyOriginatorKeyFile : null ,
61
36
SkipXamlCompilation , DebuggerLaunch , VerboseExceptions ) ;
62
- if ( ! res . Success )
63
- {
64
- WrittenFilePaths = writtenFilePaths . ToArray ( ) ;
65
- return false ;
66
- }
67
37
68
- if ( ! res . WrittenFile )
38
+ if ( res . Success && ! res . WrittenFile )
69
39
{
70
- File . Copy ( input , OutputPath , true ) ;
71
- if ( File . Exists ( inputPdb ) )
72
- File . Copy ( inputPdb , outputPdb , true ) ;
73
- }
74
- else if ( ! string . IsNullOrWhiteSpace ( RefOutputPath ) && File . Exists ( RefOutputPath ) )
75
- writtenFilePaths . Add ( RefOutputPath ) ;
76
-
77
- writtenFilePaths . Add ( OutputPath ) ;
78
- if ( File . Exists ( outputPdb ) )
79
- writtenFilePaths . Add ( outputPdb ) ;
40
+ // To simplify incremental build checks, copy the input files to the expected output locations even if the Xaml compiler didn't do anything.
41
+ File . Copy ( AssemblyFile . ItemSpec , outputPath , overwrite : true ) ;
42
+ File . Copy ( Path . ChangeExtension ( AssemblyFile . ItemSpec , ".pdb" ) , Path . ChangeExtension ( outputPath , ".pdb" ) , overwrite : true ) ;
80
43
81
- WrittenFilePaths = writtenFilePaths . ToArray ( ) ;
82
- return true ;
83
- }
44
+ if ( ! string . IsNullOrEmpty ( refOutputPath ) )
45
+ {
46
+ File . Copy ( RefAssemblyFile . ItemSpec , refOutputPath , overwrite : true ) ;
47
+ }
48
+ }
84
49
85
- string GetPdbPath ( string p )
86
- {
87
- var d = Path . GetDirectoryName ( p ) ;
88
- var f = Path . GetFileNameWithoutExtension ( p ) ;
89
- var rv = f + ".pdb" ;
90
- if ( d != null )
91
- rv = Path . Combine ( d , rv ) ;
92
- return rv ;
50
+ return res . Success ;
93
51
}
94
52
95
- [ Required ]
96
- public string AssemblyFile { get ; set ; }
97
- [ Required ]
98
- public string ReferencesFilePath { get ; set ; }
99
- [ Required ]
100
- public string OriginalCopyPath { get ; set ; }
101
53
[ Required ]
102
54
public string ProjectDirectory { get ; set ; }
103
55
104
- public string RefAssemblyFile { get ; set ; }
105
- public string RefOutputPath { get ; set ; }
106
-
107
- public string OutputPath { get ; set ; }
56
+ [ Required ]
57
+ public ITaskItem AssemblyFile { get ; set ; }
58
+
59
+ public ITaskItem ? RefAssemblyFile { get ; set ; }
60
+
61
+ public ITaskItem [ ] ? References { get ; set ; }
108
62
109
63
public bool VerifyIl { get ; set ; }
110
64
@@ -126,8 +80,5 @@ string GetPdbPath(string p)
126
80
public bool VerboseExceptions { get ; set ; }
127
81
128
82
public ITaskItem [ ] AnalyzerConfigFiles { get ; set ; }
129
-
130
- [ Output ]
131
- public string [ ] WrittenFilePaths { get ; private set ; } = Array . Empty < string > ( ) ;
132
83
}
133
84
}
0 commit comments