Skip to content

Create FileSystem.SYSTEM property in shared source set#1455

Merged
swankjesse merged 3 commits intosquare:masterfrom
zsmb13:system-file-system
Mar 12, 2024
Merged

Create FileSystem.SYSTEM property in shared source set#1455
swankjesse merged 3 commits intosquare:masterfrom
zsmb13:system-file-system

Conversation

@zsmb13
Copy link
Copy Markdown
Contributor

@zsmb13 zsmb13 commented Mar 11, 2024

This PR creates a new source set called systemFileSystem that jvm and native depend on, and makes FileSystem.SYSTEM available there.

We can't remove the existing SYSTEM declarations in the companion objects of FileSystem, and we can't introduce a companion object in the shared source set as it could not be further refined in more specific source sets.

Therefore, this new declaration is added as an expect extension on the companion. This lets code targeting JVM and native platforms resolve to the extension in common code, while they will actually use the properties of the companions directly when compiled.

To make this change easier to test, we add additional platforms to the samples project, and a sample function that exercises the new property.

Copy link
Copy Markdown
Collaborator

@JakeWharton JakeWharton left a comment

Choose a reason for hiding this comment

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

Clever! LGTM once the sample build issues are fixed.

import okio.Path.Companion.toPath
import okio.SYSTEM

class MultiplatformFileSystem {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe skip this new sample, and instead delete SYSTEM_FILE_SYSTEM from TestingJvm.kt and TestingNative.kt ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, added this change.

Copy link
Copy Markdown
Collaborator

@swankjesse swankjesse left a comment

Choose a reason for hiding this comment

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

Long overdue. Nice fix.

@zsmb13 zsmb13 marked this pull request as ready for review March 12, 2024 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants