@@ -7,10 +7,11 @@ namespace Xamarin.Android.Prepare
77{
88 partial class Step_InstallGNUBinutils : StepWithDownloadProgress
99 {
10- static readonly string ProductName = $ "GNU Binutils { Configurables . Defaults . BinutilsVersion } ";
10+ static readonly string [ ] ? WindowsExtensions = { ".exe" , ".cmd" } ;
11+ static readonly string ProductName = $ "Xamarin.Android Toolchain { Configurables . Defaults . BinutilsVersion } ";
1112
1213 public Step_InstallGNUBinutils ( )
13- : base ( "Install GNU Binutils " )
14+ : base ( "Install Xamarin.Android Toolchain " )
1415 { }
1516
1617 protected override async Task < bool > Execute ( Context context )
@@ -19,7 +20,7 @@ protected override async Task<bool> Execute (Context context)
1920 string windowsDestinationDirectory = Configurables . Paths . WindowsBinutilsInstallDir ;
2021
2122 bool hostHaveAll = HaveAllBinutils ( hostDestinationDirectory ) ;
22- bool windowsHaveAll = HaveAllBinutils ( windowsDestinationDirectory , ".exe" ) ;
23+ bool windowsHaveAll = HaveAllBinutils ( windowsDestinationDirectory , WindowsExtensions ) ;
2324
2425 if ( hostHaveAll && windowsHaveAll ) {
2526 Log . StatusLine ( "All Binutils are already installed" ) ;
@@ -43,28 +44,42 @@ protected override async Task<bool> Execute (Context context)
4344 }
4445
4546 if ( ! hostHaveAll ) {
46- CopyToDestination ( context , "Host" , tempDir , hostDestinationDirectory , executableExtension : ExecutableExtension ) ;
47+ CopyToDestination ( context , "Host" , tempDir , hostDestinationDirectory , executableExtensions : ExecutableExtensions ) ;
4748 }
4849
4950 if ( ! windowsHaveAll ) {
50- CopyToDestination ( context , "Windows" , tempDir , windowsDestinationDirectory , "windows" , ".exe" ) ;
51+ CopyToDestination ( context , "Windows" , tempDir , windowsDestinationDirectory , "windows" , WindowsExtensions ) ;
5152 }
5253
5354 return true ;
5455 }
5556
56- bool CopyToDestination ( Context context , string label , string sourceDir , string destinationDir , string osName = HostName , string ? executableExtension = null )
57+ bool CopyToDestination ( Context context , string label , string sourceDir , string destinationDir , string osName = HostName , string [ ] ? executableExtensions = null )
5758 {
5859 Log . StatusLine ( ) ;
5960 Log . StatusLine ( $ "Installing for { label } :") ;
6061
6162 string sourcePath = Path . Combine ( sourceDir , osName ) ;
6263 foreach ( var kvp in Configurables . Defaults . AndroidToolchainPrefixes ) {
6364 string prefix = kvp . Value ;
65+ CopyTools ( prefix ) ;
66+ }
67+ CopyTools ( String . Empty ) ;
68+
69+ return true ;
6470
71+ void CopyTools ( string prefix )
72+ {
73+ bool copyPrefixed = ! String . IsNullOrEmpty ( prefix ) ;
74+ Console . WriteLine ( $ "Copy prefixed? { copyPrefixed } ") ;
6575 foreach ( NDKTool tool in Configurables . Defaults . NDKTools ) {
66- string toolName = GetToolName ( prefix , tool , executableExtension ) ;
67- string toolSourcePath = Path . Combine ( sourcePath , toolName ) ;
76+ Console . WriteLine ( $ "tool name { tool . Name } , prefixed? { tool . Prefixed } ") ;
77+ if ( tool . Prefixed != copyPrefixed ) {
78+ continue ;
79+ }
80+
81+ string toolSourcePath = GetToolPath ( sourcePath , prefix , tool , executableExtensions , throwOnMissing : true ) ;
82+ string toolName = Path . GetFileName ( toolSourcePath ) ;
6883 string toolDestinationPath = Path . Combine ( destinationDir , toolName ) ;
6984 string versionMarkerPath = GetVersionMarker ( toolDestinationPath ) ;
7085
@@ -73,8 +88,6 @@ bool CopyToDestination (Context context, string label, string sourceDir, string
7388 File . WriteAllText ( versionMarkerPath , DateTime . UtcNow . ToString ( ) ) ;
7489 }
7590 }
76-
77- return true ;
7891 }
7992
8093 async Task < bool > DownloadBinutils ( Context context , string localPackagePath , Uri url )
@@ -106,16 +119,27 @@ async Task<bool> DownloadBinutils (Context context, string localPackagePath, Uri
106119 return true ;
107120 }
108121
109- bool HaveAllBinutils ( string dir , string ? executableExtension = null )
122+ bool HaveAllBinutils ( string dir , string [ ] ? executableExtensions = null )
110123 {
111124 Log . DebugLine ( "Checking if all binutils are installed in {dir}" ) ;
112- string extension = executableExtension ?? String . Empty ;
113125 foreach ( var kvp in Configurables . Defaults . AndroidToolchainPrefixes ) {
114126 string prefix = kvp . Value ;
127+ if ( ! CheckToolsExist ( prefix ) ) {
128+ return false ;
129+ }
130+ }
131+
132+ return CheckToolsExist ( String . Empty ) ;
115133
134+ bool CheckToolsExist ( string prefix )
135+ {
136+ bool checkPrefixed = ! String . IsNullOrEmpty ( prefix ) ;
116137 foreach ( NDKTool tool in Configurables . Defaults . NDKTools ) {
117- string toolName = GetToolName ( prefix , tool , executableExtension ) ;
118- string toolPath = Path . Combine ( dir , toolName ) ;
138+ if ( tool . Prefixed != checkPrefixed ) {
139+ continue ;
140+ }
141+ string toolPath = GetToolPath ( dir , prefix , tool , executableExtensions ) ;
142+ string toolName = Path . GetFileName ( toolPath ) ;
119143 string versionMarkerPath = GetVersionMarker ( toolPath ) ;
120144
121145 Log . DebugLine ( $ "Checking { toolName } ") ;
@@ -129,14 +153,39 @@ bool HaveAllBinutils (string dir, string? executableExtension = null)
129153 return false ;
130154 }
131155 }
132- }
133156
134- return true ;
157+ return true ;
158+ }
135159 }
136160
137- string GetToolName ( string prefix , NDKTool tool , string ? executableExtension = null )
161+ string GetToolPath ( string sourcePath , string prefix , NDKTool tool , string [ ] ? executableExtensions = null , bool throwOnMissing = false )
138162 {
139- return $ "{ prefix } -{ ( String . IsNullOrEmpty ( tool . DestinationName ) ? tool . Name : tool . DestinationName ) } { executableExtension } ";
163+ string baseName = $ "{ ( String . IsNullOrEmpty ( tool . DestinationName ) ? tool . Name : tool . DestinationName ) } ";
164+
165+ if ( ! String . IsNullOrEmpty ( prefix ) ) {
166+ baseName = $ "{ prefix } -{ baseName } ";
167+ }
168+
169+ if ( executableExtensions == null || executableExtensions . Length == 0 ) {
170+ return Path . Combine ( sourcePath , baseName ) ;
171+ }
172+
173+ foreach ( string executableExtension in executableExtensions ) {
174+ string binary = Path . Combine ( sourcePath , $ "{ baseName } { executableExtension } ") ;
175+ Console . WriteLine ( $ "Checking: { binary } ") ;
176+ if ( ! Utilities . FileExists ( binary ) ) {
177+ continue ;
178+ }
179+
180+ return binary ;
181+ }
182+
183+ if ( throwOnMissing ) {
184+ string extensions = String . Join ( "," , executableExtensions ) ;
185+ throw new InvalidOperationException ( $ "Failed to find binary file '{ baseName } {{{extensions}}}'") ;
186+ }
187+
188+ return baseName ;
140189 }
141190
142191 string GetVersionMarker ( string toolPath )
0 commit comments