compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

[Request] Support passing Linux package deps when creating .deb file

Open garret-gunter opened this issue 2 years ago • 2 comments

Description

It would be nice to be able to pass extra dependencies to jpackage using the --linux-package-deps flag. It should easy to implement as it will only require adding a new field to LinuxPlatformSettings and AbstractJPackageTask. And then alterations to AbstractJPackageTask.makeArgs and AbstractJPackageTask.configurePlatformSettings. I'm willing to make a pull request if this feature is approved.

Proposed Changes

Example configuration:

compose.desktop {
    application {
        mainClass = "MainKt"
        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "example"
            packageVersion = "1.0.0"
            vendor = "Example Vendor"
            linux {
                shortcut = true
                packageDeps = "foo [i386], bar [amd64]" // New field
            }
        }
    }
}

org.jetbrains.compose.desktop.application.dsl.LinuxPlatformSettings:

open class LinuxPlatformSettings @Inject constructor(objects: ObjectFactory): PlatformSettings(objects) {
    var shortcut: Boolean = false
    var packageName: String? = null
    var appRelease: String? = null
    var appCategory: String? = null
    var debMaintainer: String? = null
    var menuGroup: String? = null
    var rpmLicenseType: String? = null
    var debPackageVersion: String? = null
    var rpmPackageVersion: String? = null
    var packageDeps: String? = null // New field
}

org.jetbrains.compose.desktop.application.internal.AbstractJPackageTask.configurePlatformSettings:

internal fun AbstractJPackageTask.configurePlatformSettings(app: Application) {
// ...
when (currentOS) {
        OS.Linux -> {
            app.nativeDistributions.linux.also { linux ->
                linuxShortcut.set(provider { linux.shortcut })
                linuxAppCategory.set(provider { linux.appCategory })
                linuxAppRelease.set(provider { linux.appRelease })
                linuxDebMaintainer.set(provider { linux.debMaintainer })
                linuxMenuGroup.set(provider { linux.menuGroup })
                linuxPackageName.set(provider { linux.packageName })
                linuxRpmLicenseType.set(provider { linux.rpmLicenseType })
                iconFile.set(linux.iconFile.orElse(DefaultIcons.forLinux(project)))
                installationPath.set(linux.installationPath)
                linuxPackageDeps.set(linux.packageDeps) // New line
            }
        }
// ...
    }

// ...
}

org.jetbrains.compose.desktop.application.tasks.AbstractJPackageTask:

abstract class AbstractJPackageTask @Inject constructor(
    @get:Input
    val targetFormat: TargetFormat,
) : AbstractJvmToolOperationTask("jpackage") {
// ...

    @get:Input
    @get:Optional
    val linuxPackageDeps: Property<String?> = objects.nullableProperty() // New field

// ...

    override fun makeArgs(tmpDir: File): MutableList<String> = super.makeArgs(tmpDir).apply {
// ...

            when (currentOS) {
                OS.Linux -> {
                    cliArg("--linux-shortcut", linuxShortcut)
                    cliArg("--linux-package-name", linuxPackageName)
                    cliArg("--linux-app-release", linuxAppRelease)
                    cliArg("--linux-app-category", linuxAppCategory)
                    cliArg("--linux-deb-maintainer", linuxDebMaintainer)
                    cliArg("--linux-menu-group", linuxMenuGroup)
                    cliArg("--linux-rpm-license-type", linuxRpmLicenseType)
                    cliArg("--linux-package-deps", linuxPackageDeps) // New line
                }
                OS.Windows -> {
                    cliArg("--win-dir-chooser", winDirChooser)
                    cliArg("--win-per-user-install", winPerUserInstall)
                    cliArg("--win-shortcut", winShortcut)
                    cliArg("--win-menu", winMenu)
                    cliArg("--win-menu-group", winMenuGroup)
                    cliArg("--win-upgrade-uuid", winUpgradeUuid)
                }
            }

// ...
    }

// ...
}

garret-gunter avatar Aug 08 '22 14:08 garret-gunter

I would suggest multiple new variables instead of one, one for deb and one for rpm packages. The reason for this is, that deb packages often have different package names than their rpm equivalent. An example for this is the avahi client. On centos/fedora the package name is avahi-devel and on debian/ubuntu it is libavahi-client-dev

DSeeLP avatar Aug 09 '22 11:08 DSeeLP

@DSeeLP, I will implement an option for rpm packages too. I may need help testing that part of the pull request out. I'm not as familiar with rpm packages and environments.

garret-gunter avatar Aug 15 '22 16:08 garret-gunter