33using System . Collections . Generic ;
44using System . IO ;
55using System . Linq ;
6+ using System . Security . Cryptography ;
7+ using System . Text ;
68using GodotTools . Build ;
79using GodotTools . Core ;
810using GodotTools . Internals ;
@@ -45,6 +47,17 @@ public partial class ExportPlugin : EditorExportPlugin
4547 }
4648 } ,
4749 { "default_value" , true }
50+ } ,
51+ new Godot . Collections . Dictionary ( )
52+ {
53+ {
54+ "option" , new Godot . Collections . Dictionary ( )
55+ {
56+ { "name" , "dotnet/embed_build_outputs" } ,
57+ { "type" , ( int ) Variant . Type . Bool }
58+ }
59+ } ,
60+ { "default_value" , false }
4861 }
4962 } ;
5063 }
@@ -114,7 +127,7 @@ private void _ExportBeginImpl(string[] features, bool isDebug, string path, long
114127 if ( ! DeterminePlatformFromFeatures ( features , out string platform ) )
115128 throw new NotSupportedException ( "Target platform not supported." ) ;
116129
117- if ( ! new [ ] { OS . Platforms . Windows , OS . Platforms . LinuxBSD , OS . Platforms . MacOS }
130+ if ( ! new [ ] { OS . Platforms . Windows , OS . Platforms . LinuxBSD , OS . Platforms . MacOS , OS . Platforms . Android }
118131 . Contains ( platform ) )
119132 {
120133 throw new NotImplementedException ( "Target platform not yet implemented." ) ;
@@ -129,15 +142,19 @@ private void _ExportBeginImpl(string[] features, bool isDebug, string path, long
129142 {
130143 archs . Add ( "x86_64" ) ;
131144 }
132- else if ( features . Contains ( "x86_32" ) )
145+ if ( features . Contains ( "x86_32" ) )
133146 {
134147 archs . Add ( "x86_32" ) ;
135148 }
136- else if ( features . Contains ( "arm64" ) )
149+ if ( features . Contains ( "arm64" ) )
137150 {
138151 archs . Add ( "arm64" ) ;
139152 }
140- else if ( features . Contains ( "universal" ) )
153+ if ( features . Contains ( "arm32" ) )
154+ {
155+ archs . Add ( "arm32" ) ;
156+ }
157+ if ( features . Contains ( "universal" ) )
141158 {
142159 if ( platform == OS . Platforms . MacOS )
143160 {
@@ -146,6 +163,8 @@ private void _ExportBeginImpl(string[] features, bool isDebug, string path, long
146163 }
147164 }
148165
166+ bool embedBuildResults = ( bool ) GetOption ( "dotnet/embed_build_outputs" ) || features . Contains ( "android" ) ;
167+
149168 foreach ( var arch in archs )
150169 {
151170 string ridOS = DetermineRuntimeIdentifierOS ( platform ) ;
@@ -190,17 +209,44 @@ private void _ExportBeginImpl(string[] features, bool isDebug, string path, long
190209 "Publish succeeded but project assembly not found in the output directory" ) ;
191210 }
192211
193- // Add to the exported project shared object list.
212+ var manifest = new StringBuilder ( ) ;
194213
214+ // Add to the exported project shared object list or packed resources.
195215 foreach ( string file in Directory . GetFiles ( publishOutputTempDir , "*" , SearchOption . AllDirectories ) )
196216 {
197- AddSharedObject ( file , tags : null ,
198- Path . Join ( projectDataDirName ,
199- Path . GetRelativePath ( publishOutputTempDir , Path . GetDirectoryName ( file ) ) ) ) ;
217+ if ( embedBuildResults )
218+ {
219+ var filePath = SanitizeSlashes ( Path . GetRelativePath ( publishOutputTempDir , file ) ) ;
220+ var fileData = File . ReadAllBytes ( file ) ;
221+ var hash = Convert . ToBase64String ( SHA512 . HashData ( fileData ) ) ;
222+
223+ manifest . Append ( $ "{ filePath } \t { hash } \n ") ;
224+
225+ AddFile ( $ "res://.godot/mono/publish/{ arch } /{ filePath } ", fileData , false ) ;
226+ }
227+ else
228+ {
229+ AddSharedObject ( file , tags : null ,
230+ Path . Join ( projectDataDirName ,
231+ Path . GetRelativePath ( publishOutputTempDir , Path . GetDirectoryName ( file ) ) ) ) ;
232+ }
233+ }
234+
235+ if ( embedBuildResults )
236+ {
237+ var fileData = Encoding . Default . GetBytes ( manifest . ToString ( ) ) ;
238+ AddFile ( $ "res://.godot/mono/publish/{ arch } /.dotnet-publish-manifest", fileData , false ) ;
200239 }
201240 }
202241 }
203242
243+ private string SanitizeSlashes ( string path )
244+ {
245+ if ( Path . DirectorySeparatorChar == '\\ ' )
246+ return path . Replace ( '\\ ' , '/' ) ;
247+ return path ;
248+ }
249+
204250 private string DetermineRuntimeIdentifierOS ( string platform )
205251 => OS . DotNetOSPlatformMap [ platform ] ;
206252
@@ -214,7 +260,7 @@ private string DetermineRuntimeIdentifierArch(string arch)
214260 "x86_64" => "x64" ,
215261 "armeabi-v7a" => "arm" ,
216262 "arm64-v8a" => "arm64" ,
217- "armv7 " => "arm" ,
263+ "arm32 " => "arm" ,
218264 "arm64" => "arm64" ,
219265 _ => throw new ArgumentOutOfRangeException ( nameof ( arch ) , arch , "Unexpected architecture" )
220266 } ;
0 commit comments