Skip to content

Conversation

@finagolfin
Copy link
Contributor

@finagolfin finagolfin commented Feb 20, 2024

Motivation:

Get the new module building and tested on my Android CI again (I had to make a few extra modifications there to get this working with the older Android API 24 that I test on my CI)

Modifications:

  • Add force unwraps where needed
  • Update C types and account for nullability annotations in NDK 26
  • Use /data/local/tmp for the temporaryDirectory and invoke it in the tests, instead of /tmp directly
  • Don't copy over extended attributes
  • Android doesn't support hard-linking on most partitions, so don't use it for materializing temporary files

Result:

Everything works again on Android

@glbrntt, please review.

options: options,
permissions: permissions,
executor: executor,
useTemporaryFileIfPossible: false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@finagolfin
Copy link
Contributor Author

5.8 test run timed out for some reason, while nightly CI has been broken for awhile.

import Atomics
import NIOCore
@preconcurrency import SystemPackage
import class Foundation.FileManager
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NIOFilsystem module is intentionally not depending on Foundation. Is there a way to solve this without using Foundation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know that, will revert this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I would like @glbrntt to also take a quick look before we merge this

Copy link
Contributor

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, left a couple of nits.

Comment on lines 1123 to 1124
#if os(Android)
return Self.syncOpenWithMaterialization(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than duping the whole call, can we conditionalise just useTemporaryFileIfPossible? i.e.

#if os(Android)
let useTemporaryFileIfPossible = false
#else
let useTemporaryFileIfPossible = true
#endif

Makes it a little bit easier to see what the differences are.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

_ execute: @Sendable (SystemFileHandle) async throws -> Void
) async throws {
let path = FilePath("/tmp/\(Self.temporaryFileName())")
let path = FilePath("\(FileManager.default.temporaryDirectory.path)/\(Self.temporaryFileName())")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use FileSystem.shared.temporaryDirectory instead of FileManager?

Copy link
Contributor Author

@finagolfin finagolfin Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not, as that uses a hard-coded /tmp, which doesn't exist on Android. I had originally modified that method to use Foundation also, but removed it when asked above. I figured it was fine here in the tests, since they're already using Foundation, which is why I didn't have to add an import here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So FileSystem.shared.temporaryDirectory returns a bogus path on Android, we should fix that instead of resorting on FileManager here if possible. How does Foundation get the right tmp path on Android?

Copy link
Contributor Author

@finagolfin finagolfin Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should fix that instead of resorting on FileManager here if possible.

Something wrong with using Foundation methods here in the tests? It is already a dependency.

How does Foundation get the right tmp path on Android?

The logic is a bit convoluted, checking TMPDIR in the Termux app that runs natively on Android and defaulting to /data/local/tmp/ otherwise. I figured it's better to just invoke that Foundation method here, as I've done for other NIO test functions before.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just default to "/data/local/tmp" on Android then? The comment suggests TMPDIR is rarely set, so this would at least produce a less wrong answer on Android than "/tmp".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Motivation:

Get the new module building and tested on my Android CI again

Modifications:

- Add force unwraps where needed
- Update C types and account for nullability annotations in NDK 26
- Use /data/local/tmp for the `temporaryDirectory` and invoke it in the tests, instead of /tmp directly
- Don't copy over extended attributes
- Android doesn't support hard-linking on most partitions, so don't use it for materializing temporary files

Result:

Everything works again on Android
Copy link
Contributor

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@glbrntt
Copy link
Contributor

glbrntt commented Mar 5, 2024

@swift-server-bot test this please

@glbrntt glbrntt merged commit 53be205 into apple:main Mar 5, 2024
@finagolfin finagolfin deleted the droid branch March 5, 2024 16:17
@glbrntt glbrntt added the 🔨 semver/patch No public API change. label Mar 6, 2024
Lukasa pushed a commit that referenced this pull request Dec 15, 2024
I added this changed function call for Android in #2660 earlier this
year, because of [an incorrect Bionic function signature as explained
recently](#3009 (comment)),
but now that it has been worked around through a new API note as
mentioned there, this change is no longer needed.

I simply did not notice this earlier because it still compiles and
merely gives a warning, which removing this call now silences.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants