@@ -134,6 +134,42 @@ sealed class RuntimePropertyIndexEntry
134
134
public uint index ;
135
135
}
136
136
137
+ sealed class AppEnvironmentVariableContextDataProvider : NativeAssemblerStructContextDataProvider
138
+ {
139
+ public override string GetComment ( object data , string fieldName )
140
+ {
141
+ var envVar = EnsureType < AppEnvironmentVariable > ( data ) ;
142
+
143
+ if ( String . Compare ( "name_index" , fieldName , StringComparison . Ordinal ) == 0 ) {
144
+ return $ " '{ envVar . Name } '";
145
+ }
146
+
147
+ if ( String . Compare ( "value_index" , fieldName , StringComparison . Ordinal ) == 0 ) {
148
+ return $ " '{ envVar . Value } '";
149
+ }
150
+
151
+ return String . Empty ;
152
+ }
153
+ }
154
+
155
+ // Order of fields and their type must correspond *exactly* to that in
156
+ // src/native/clr/include/xamarin-app.hh AppEnvironmentVariable structure
157
+ [ NativeAssemblerStructContextDataProvider ( typeof ( AppEnvironmentVariableContextDataProvider ) ) ]
158
+ sealed class AppEnvironmentVariable
159
+ {
160
+ [ NativeAssembler ( Ignore = true ) ]
161
+ public string Name ;
162
+
163
+ [ NativeAssembler ( Ignore = true ) ]
164
+ public string Value ;
165
+
166
+ [ NativeAssembler ( UsesDataProvider = true ) ]
167
+ public uint name_index ;
168
+
169
+ [ NativeAssembler ( UsesDataProvider = true ) ]
170
+ public uint value_index ;
171
+ }
172
+
137
173
sealed class XamarinAndroidBundledAssemblyContextDataProvider : NativeAssemblerStructContextDataProvider
138
174
{
139
175
public override ulong GetBufferSize ( object data , string fieldName )
@@ -195,6 +231,7 @@ sealed class XamarinAndroidBundledAssembly
195
231
StructureInfo ? runtimePropertyIndexEntryStructureInfo ;
196
232
StructureInfo ? hostConfigurationPropertyStructureInfo ;
197
233
StructureInfo ? hostConfigurationPropertiesStructureInfo ;
234
+ StructureInfo ? appEnvironmentVariableStructureInfo ;
198
235
199
236
public bool UsesAssemblyPreload { get ; set ; }
200
237
public string AndroidPackageName { get ; set ; }
@@ -244,10 +281,32 @@ protected override void Construct (LlvmIrModule module)
244
281
245
282
module . AddGlobalVariable ( "format_tag" , FORMAT_TAG , comment : $ " 0x{ FORMAT_TAG : x} ") ;
246
283
247
- var envVars = new LlvmIrGlobalVariable ( environmentVariables , "app_environment_variables" ) {
284
+ var envVarsBlob = new LlvmIrStringBlob ( ) ;
285
+ var appEnvVars = new List < StructureInstance < AppEnvironmentVariable > > ( ) ;
286
+
287
+ if ( environmentVariables != null ) {
288
+ // TODO: skip variables with no name
289
+ foreach ( var kvp in environmentVariables ) {
290
+ ( int nameOffset , int _ ) = envVarsBlob . Add ( kvp . Key ) ;
291
+ ( int valueOffset , int _ ) = envVarsBlob . Add ( kvp . Value ) ;
292
+
293
+ var appEnvVar = new AppEnvironmentVariable {
294
+ Name = kvp . Key ,
295
+ Value = kvp . Value ,
296
+
297
+ name_index = ( uint ) nameOffset ,
298
+ value_index = ( uint ) valueOffset ,
299
+ } ;
300
+ appEnvVars . Add ( new StructureInstance < AppEnvironmentVariable > ( appEnvironmentVariableStructureInfo , appEnvVar ) ) ;
301
+ }
302
+ }
303
+
304
+ var envVars = new LlvmIrGlobalVariable ( appEnvVars , "app_environment_variables" ) {
248
305
Comment = " Application environment variables array, name:value" ,
306
+ Options = LlvmIrVariableOptions . GlobalConstant ,
249
307
} ;
250
- module . Add ( envVars , stringGroupName : "env" , stringGroupComment : " Application environment variables name:value pairs" ) ;
308
+ module . Add ( envVars ) ;
309
+ module . AddGlobalVariable ( "app_environment_variable_contents" , envVarsBlob , LlvmIrVariableOptions . GlobalConstant ) ;
251
310
252
311
var sysProps = new LlvmIrGlobalVariable ( systemProperties , "app_system_properties" ) {
253
312
Comment = " System properties defined by the application" ,
@@ -263,7 +322,7 @@ protected override void Construct (LlvmIrModule module)
263
322
ignore_split_configs = IgnoreSplitConfigs ,
264
323
number_of_runtime_properties = ( uint ) ( runtimeProperties == null ? 0 : runtimeProperties . Count ) ,
265
324
package_naming_policy = ( uint ) PackageNamingPolicy ,
266
- environment_variable_count = ( uint ) ( environmentVariables == null ? 0 : environmentVariables . Count * 2 ) ,
325
+ environment_variable_count = ( uint ) ( environmentVariables == null ? 0 : environmentVariables . Count ) ,
267
326
system_property_count = ( uint ) ( systemProperties == null ? 0 : systemProperties . Count * 2 ) ,
268
327
number_of_assemblies_in_apk = ( uint ) NumberOfAssembliesInApk ,
269
328
number_of_shared_libraries = ( uint ) NativeLibraries . Count ,
@@ -541,5 +600,6 @@ void MapStructures (LlvmIrModule module)
541
600
dsoApkEntryStructureInfo = module . MapStructure < DSOApkEntry > ( ) ;
542
601
runtimePropertyStructureInfo = module . MapStructure < RuntimeProperty > ( ) ;
543
602
runtimePropertyIndexEntryStructureInfo = module . MapStructure < RuntimePropertyIndexEntry > ( ) ;
603
+ appEnvironmentVariableStructureInfo = module . MapStructure < AppEnvironmentVariable > ( ) ;
544
604
}
545
605
}
0 commit comments