Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jnimarshalmethod-gen] Update the originating assembly #300

Merged
merged 2 commits into from
Apr 18, 2018

Conversation

radekdoulik
Copy link
Member

Update the originating assembly instead of creating a new one,
called <AssemblyName>-new.dll

I expected I would need to load the originating assembly in the
separate AppDomain, but instead it was enough to load it with cecil
with reading parameters having ReadWrite = true.

Because the referenced assemblies might not be writable, we need to
keep loading them as read only, thus with default ReadWrite = false.

For that I added new method to our cecil assembly resolver, to add
existing assembly definition to its cache. We first read the
originating assemblies as ReadWrite and add them to the resolver
cache.

Update the originating assembly instead of creating a *new* one,
called `<AssemblyName>-new.dll`

I expected I would need to load the originating assembly in the
separate AppDomain, but instead it was enough to load it with cecil
with reading parameters having `ReadWrite = true`.

Because the referenced assemblies might not be writable, we need to
keep loading them as read only, thus with default `ReadWrite = false`.

For that I added new method to our cecil assembly resolver, to add
existing assembly definition to its cache. We first read the
originating assemblies as *ReadWrite* and add them to the resolver
cache.
@radekdoulik radekdoulik requested a review from jonpryor April 18, 2018 11:43
@jonpryor
Copy link
Member

Question: can this be changed to instead:

  1. By default not "generate" a *-JniMarshalMethods.dll assembly. (It could still be created as part of operation, but should be deleted before process exit.)

  2. Add a jnimarshalmethod-gen.exe --keeptemp option which preserves the *-JniMarshalMethods.dll assembly.

This would remove the need to explicitly remove the *-JniMarshalMethods.dll assembly within Makefile

@radekdoulik
Copy link
Member Author

I plan to add an option to do that. This PR is not related to *-JniMarshalMethods.dll though, it removes *-new.dll creation.

@jonpryor jonpryor merged commit a4a7fda into dotnet:master Apr 18, 2018
jonpryor added a commit to jonpryor/java.interop that referenced this pull request Aug 25, 2021
)

Commit 8898bc1 put too much faith into `$(MSBuildProjectDirectory)).
The problem is that `$(MSBuildProjectDirectory)` *isn't necessarily*
the path to `Directory.Build.props`; it's the directory for the
`.csproj` being built!

The *intent* for 8898bc1 is that e.g. `xamarin/xamarin-android`
should be able to create a `Java.Interop.override.props` file
alongside the `Java.Interop` git submodule, and the Java.Interop
build would use the overrides within `Java.Interop.override.props`.

That didn't happen; due to using `$(MSBuildProjectDirectory)`, the
build may instead attempting to import e.g.
`Java.Interop/src/Java.Interop.override.props`!

        Project "$(MSBuildProjectDirectory).override.props" was not imported by "…/external/Java.Interop/Directory.Build.props" at (6,3), due to false condition;
        (Exists('$(MSBuildProjectDirectory).override.props')) was evaluated as
        (Exists('…/xamarin-android/external/Java.Interop/src/Java.Interop.override.props')).

Oops.

Fix the `<Import/>` expressions so that we instead try to import:

        $([System.IO.Path]::GetDirectoryName($(MSBuildThisFileDirectory))).override.props

We need `$(MSBuildThisFileDirectory)`, as that's the easiest way to
get the checkout directory -- the directory containing
`Directory.Build.props` -- but `$(MSBuildThisFileDirectory)` always
ends in a directory separator character.  Remove the directory
separator character by using `Path.GetDirectoryName()`.

This allows e.g. the `Java.Interop.csproj` build to appropriately
import `Java.Interop.override.props`.
jonpryor added a commit that referenced this pull request Aug 25, 2021
…873)

Commit 8898bc1 put too much faith into `$(MSBuildProjectDirectory)).
The problem is that `$(MSBuildProjectDirectory)` *isn't necessarily*
the path to `Directory.Build.props`; it's the directory for the
`.csproj` being built!

The *intent* for 8898bc1 is that e.g. `xamarin/xamarin-android`
should be able to create a `Java.Interop.override.props` file
alongside the `Java.Interop` git submodule, and the Java.Interop
build would use the overrides within `Java.Interop.override.props`.

That didn't happen; due to using `$(MSBuildProjectDirectory)`, the
build may instead attempting to import e.g.
`Java.Interop/src/Java.Interop.override.props`!

        Project "$(MSBuildProjectDirectory).override.props" was not imported by "…/external/Java.Interop/Directory.Build.props" at (6,3), due to false condition;
        (Exists('$(MSBuildProjectDirectory).override.props')) was evaluated as
        (Exists('…/xamarin-android/external/Java.Interop/src/Java.Interop.override.props')).

Oops.

Fix the `<Import/>` expressions so that we instead try to import:

        $([System.IO.Path]::GetDirectoryName($(MSBuildThisFileDirectory))).override.props

We need `$(MSBuildThisFileDirectory)`, as that's the easiest way to
get the checkout directory -- the directory containing
`Directory.Build.props` -- but `$(MSBuildThisFileDirectory)` always
ends in a directory separator character.  Remove the directory
separator character by using `Path.GetDirectoryName()`.

This allows e.g. the `Java.Interop.csproj` build to appropriately
import `Java.Interop.override.props`.
jpobst pushed a commit that referenced this pull request Sep 30, 2021
…873)

Commit 8898bc1 put too much faith into `$(MSBuildProjectDirectory)).
The problem is that `$(MSBuildProjectDirectory)` *isn't necessarily*
the path to `Directory.Build.props`; it's the directory for the
`.csproj` being built!

The *intent* for 8898bc1 is that e.g. `xamarin/xamarin-android`
should be able to create a `Java.Interop.override.props` file
alongside the `Java.Interop` git submodule, and the Java.Interop
build would use the overrides within `Java.Interop.override.props`.

That didn't happen; due to using `$(MSBuildProjectDirectory)`, the
build may instead attempting to import e.g.
`Java.Interop/src/Java.Interop.override.props`!

        Project "$(MSBuildProjectDirectory).override.props" was not imported by "…/external/Java.Interop/Directory.Build.props" at (6,3), due to false condition;
        (Exists('$(MSBuildProjectDirectory).override.props')) was evaluated as
        (Exists('…/xamarin-android/external/Java.Interop/src/Java.Interop.override.props')).

Oops.

Fix the `<Import/>` expressions so that we instead try to import:

        $([System.IO.Path]::GetDirectoryName($(MSBuildThisFileDirectory))).override.props

We need `$(MSBuildThisFileDirectory)`, as that's the easiest way to
get the checkout directory -- the directory containing
`Directory.Build.props` -- but `$(MSBuildThisFileDirectory)` always
ends in a directory separator character.  Remove the directory
separator character by using `Path.GetDirectoryName()`.

This allows e.g. the `Java.Interop.csproj` build to appropriately
import `Java.Interop.override.props`.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants