Skip to content

Commit 40a46b6

Browse files
committed
A handful of bugfixes and performance tweaks
1 parent c854efa commit 40a46b6

File tree

8 files changed

+34
-25
lines changed

8 files changed

+34
-25
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/GeneratePackageManagerJava.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public class GeneratePackageManagerJava : AndroidTask
6464
[Required]
6565
public string AndroidBinUtilsDirectory { get; set; }
6666

67+
[Required]
68+
public bool AssemblyStoreEmbeddedInRuntime { get; set; }
69+
6770
[Output]
6871
public ITaskItem[] EmbeddedObjectFiles { get; set; }
6972

@@ -366,6 +369,7 @@ void AddEnvironment ()
366369
JniRemappingReplacementMethodIndexEntryCount = jniRemappingNativeCodeInfo == null ? 0 : jniRemappingNativeCodeInfo.ReplacementMethodIndexEntryCount,
367370
MarshalMethodsEnabled = EnableMarshalMethods,
368371
IgnoreSplitConfigs = ShouldIgnoreSplitConfigs (),
372+
AssemblyStoreEmbeddedInRuntime = UseAssemblyStore && AssemblyStoreEmbeddedInRuntime,
369373
};
370374
LLVMIR.LlvmIrModule appConfigModule = appConfigAsmGen.Construct ();
371375

src/Xamarin.Android.Build.Tasks/Utilities/ApplicationConfigNativeAssemblyGenerator.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ sealed class XamarinAndroidBundledAssembly
188188
public List<ITaskItem> NativeLibraries { get; set; }
189189
public bool MarshalMethodsEnabled { get; set; }
190190
public bool IgnoreSplitConfigs { get; set; }
191+
public bool AssemblyStoreEmbeddedInRuntime { get; set; }
191192

192193
public ApplicationConfigNativeAssemblyGenerator (IDictionary<string, string> environmentVariables, IDictionary<string, string> systemProperties, TaskLoggingHelper log)
193194
: base (log)
@@ -294,6 +295,24 @@ protected override void Construct (LlvmIrModule module)
294295
module.Add (bundled_assemblies);
295296

296297
AddAssemblyStores (module);
298+
299+
if (AssemblyStoreEmbeddedInRuntime) {
300+
return;
301+
}
302+
303+
// Need these to keep ABI compatibility with `libxamarin-app.so` used at the runtime's build time
304+
var embedded_assembly_store_size = new LlvmIrGlobalVariable (
305+
(ulong)0,
306+
"embedded_assembly_store_size",
307+
LlvmIrVariableOptions.GlobalConstant
308+
);
309+
module.Add (embedded_assembly_store_size);
310+
311+
var embedded_assembly_store = new LlvmIrGlobalVariable (typeof (byte[]), "embedded_assembly_store", LlvmIrVariableOptions.GlobalWritable) {
312+
ZeroInitializeArray = true,
313+
ArrayItemCount = 0,
314+
};
315+
module.Add (embedded_assembly_store);
297316
}
298317

299318
void AddAssemblyStores (LlvmIrModule module)

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
328328
<_AndroidUseMarshalMethods Condition=" '$(AndroidIncludeDebugSymbols)' == 'True' ">False</_AndroidUseMarshalMethods>
329329
<_AndroidUseMarshalMethods Condition=" '$(AndroidIncludeDebugSymbols)' != 'True' ">$(AndroidEnableMarshalMethods)</_AndroidUseMarshalMethods>
330330
<_AndroidEmbedAssemblyStoreInRuntime Condition=" '$(AndroidUseAssemblyStore)' == 'True' And '$(_AndroidEmbedAssemblyStoreInRuntime)' == '' ">True</_AndroidEmbedAssemblyStoreInRuntime>
331+
<_AndroidEmbedAssemblyStoreInRuntime Condition="'$(_AndroidEmbedAssemblyStoreInRuntime)' == '' ">False</_AndroidEmbedAssemblyStoreInRuntime>
331332
</PropertyGroup>
332333

333334
<!-- Do not resolve from the GAC under any circumstances in Mobile -->
@@ -1749,6 +1750,7 @@ because xbuild doesn't support framework reference assemblies.
17491750
EnableMarshalMethods="$(_AndroidUseMarshalMethods)"
17501751
CustomBundleConfigFile="$(AndroidBundleConfigurationFile)"
17511752
AndroidBinUtilsDirectory="$(AndroidBinUtilsDirectory)"
1753+
AssemblyStoreEmbeddedInRuntime="$(_AndroidEmbedAssemblyStoreInRuntime)"
17521754
>
17531755
<Output TaskParameter="EmbeddedObjectFiles" ItemName="_NativeAssemblyTarget" />
17541756
</GeneratePackageManagerJava>

