Skip to content

Commit

Permalink
Merge branch 'main' into issue7335
Browse files Browse the repository at this point in the history
* main:
  [monodroid] Replace `exit()` with `abort()` in native code (dotnet#7734)
  Bump to xamarin/Java.Interop/main@8a1ae57 (dotnet#7738)
  [build] bump `$(AndroidNet7Version)` (dotnet#7737)
  Bump to xamarin/Java.Interop/main@1366d99 (dotnet#7718)
  [Xamarin.Android.Build.Tasks] fix AndroidGenerateResourceDesigner (dotnet#7721)
  Bump to xamarin/monodroid@50faac94 (dotnet#7725)
  • Loading branch information
grendello committed Jan 25, 2023
2 parents 3b1c93b + c990148 commit 232d8da
Show file tree
Hide file tree
Showing 23 changed files with 137 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .external
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
xamarin/monodroid:main@2b9c9d01820c8df4541157f6b6116852eba73350
xamarin/monodroid:main@50faac94c6a0c27864564829ac83f3988c82f8ef
mono/mono:2020-02@6dd9def57ce969ca04a0ecd9ef72c0a8f069112d
2 changes: 1 addition & 1 deletion Configuration.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<DebugType Condition=" '$(DebugType)' == '' ">portable</DebugType>
<Deterministic Condition=" '$(Deterministic)' == '' ">True</Deterministic>
<LangVersion Condition=" '$(LangVersion)' == '' ">latest</LangVersion>
<AndroidNet7Version Condition=" '$(AndroidNet7Version)' == '' ">33.0.1</AndroidNet7Version>
<AndroidNet7Version Condition=" '$(AndroidNet7Version)' == '' ">33.0.26</AndroidNet7Version>
<AndroidNet6Version Condition=" '$(AndroidNet6Version)' == '' ">32.0.485</AndroidNet6Version>
</PropertyGroup>
<PropertyGroup Condition=" '$(HostOS)' == '' ">
Expand Down
2 changes: 1 addition & 1 deletion external/Java.Interop
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Copyright (C) 2016 Xamarin. All rights reserved.
</Target>

<Target Name="_GenerateResourceDesignerIntermediateClass"
Condition=" '$(AndroidUseDesignerAssembly)' == 'True' "
Condition=" '$(AndroidUseDesignerAssembly)' == 'True' And '$(AndroidGenerateResourceDesigner)' == 'true' "
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(_GenerateResourceDesignerClassFile)"
>
Expand Down Expand Up @@ -166,11 +166,11 @@ Copyright (C) 2016 Xamarin. All rights reserved.
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ReferencePath>
<Compile Remove="$(_AndroidResourceDesignerFile)" />
<Compile Include="$(_GenerateResourceDesignerClassFile)" Condition=" '$(Language)' != 'F#' "/>
<Compile Include="$(_GenerateResourceDesignerClassFile)" Condition=" '$(Language)' != 'F#' And '$(AndroidGenerateResourceDesigner)' == 'true' "/>
<!-- For F# we need to use the CompileBefore ItemGroup so that our type is processed
before all the other types in the build. Otherwise we get weird compiler errors.
-->
<CompileBefore Include="$(_GenerateResourceDesignerClassFile)" Condition=" '$(Language)' == 'F#' "/>
<CompileBefore Include="$(_GenerateResourceDesignerClassFile)" Condition=" '$(Language)' == 'F#' And '$(AndroidGenerateResourceDesigner)' == 'true' "/>
</ItemGroup>
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<AndroidEnableSGenConcurrent Condition=" '$(AndroidEnableSGenConcurrent)' == '' ">true</AndroidEnableSGenConcurrent>
<AndroidHttpClientHandlerType Condition=" '$(AndroidHttpClientHandlerType)' == '' and '$(UsingAndroidNETSdk)' == 'true' ">Xamarin.Android.Net.AndroidMessageHandler</AndroidHttpClientHandlerType>
<AndroidHttpClientHandlerType Condition=" '$(AndroidHttpClientHandlerType)' == '' and '$(UsingAndroidNETSdk)' != 'true' ">Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
<AndroidUseDesignerAssembly Condition=" '$(AndroidUseDesignerAssembly)' == '' ">true</AndroidUseDesignerAssembly>
<AndroidGenerateResourceDesigner Condition=" '$(AndroidUseDesignerAssembly)' == 'True' ">false</AndroidGenerateResourceDesigner>
<AndroidGenerateResourceDesigner Condition=" '$(AndroidGenerateResourceDesigner)' == '' ">true</AndroidGenerateResourceDesigner>
<AndroidUseDesignerAssembly Condition=" '$(AndroidUseDesignerAssembly)' == '' ">true</AndroidUseDesignerAssembly>
<AndroidUseIntermediateDesignerFile Condition=" '$(AndroidUseDesignerAssembly)' == 'True' ">false</AndroidUseIntermediateDesignerFile>
<AndroidUseIntermediateDesignerFile Condition=" '$(AndroidUseIntermediateDesignerFile)' == '' ">$(AndroidGenerateResourceDesigner)</AndroidUseIntermediateDesignerFile>
<GenerateDependencyFile Condition=" '$(GenerateDependencyFile)' == '' ">false</GenerateDependencyFile>
<CopyLocalLockFileAssemblies Condition=" '$(CopyLocalLockFileAssemblies)' == '' ">false</CopyLocalLockFileAssemblies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,54 @@ public void AppWithSingleJar ()
}

[Test]
public void GenerateResourceDesigner_false()
public void GenerateResourceDesigner([Values (false, true)] bool generateResourceDesigner, [Values (false, true)] bool useDesignerAssembly)
{
var path = Path.Combine ("temp", TestName);
var libraryB = new XASdkProject (outputType: "Library") {
ProjectName = "LibraryB",
};
libraryB.Sources.Clear ();
libraryB.Sources.Add (new BuildItem.Source ("Foo.cs") {
TextContent = () => @"namespace LibraryB;
public class Foo {
public static int foo => Resource.Drawable.foo;
}",
});
libraryB.Sources.Add (new AndroidItem.AndroidResource (() => "Resources\\drawable\\foo.png") {
BinaryContent = () => XamarinAndroidCommonProject.icon_binary_mdpi,
});
libraryB.SetProperty ("AndroidUseDesignerAssembly", useDesignerAssembly.ToString ());
var libraryA = new XASdkProject (outputType: "Library") {
ProjectName = "LibraryA",
};
libraryA.Sources.Clear ();
libraryA.Sources.Add (new BuildItem.Source ("FooA.cs") {
TextContent = () => @"namespace LibraryA;
public class FooA {
public int foo => 0;
public int foo2 => LibraryB.Foo.foo;
public int foo3 => LibraryB.Resource.Drawable.foo;
}",
});
libraryA.AddReference (libraryB);
libraryA.SetProperty ("AndroidGenerateResourceDesigner", generateResourceDesigner.ToString ());
if (!useDesignerAssembly)
libraryA.SetProperty ("AndroidUseDesignerAssembly", "False");
var libraryBBuilder = CreateDotNetBuilder (libraryB, Path.Combine (path, libraryB.ProjectName));
Assert.IsTrue (libraryBBuilder.Build (), "Build of LibraryB should succeed.");
var libraryABuilder = CreateDotNetBuilder (libraryA, Path.Combine (path, libraryA.ProjectName));
Assert.IsTrue (libraryABuilder.Build (), "Build of LibraryA should succeed.");
var proj = new XASdkProject () {
ProjectName = "App1",
};
proj.SetProperty ("AndroidUseDesignerAssembly", useDesignerAssembly.ToString ());
proj.AddReference (libraryA);
var dotnet = CreateDotNetBuilder (proj, Path.Combine (path, proj.ProjectName));
Assert.IsTrue (dotnet.Build (), "Build of Proj should succeed.");
}

[Test]
public void GenerateResourceDesigner_false([Values (false, true)] bool useDesignerAssembly)
{
var proj = new XASdkProject (outputType: "Library") {
Sources = {
Expand All @@ -466,7 +513,8 @@ public void GenerateResourceDesigner_false()
};
// Turn off Resource.designer.cs and remove usage of it
proj.SetProperty ("AndroidGenerateResourceDesigner", "false");
proj.SetProperty ("AndroidUseDesignerAssembly", "false");
if (!useDesignerAssembly)
proj.SetProperty ("AndroidUseDesignerAssembly", "false");
proj.MainActivity = proj.DefaultMainActivity
.Replace ("Resource.Layout.Main", "0")
.Replace ("Resource.Id.myButton", "0");
Expand All @@ -475,11 +523,15 @@ public void GenerateResourceDesigner_false()
Assert.IsTrue (dotnet.Build(target: "CoreCompile", parameters: new string[] { "BuildingInsideVisualStudio=true" }), "Designtime build should succeed.");
var intermediate = Path.Combine (FullProjectDirectory, proj.IntermediateOutputPath);
var resource_designer_cs = Path.Combine (intermediate, "designtime", "Resource.designer.cs");
if (useDesignerAssembly)
resource_designer_cs = Path.Combine (intermediate, "__Microsoft.Android.Resource.Designer.cs");
FileAssert.DoesNotExist (resource_designer_cs);

Assert.IsTrue (dotnet.Build (), "build should succeed");

resource_designer_cs = Path.Combine (intermediate, "Resource.designer.cs");
resource_designer_cs = Path.Combine (intermediate, "Resource.designer.cs");
if (useDesignerAssembly)
resource_designer_cs = Path.Combine (intermediate, "__Microsoft.Android.Resource.Designer.cs");
FileAssert.DoesNotExist (resource_designer_cs);

var assemblyPath = Path.Combine (FullProjectDirectory, proj.OutputPath, $"{proj.ProjectName}.dll");
Expand Down
2 changes: 2 additions & 0 deletions src/monodroid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ set(XAMARIN_MONODROID_SOURCES
${SOURCES_DIR}/embedded-assemblies.cc
${SOURCES_DIR}/embedded-assemblies-zip.cc
${SOURCES_DIR}/globals.cc
${SOURCES_DIR}/helpers.cc
${SOURCES_DIR}/logger.cc
${SOURCES_DIR}/jni-remapping.cc
${SOURCES_DIR}/monodroid-glue.cc
Expand Down Expand Up @@ -564,6 +565,7 @@ set(XAMARIN_DEBUG_APP_HELPER_SOURCES
${SOURCES_DIR}/basic-utilities.cc
${SOURCES_DIR}/cpu-arch-detect.cc
${SOURCES_DIR}/debug-app-helper.cc
${SOURCES_DIR}/helpers.cc
${SOURCES_DIR}/new_delete.cc
${SOURCES_DIR}/shared-constants.cc
)
Expand Down
3 changes: 2 additions & 1 deletion src/monodroid/jni/cpp-util.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "cppcompat.hh"
#include "platform-compat.hh"
#include "helpers.hh"

static inline void
do_abort_unless (const char* fmt, ...)
Expand All @@ -32,7 +33,7 @@ do_abort_unless (const char* fmt, ...)
#endif // ndef ANDROID
va_end (ap);

std::abort ();
xamarin::android::Helpers::abort_application ();
}

#define abort_unless(_condition_, _fmt_, ...) \
Expand Down
4 changes: 3 additions & 1 deletion src/monodroid/jni/cxx-abi/terminate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
#include <cstdlib>
#include <android/log.h>

#include "helpers.hh"

namespace std {
[[noreturn]] void
terminate () noexcept
{
__android_log_write (ANDROID_LOG_FATAL, "monodroid", "std::terminate() called. Aborting.");
abort ();
xamarin::android::Helpers::abort_application ();
}
}
4 changes: 2 additions & 2 deletions src/monodroid/jni/debug-app-helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Java_mono_android_DebugRuntime_init (JNIEnv *env, [[maybe_unused]] jclass klass,
void *monosgen = dlopen (monosgen_path, RTLD_LAZY | RTLD_GLOBAL);
if (monosgen == nullptr) {
log_fatal (LOG_DEFAULT, "Failed to dlopen Mono runtime from %s: %s", monosgen_path, dlerror ());
exit (FATAL_EXIT_CANNOT_FIND_LIBMONOSGEN);
Helpers::abort_application ();
}
}

Expand Down Expand Up @@ -276,7 +276,7 @@ get_libmonosgen_path ()

log_fatal (LOG_DEFAULT, "Do you have a shared runtime build of your app with AndroidManifest.xml android:minSdkVersion < 10 while running on a 64-bit Android 5.0 target? This combination is not supported.");
log_fatal (LOG_DEFAULT, "Please either set android:minSdkVersion >= 10 or use a build without the shared runtime (like default Release configuration).");
exit (FATAL_EXIT_CANNOT_FIND_LIBMONOSGEN);
Helpers::abort_application ();

return libmonoso;
}
Expand Down
4 changes: 2 additions & 2 deletions src/monodroid/jni/debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ Debug::start_debugging_and_profiling ()
DebuggerConnectionStatus res = start_connection (connect_args);
if (res == DebuggerConnectionStatus::Error) {
log_fatal (LOG_DEBUGGER, "Could not start a connection to the debugger with connection args '%s'.", connect_args);
exit (FATAL_EXIT_DEBUGGER_CONNECT);
Helpers::abort_application ();
} else if (res == DebuggerConnectionStatus::Connected) {
/* Wait for XS to configure debugging/profiling */
gettimeofday(&wait_tv, nullptr);
Expand Down Expand Up @@ -655,7 +655,7 @@ xamarin::android::conn_thread (void *arg)
res = instance->handle_server_connection ();
if (res && res != 3) {
log_fatal (LOG_DEBUGGER, "Error communicating with the IDE, exiting...");
exit (FATAL_EXIT_DEBUGGER_CONNECT);
Helpers::abort_application ();
}

return nullptr;
Expand Down
22 changes: 11 additions & 11 deletions src/monodroid/jni/embedded-assemblies-zip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ EmbeddedAssemblies::zip_load_entry_common (size_t entry_index, std::vector<uint8
#endif
if (!result || entry_name.empty ()) {
log_fatal (LOG_ASSEMBLY, "Failed to read Central Directory info for entry %u in APK file %s", entry_index, state.apk_name);
exit (FATAL_EXIT_NO_ASSEMBLIES);
Helpers::abort_application ();
}

if (!zip_adjust_data_offset (state.apk_fd, state)) {
log_fatal (LOG_ASSEMBLY, "Failed to adjust data start offset for entry %u in APK file %s", entry_index, state.apk_name);
exit (FATAL_EXIT_NO_ASSEMBLIES);
Helpers::abort_application ();
}
#ifdef DEBUG
log_info (LOG_ASSEMBLY, " ZIP: local header offset: %u; data offset: %u; file size: %u", state.local_header_offset, state.data_offset, state.file_size);
Expand All @@ -79,7 +79,7 @@ EmbeddedAssemblies::zip_load_entry_common (size_t entry_index, std::vector<uint8
if ((state.data_offset & 0x3) != 0) {
log_fatal (LOG_ASSEMBLY, "Assembly '%s' is located at bad offset %lu within the .apk\n", entry_name.get (), state.data_offset);
log_fatal (LOG_ASSEMBLY, "You MUST run `zipalign` on %s\n", strrchr (state.apk_name, '/') + 1);
exit (FATAL_EXIT_MISSING_ZIPALIGN);
Helpers::abort_application ();
}

return true;
Expand Down Expand Up @@ -174,20 +174,20 @@ EmbeddedAssemblies::map_assembly_store (dynamic_local_string<SENSIBLE_PATH_MAX>
{
if (number_of_mapped_assembly_stores >= application_config.number_of_assembly_store_files) {
log_fatal (LOG_ASSEMBLY, "Too many assembly stores. Expected at most %u", application_config.number_of_assembly_store_files);
abort ();
Helpers::abort_application ();
}

md_mmap_info assembly_store_map = md_mmap_apk_file (state.apk_fd, state.data_offset, state.file_size, entry_name.get ());
auto header = static_cast<AssemblyStoreHeader*>(assembly_store_map.area);

if (header->magic != ASSEMBLY_STORE_MAGIC) {
log_fatal (LOG_ASSEMBLY, "Assembly store '%s' is not a valid Xamarin.Android assembly store file", entry_name.get ());
abort ();
Helpers::abort_application ();
}

if (header->version > ASSEMBLY_STORE_FORMAT_VERSION) {
log_fatal (LOG_ASSEMBLY, "Assembly store '%s' uses format v%u which is not understood by this version of Xamarin.Android", entry_name.get (), header->version);
abort ();
Helpers::abort_application ();
}

if (header->store_id >= application_config.number_of_assembly_store_files) {
Expand All @@ -198,13 +198,13 @@ EmbeddedAssemblies::map_assembly_store (dynamic_local_string<SENSIBLE_PATH_MAX>
header->store_id,
application_config.number_of_assembly_store_files
);
abort ();
Helpers::abort_application ();
}

AssemblyStoreRuntimeData &rd = assembly_stores[header->store_id];
if (rd.data_start != nullptr) {
log_fatal (LOG_ASSEMBLY, "Assembly store '%s' has a duplicate ID (%u)", entry_name.get (), header->store_id);
abort ();
Helpers::abort_application ();
}

constexpr size_t header_size = sizeof(AssemblyStoreHeader);
Expand Down Expand Up @@ -277,7 +277,7 @@ EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unus

if (!zip_read_cd_info (fd, cd_offset, cd_size, cd_entries)) {
log_fatal (LOG_ASSEMBLY, "Failed to read the EOCD record from APK file %s", apk_name);
exit (FATAL_EXIT_NO_ASSEMBLIES);
Helpers::abort_application ();
}
#ifdef DEBUG
log_info (LOG_ASSEMBLY, "Central directory offset: %u", cd_offset);
Expand All @@ -287,7 +287,7 @@ EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unus
off_t retval = ::lseek (fd, static_cast<off_t>(cd_offset), SEEK_SET);
if (retval < 0) {
log_fatal (LOG_ASSEMBLY, "Failed to seek to central directory position in the APK file %s. %s (result: %d; errno: %d)", apk_name, std::strerror (errno), retval, errno);
exit (FATAL_EXIT_NO_ASSEMBLIES);
Helpers::abort_application ();
}

std::vector<uint8_t> buf (cd_size);
Expand All @@ -306,7 +306,7 @@ EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unus
ssize_t nread = read (fd, buf.data (), static_cast<read_count_type>(buf.size ()));
if (static_cast<size_t>(nread) != cd_size) {
log_fatal (LOG_ASSEMBLY, "Failed to read Central Directory from the APK archive %s. %s (nread: %d; errno: %d)", apk_name, std::strerror (errno), nread, errno);
exit (FATAL_EXIT_NO_ASSEMBLIES);
Helpers::abort_application ();
}

if (application_config.have_assembly_store) {
Expand Down
Loading

0 comments on commit 232d8da

Please sign in to comment.