(ded4a3e0a) v0.9.0.7
This commit is contained in:
+191
@@ -0,0 +1,191 @@
|
||||
// MonoGame - Copyright (C) The MonoGame Team
|
||||
// This file is subject to the terms and conditions defined in
|
||||
// file 'LICENSE.txt', which is part of this source code package.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Microsoft.Build.Framework;
|
||||
using Microsoft.Build.Utilities;
|
||||
|
||||
namespace MonoGame.Packaging
|
||||
{
|
||||
public class BuildFlatpakTask : Task
|
||||
{
|
||||
[Required]
|
||||
public string IntermediateDir { get; set; }
|
||||
|
||||
[Required]
|
||||
public string OutputPath { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ProjectDir { get; set; }
|
||||
|
||||
[Required]
|
||||
public string PublishDir { get; set; }
|
||||
|
||||
[Required]
|
||||
public string AssemblyName { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Title { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string IconPath { get; set; }
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.LogMessage(MessageImportance.Normal, "BuildFlatpakTask: Starting...");
|
||||
|
||||
// Ensure that flatpak command is installed
|
||||
if (!IsFlatpakInstalled())
|
||||
{
|
||||
Log.LogMessage(MessageImportance.High, "Flatpak command not found :(");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ensure that flatpak runtimes are installed
|
||||
if (!AreFlatpakRuntimesInstalled())
|
||||
{
|
||||
Log.LogMessage(MessageImportance.High, "Error, the requred flatpak runtime components were not found:");
|
||||
Log.LogMessage(MessageImportance.High, " - org.freedesktop.Platform/x86_64/1.6");
|
||||
Log.LogMessage(MessageImportance.High, " - org.freedesktop.Sdk/x86_64/1.6");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Setup intermediate directory
|
||||
var objpath = Path.Combine(ProjectDir, IntermediateDir, "Flatpak");
|
||||
if (Directory.Exists(objpath))
|
||||
Directory.Delete(objpath, true);
|
||||
Directory.CreateDirectory(objpath);
|
||||
|
||||
// Generate metadata
|
||||
Log.LogMessage(MessageImportance.Normal, "BuildFlatpakTask: Generating metadata");
|
||||
var metadatalines = new[] {
|
||||
"[Application]",
|
||||
"name=" + Id,
|
||||
"runtime=org.freedesktop.Platform/x86_64/1.6",
|
||||
"command=/app/opt/" + AssemblyName + "/" + AssemblyName,
|
||||
"",
|
||||
"[Context]",
|
||||
"shared=ipc;network;",
|
||||
"sockets=x11;wayland;pulseaudio;",
|
||||
"devices=all;"
|
||||
};
|
||||
File.WriteAllLines(Path.Combine(objpath, "metadata"), metadatalines);
|
||||
|
||||
// Copy over icon
|
||||
Log.LogMessage(MessageImportance.Normal, "BuildFlatpakTask: Copying over icon");
|
||||
var icondir = Path.Combine(objpath, "export/share/icons");
|
||||
Directory.CreateDirectory(icondir);
|
||||
File.Copy(Path.Combine(ProjectDir, IconPath), Path.Combine(icondir, Id + ".png"));
|
||||
|
||||
// Generate .desktop launcher file
|
||||
Log.LogMessage(MessageImportance.Normal, "BuildFlatpakTask: Generating launcher file");
|
||||
var desktopdir = Path.Combine(objpath, "export/share/applications");
|
||||
Directory.CreateDirectory(desktopdir);
|
||||
var desktoplines = new[] {
|
||||
"[Desktop Entry]",
|
||||
"Name=" + Title,
|
||||
"Exec=/app/opt/" + AssemblyName + "/" + AssemblyName,
|
||||
"Type=Application",
|
||||
"Icon=" + Id,
|
||||
"Categories=Game;"
|
||||
};
|
||||
File.WriteAllLines(Path.Combine(desktopdir, Id + ".desktop"), desktoplines);
|
||||
|
||||
// Copy over game
|
||||
Log.LogMessage(MessageImportance.Normal, "BuildFlatpakTask: Copying over game data");
|
||||
var sourcegamedir = Path.Combine(ProjectDir, PublishDir);
|
||||
var gamedir = Path.Combine(objpath, "files/opt/" + AssemblyName + "/");
|
||||
Directory.CreateDirectory(gamedir);
|
||||
foreach (var dirpath in Directory.GetDirectories(sourcegamedir, "*", SearchOption.AllDirectories))
|
||||
Directory.CreateDirectory(dirpath.Replace(sourcegamedir, gamedir));
|
||||
foreach (var filepath in Directory.GetFiles(sourcegamedir, "*.*", SearchOption.AllDirectories))
|
||||
File.Copy(filepath, filepath.Replace(sourcegamedir, gamedir));
|
||||
|
||||
// Copy over suplementary libraries
|
||||
var libdir = Path.Combine(Path.GetDirectoryName((new Uri(typeof(BuildFlatpakTask).Assembly.CodeBase)).LocalPath), "../../extra");
|
||||
Directory.CreateDirectory(Path.Combine(objpath, "files/lib"));
|
||||
File.Copy(Path.Combine(libdir, "libunwind-x86_64.so.8"), Path.Combine(objpath, "files/lib/libunwind-x86_64.so.8"));
|
||||
File.Copy(Path.Combine(libdir, "libunwind.so.8"), Path.Combine(objpath, "files/lib/libunwind.so.8"));
|
||||
File.Copy(Path.Combine(libdir, "libSDL2-2.0.so.0.8.0"), Path.Combine(objpath, "files/opt/" + AssemblyName + "/libSDL2-2.so"), true);
|
||||
|
||||
// Generate flatpak
|
||||
Log.LogMessage(MessageImportance.Normal, "BuildFlatpakTask: Generating flatpak");
|
||||
var repodir = Path.Combine(ProjectDir, IntermediateDir, "FlatpakRepo");
|
||||
if (Directory.Exists(repodir))
|
||||
Directory.Delete(repodir, true);
|
||||
Directory.CreateDirectory(repodir);
|
||||
var flatpak = Path.Combine(ProjectDir, OutputPath, AssemblyName + ".flatpak");
|
||||
CallFlatpak("build-export " + repodir + " " + objpath);
|
||||
CallFlatpak("build-bundle " + repodir + " " + flatpak + " " + Id);
|
||||
|
||||
Log.LogMessage(MessageImportance.High, "BuildFlatpakTask: Flatpak generated at: " + flatpak);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.LogMessage(MessageImportance.High, "An error occured while trying to package the project into a flatpak.");
|
||||
Log.LogMessage(MessageImportance.High, "Error Info: " + e.ToString());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool IsFlatpakInstalled()
|
||||
{
|
||||
var proc = new Process();
|
||||
proc.StartInfo.FileName = "which";
|
||||
proc.StartInfo.Arguments = "flatpak";
|
||||
proc.StartInfo.UseShellExecute = false;
|
||||
proc.StartInfo.RedirectStandardOutput = true;
|
||||
proc.Start();
|
||||
proc.StandardOutput.ReadToEnd();
|
||||
|
||||
return proc.ExitCode == 0;
|
||||
}
|
||||
|
||||
private bool AreFlatpakRuntimesInstalled()
|
||||
{
|
||||
var rt = false;
|
||||
var rtsdk = false;
|
||||
var proc = new Process();
|
||||
proc.StartInfo.FileName = "flatpak";
|
||||
proc.StartInfo.Arguments = "list";
|
||||
proc.StartInfo.UseShellExecute = false;
|
||||
proc.StartInfo.RedirectStandardOutput = true;
|
||||
proc.Start();
|
||||
|
||||
while (!proc.StandardOutput.EndOfStream)
|
||||
{
|
||||
var line = proc.StandardOutput.ReadLine();
|
||||
if (line.Contains("org.freedesktop.Platform/x86_64/1.6"))
|
||||
rt = true;
|
||||
else if (line.Contains("org.freedesktop.Sdk/x86_64/1.6"))
|
||||
rtsdk = true;
|
||||
}
|
||||
|
||||
return rt && rtsdk;
|
||||
}
|
||||
|
||||
private void CallFlatpak(string args)
|
||||
{
|
||||
var proc = new Process();
|
||||
proc.StartInfo.FileName = "flatpak";
|
||||
proc.StartInfo.Arguments = args;
|
||||
proc.StartInfo.UseShellExecute = false;
|
||||
proc.StartInfo.RedirectStandardOutput = true;
|
||||
proc.Start();
|
||||
|
||||
while (!proc.StandardOutput.EndOfStream)
|
||||
Log.LogMessage(MessageImportance.Normal, proc.StandardOutput.ReadLine());
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net46</TargetFrameworks>
|
||||
<BuildOutputTargetFolder>tasks</BuildOutputTargetFolder>
|
||||
<PackageIconUrl>https://pbs.twimg.com/profile_images/487954549441691649/O3KsHAsb_400x400.png</PackageIconUrl>
|
||||
<PackageProjectUrl>http://monogame.net</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/MonoGame/MonoGame.git</RepositoryUrl>
|
||||
<Description>This package allows you to package up your MonoGame game into a flatpak installer for Linux.</Description>
|
||||
<PackageTags>monogame;.net core;core;packaging;flatpak</PackageTags>
|
||||
<Version>3.7.0.18</Version>
|
||||
<Authors>MonoGame Team</Authors>
|
||||
<PackageId>MonoGame.Packaging.Flatpak</PackageId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="MonoGame.Packaging.Flatpak.targets" PackagePath="build\MonoGame.Packaging.Flatpak.targets" />
|
||||
<Content Include="..\..\ThirdParty\Dependencies\FlatpakLibs\*" PackagePath="extra\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Build.Framework" Version="15.1.1012" />
|
||||
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.1.1012" />
|
||||
|
||||
<PackageReference Update="@(PackageReference)" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
**This package only works if you are targeting .NET Core.** This package allows you to package up your MonoGame game into a flatpak installer for Linux.
|
||||
|
||||
## Requirements:
|
||||
- netcoreapp as the target
|
||||
- flatpak
|
||||
- org.freedesktop.Platform/x86_64/1.6
|
||||
- org.freedesktop.Sdk/x86_64/1.6
|
||||
|
||||
Flatpak install instructions: [https://flatpak.org/setup/](https://flatpak.org/setup/)
|
||||
|
||||
To install the required runtimes, simply do:
|
||||
```sh
|
||||
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
|
||||
flatpak install flathub org.freedesktop.Platform/x86_64/1.6
|
||||
flatpak install flathub org.freedesktop.Sdk/x86_64/1.6
|
||||
```
|
||||
|
||||
## Usage:
|
||||
Call the publish command as you normally would: `dotnet publish -r linux-x64`, the resulting flatpak should get generated in the output directory.
|
||||
|
||||
## Customization:
|
||||
This nuget package offers the following properties for customizing the build of the flatpak. Simply set them in the csproj or pass them to msbuild to change their values:
|
||||
|
||||
```
|
||||
| Variable Name | Description / Default value |
|
||||
| ------------------------ | -------------------------------------- |
|
||||
| MGFlatpakIntermediateDir | Folder for temporary files. |
|
||||
| | $(IntermediateOutputPath) |
|
||||
| ------------------------ | -------------------------------------- |
|
||||
| MGFlatpakOutputPath | The output folder for the flatpak. |
|
||||
| | $(OutputPath) |
|
||||
| ------------------------ | -------------------------------------- |
|
||||
| MGFlatpakProjectDir | The current project directory. |
|
||||
| | $(ProjectDir) |
|
||||
| ------------------------ | -------------------------------------- |
|
||||
| MGFlatpakPublishDir | The publish output folder. |
|
||||
| | $(PublishDir) |
|
||||
| ------------------------ | -------------------------------------- |
|
||||
| MGFlatpakAssemblyName | The output assembly to run. |
|
||||
| | $(AssemblyName) |
|
||||
| ------------------------ | -------------------------------------- |
|
||||
| MGFlatpakTitle | The game title. |
|
||||
| | $(AssemblyTitle) |
|
||||
| ------------------------ | -------------------------------------- |
|
||||
| MGFlatpakId | The game id. |
|
||||
| | com.$(Company).$(AssemblyName) |
|
||||
| ------------------------ | -------------------------------------- |
|
||||
| MGFlatpakIcon | The icon file, needs to be png format. |
|
||||
| | Icon.png |
|
||||
```
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- Select correct MSBuild task assembly. -->
|
||||
<MGFlatpakFoler Condition=" '$(MSBuildRuntimeType)' == 'Core' ">netstandard2.0</MGFlatpakFoler>
|
||||
<MGFlatpakFoler Condition=" '$(MSBuildRuntimeType)' != 'Core' ">net46</MGFlatpakFoler>
|
||||
<MGFlatpakTaskAssembly>$(MSBuildThisFileDirectory)..\tasks\$(MGFlatpakFoler)\MonoGame.Packaging.Flatpak.dll</MGFlatpakTaskAssembly>
|
||||
|
||||
<!-- Init task properties -->
|
||||
<MGFlatpakIntermediateDir Condition=" '$(MGFlatpakIntermediateDir)' == '' ">$(IntermediateOutputPath)</MGFlatpakIntermediateDir>
|
||||
<MGFlatpakOutputPath Condition=" '$(MGFlatpakOutputPath)' == '' ">$(OutputPath)</MGFlatpakOutputPath>
|
||||
<MGFlatpakProjectDir Condition=" '$(MGFlatpakProjectDir)' == '' ">$(ProjectDir)</MGFlatpakProjectDir>
|
||||
<MGFlatpakPublishDir Condition=" '$(MGFlatpakPublishDir)' == '' ">$(PublishDir)</MGFlatpakPublishDir>
|
||||
<MGFlatpakAssemblyName Condition=" '$(MGFlatpakAssemblyName)' == '' ">$(AssemblyName)</MGFlatpakAssemblyName>
|
||||
<MGFlatpakTitle Condition=" '$(MGFlatpakTitle)' == '' ">$(AssemblyTitle)</MGFlatpakTitle>
|
||||
<MGFlatpakId Condition=" '$(MGFlatpakId)' == '' ">com.$(Company).$(AssemblyName)</MGFlatpakId>
|
||||
<MGFlatpakIcon Condition=" '$(MGFlatpakIcon)' == '' ">Icon.png</MGFlatpakIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<UsingTask TaskName="MonoGame.Packaging.BuildFlatpakTask" AssemblyFile="$(MGFlatpakTaskAssembly)" />
|
||||
|
||||
<Target Name="PackageFlatpak" AfterTargets="Publish" Condition=" '$(RuntimeIdentifier)'=='linux-x64' ">
|
||||
<BuildFlatpakTask IntermediateDir="$(MGFlatpakIntermediateDir)"
|
||||
OutputPath="$(MGFlatpakOutputPath)"
|
||||
ProjectDir="$(MGFlatpakProjectDir)"
|
||||
PublishDir="$(MGFlatpakPublishDir)"
|
||||
AssemblyName="$(MGFlatpakAssemblyName)"
|
||||
Title="$(MGFlatpakTitle)"
|
||||
Id="$(MGFlatpakId)"
|
||||
IconPath="$(MGFlatpakIcon)" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user