src/native/monodroid/monodroid-glue.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ MonodroidRuntime::set_profile_options ()
11051105
.append (OUTPUT_ARG)
11061106
.append (output_path.get (), output_path.length ());
11071107
}
1108-
if (Util::create_directory (AndroidSystem::override_dirs[0], 0) < 0) {
1108+
if (Util::create_directory (AndroidSystem::override_dirs[0], 0777, 000) < 0) {
11091109
log_warn (LOG_DEFAULT, "Failed to create directory '%s'. %s", AndroidSystem::override_dirs[0], std::strerror (errno));
11101110
}
11111111

src/native/runtime-base/android-system.cc

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -262,26 +262,14 @@ AndroidSystem::monodroid_get_system_property_from_overrides ([[maybe_unused]] co
262262
return 0;
263263
}
264264

265-
// TODO: review this. Do we really have to create the dir in release?
266265
void
267266
AndroidSystem::create_update_dir (char *override_dir) noexcept
268267
{
269-
#if defined (RELEASE)
270-
/*
271-
* Don't create .__override__ on Release builds, because Google requires
272-
* that pre-loaded apps not create world-writable directories.
273-
*
274-
* However, if any logging is enabled (which should _not_ happen with
275-
* pre-loaded apps!), we need the .__override__ directory...
276-
*/
277-
if (log_categories == 0 && monodroid_get_system_property (SharedConstants::DEBUG_MONO_PROFILE_PROPERTY, nullptr) == 0) {
278-
return;
279-
}
280-
#endif // def RELEASE
281-
282268
override_dirs [0] = override_dir;
269+
#if defined(DEBUG)
270+
log_debug (LOG_DEFAULT, "Creating public update directory: `%s`", override_dir);
283271
Util::create_public_directory (override_dir);
284-
log_warn (LOG_DEFAULT, "Creating public update directory: `%s`", override_dir);
272+
#endif
285273
}
286274

287275
bool

src/native/runtime-base/timing-internal.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ FastTiming::really_initialize (bool log_immediately) noexcept
2222
if (immediate_logging) {
2323
return;
2424
}
25-
26-
log_write (LOG_TIMING, LogLevel::Info, "[2/1] To get timing results, send the mono.android.app.DUMP_TIMING_DATA intent to the application");
2725
}
2826

2927
void

src/native/runtime-base/util.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,14 @@ Util::path_combine (const char *path1, const char *path2)
138138
void
139139
Util::create_public_directory (const char *dir)
140140
{
141-
mode_t m = umask (0);
142-
int ret = mkdir (dir, 0777);
141+
int ret = create_directory (dir, 0777, 0);
143142
if (ret < 0) {
144-
log_warn (LOG_DEFAULT, "Failed to create directory '%s'. %s", dir, std::strerror (errno));
143+
log_warn (LOG_DEFAULT, "Failed to create public directory '%s'. %s", dir, std::strerror (errno));
145144
}
146-
umask (m);
147145
}
148146

149147
int
150-
Util::create_directory (const char *pathname, mode_t mode)
148+
Util::create_directory (const char *pathname, mode_t mode, mode_t mask)
151149
{
152150
if (mode <= 0)
153151
mode = DEFAULT_DIRECTORY_MODE;
@@ -156,7 +154,7 @@ Util::create_directory (const char *pathname, mode_t mode)
156154
errno = EINVAL;
157155
return -1;
158156
}
159-
mode_t oldumask = umask (022);
157+
mode_t oldumask = umask (mask);
160158
std::unique_ptr<char> path {strdup_new (pathname)};
161159
int rv, ret = 0;
162160
for (char *d = path.get (); d != nullptr && *d; ++d) {

src/native/runtime-base/util.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace xamarin::android
7171
static char *monodroid_strdup_vprintf (const char *format, va_list vargs);
7272
static char* path_combine (const char *path1, const char *path2);
7373
static void create_public_directory (const char *dir);
74-
static int create_directory (const char *pathname, mode_t mode);
74+
static int create_directory (const char *pathname, mode_t mode, mode_t mask = 022);
7575
static void set_world_accessable (const char *path);
7676
static void set_user_executable (const char *path);
7777
static bool file_exists (const char *file);

0 commit comments

Comments
 (0)