11#![ allow( clippy:: disallowed_macros) ]
22
3- use anyhow:: { bail, Context , Result } ;
3+ use anyhow:: { bail, Result } ;
44use duct:: cmd;
5- use serde_json:: Value ;
65use std:: env;
76use std:: fs;
87use std:: path:: { Path , PathBuf } ;
98
109const BSATN_PACKAGE_ID : & str = "spacetimedb.bsatn.runtime" ;
11- const GODOTSHARP_ASSET_ID : & str = "GodotSharp" ;
12- const GODOTSHARP_DLL_FILE_NAME : & str = "GodotSharp.dll" ;
1310const GODOTSHARP_PACKAGE_ID : & str = "godotsharp" ;
1411const RUNTIME_PACKAGE_ID : & str = "spacetimedb.runtime" ;
1512
@@ -128,65 +125,6 @@ fn clear_godot_intermediate_outputs() -> Result<()> {
128125 Ok ( ( ) )
129126}
130127
131- fn restored_package < ' a > ( assets : & ' a Value , package_id : & str ) -> Option < ( & ' a str , & ' a Value ) > {
132- let libraries = assets. get ( "libraries" ) ?. as_object ( ) ?;
133-
134- libraries. iter ( ) . find_map ( |( key, package) | {
135- let ( id, version) = key. split_once ( '/' ) ?;
136- id. eq_ignore_ascii_case ( package_id) . then_some ( ( version, package) )
137- } )
138- }
139-
140- fn restored_lib_package_file < ' a > ( package : & ' a Value , file_name : & str ) -> Option < & ' a str > {
141- package. get ( "files" ) ?. as_array ( ) ?. iter ( ) . find_map ( |file| {
142- let path = file. as_str ( ) ?;
143- let actual_file_name = path. rsplit ( '/' ) . next ( ) ?;
144- ( path. starts_with ( "lib/" ) && actual_file_name == file_name) . then_some ( path)
145- } )
146- }
147-
148- fn verify_godotsharp_restore ( ) -> Result < ( ) > {
149- let sdk = sdk_dir ( ) ;
150- let assets_path = sdk. join ( "obj~/godot/project.assets.json" ) ;
151- let assets =
152- fs:: read_to_string ( & assets_path) . with_context ( || format ! ( "Failed to read {}" , assets_path. display( ) ) ) ?;
153- let assets: Value =
154- serde_json:: from_str ( & assets) . with_context ( || format ! ( "Failed to parse {}" , assets_path. display( ) ) ) ?;
155-
156- let Some ( ( godotsharp_version, godotsharp_package) ) = restored_package ( & assets, GODOTSHARP_ASSET_ID ) else {
157- bail ! (
158- "Godot restore output {} does not contain {}; refusing to pack with --no-restore" ,
159- assets_path. display( ) ,
160- GODOTSHARP_ASSET_ID
161- ) ;
162- } ;
163-
164- let Some ( godotsharp_dll_relative_path) = restored_lib_package_file ( godotsharp_package, GODOTSHARP_DLL_FILE_NAME )
165- else {
166- bail ! (
167- "Godot restore output {} does not reference a lib package file named {}; refusing to pack with --no-restore" ,
168- assets_path. display( ) ,
169- GODOTSHARP_DLL_FILE_NAME
170- ) ;
171- } ;
172-
173- let godotsharp_dll = sdk
174- . join ( "packages" )
175- . join ( GODOTSHARP_PACKAGE_ID )
176- . join ( godotsharp_version)
177- . join ( godotsharp_dll_relative_path) ;
178-
179- if !godotsharp_dll. exists ( ) {
180- bail ! (
181- "Godot restore referenced {}, but the package DLL is missing at {}; refusing to pack with --no-restore" ,
182- GODOTSHARP_ASSET_ID ,
183- godotsharp_dll. display( )
184- ) ;
185- }
186-
187- Ok ( ( ) )
188- }
189-
190128fn find_only_subdir ( dir : & Path ) -> Result < PathBuf > {
191129 let mut subdirs = vec ! [ ] ;
192130
@@ -278,8 +216,12 @@ pub fn regen_dlls() -> Result<()> {
278216 ) ?;
279217
280218 clear_restored_package_dirs ( BSATN_PACKAGE_ID ) ?;
281- clear_restored_package_dirs ( GODOTSHARP_PACKAGE_ID ) ?;
282219 clear_restored_package_dirs ( RUNTIME_PACKAGE_ID ) ?;
220+
221+ // Some Unity runners have had partially restored GodotSharp package state in the past.
222+ // Clear the package and restore outputs so NuGet cannot reuse assets missing GodotSharp.dll.
223+ // See https://github.com/clockworklabs/SpacetimeDB/pull/5133 for more details.
224+ clear_restored_package_dirs ( GODOTSHARP_PACKAGE_ID ) ?;
283225 clear_godot_intermediate_outputs ( ) ?;
284226
285227 cmd ! (
@@ -305,7 +247,6 @@ pub fn regen_dlls() -> Result<()> {
305247 )
306248 . dir ( & sdk)
307249 . run ( ) ?;
308- verify_godotsharp_restore ( ) ?;
309250
310251 overlay_unity_meta_skeleton ( BSATN_PACKAGE_ID ) ?;
311252 overlay_unity_meta_skeleton ( RUNTIME_PACKAGE_ID ) ?;
0 commit comments