Skip to content

Commit

Permalink
Add basic linux support
Browse files Browse the repository at this point in the history
  • Loading branch information
UncraftedName committed Jul 9, 2023
1 parent 4013389 commit 48ef22a
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 200 deletions.
41 changes: 30 additions & 11 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,31 @@ on:

jobs:
build:
strategy:
fail-fast: false
matrix:
platform:
- {os: windows-latest, framework: net7.0-windows, runtime: win-x64}
- {os: ubuntu-latest, framework: net7.0, runtime: linux-x64}
build_type:
- {
name: 'Build',
configuration: Debug,
command: 'dotnet build ConsoleApp --no-self-contained',
}
- {
name: 'Publish to single file',
configuration: Release,
command: 'dotnet publish ConsoleApp -p:PublishSingleFile=true --self-contained',
}
- {
name: 'Run tests',
configuration: Release,
command: 'dotnet test --logger "console;verbosity=detailed"',
}

runs-on: windows-latest
runs-on: ${{ matrix.platform.os }}
name: ${{ matrix.build_type.name }} (${{ matrix.build_type.configuration }}, ${{ matrix.platform.os }}

steps:
- name: Checkout Project
Expand All @@ -20,14 +43,10 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Add msbuild to PATH
uses: microsoft/[email protected]

- name: Build Debug
run: msbuild ConsoleApp\ConsoleApp.csproj -target:Rebuild -property:Configuration=Debug -restore
- name: Build Release
run: msbuild ConsoleApp\ConsoleApp.csproj -target:Rebuild -property:Configuration=Release -restore
- name: Publish to single executable
run: msbuild ConsoleApp\ConsoleApp.csproj -target:Rebuild /p:DeployOnBuild=true /p:PublishProfile=publish-single-file -restore
- name: Test
run: dotnet test --logger "console;verbosity=detailed" --configuration Release
- name: ${{ matrix.build_type.name }}
run: >
${{ matrix.build_type.command }}
--framework=${{ matrix.platform.framework }}
--runtime=${{ matrix.platform.runtime }}
--configuration=${{ matrix.build_type.configuration }}
8 changes: 4 additions & 4 deletions ConsoleApp/ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<ApplicationIcon>../github-resources/investigation.ico</ApplicationIcon>
<Platforms>AnyCPU;x64</Platforms>
<Configurations>Debug;Release;Debug_ProcessEnts</Configurations>
Expand All @@ -11,6 +10,7 @@
<AssemblyName>UntitledParser</AssemblyName>
<Nullable>enable</Nullable>
<WarningLevel>9999</WarningLevel>
<TargetFrameworks>net7.0;net7.0-windows</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug_ProcessEnts' ">
Expand Down Expand Up @@ -68,8 +68,8 @@

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<!--Make sure to update Utils.GetVersionString() if you edit this!-->
<Exec Command="git rev-list --count HEAD > version.txt"/>
<Exec Command="git branch --show-current >> version.txt"/>
<Exec Command="git describe --always --dirty --exclude=* >> version.txt"/>
<Exec Command="git rev-list --count HEAD &gt; version.txt" />
<Exec Command="git branch --show-current &gt;&gt; version.txt" />
<Exec Command="git describe --always --dirty --exclude=* &gt;&gt; version.txt" />
</Target>
</Project>
2 changes: 1 addition & 1 deletion ConsoleApp/src/DemoArgProcessing/DemoParserSubCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void FlattenDirectories(DemoParsingSetupInfo setupInfo) {
demoPath,
commonParent == ""
? demoPath.FullName
: PathExt.GetRelativePath(commonParent, demoPath.FullName)
: Path.GetRelativePath(commonParent, demoPath.FullName)
));
}

Expand Down
177 changes: 0 additions & 177 deletions ConsoleApp/src/PathExt.cs

This file was deleted.

2 changes: 2 additions & 0 deletions ConsoleApp/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ public static void Main(string[] args) {
Environment.ExitCode = 3;
}
Console.ResetColor();
if (!Utils.IsWindows())
Console.WriteLine(); // TODO: checkout why linux doesn't give us as many lines as windows
if (Utils.WillBeDestroyedOnExit())
Console.ReadLine();
}
Expand Down
12 changes: 10 additions & 2 deletions ConsoleApp/src/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

namespace ConsoleApp {
Expand Down Expand Up @@ -108,13 +109,15 @@ public static string FormatTime(double seconds) {
public static string GetExeName() => QuoteIfHasSpaces(AppDomain.CurrentDomain.FriendlyName);


[System.Runtime.InteropServices.DllImport("kernel32.dll")]
[DllImport("kernel32.dll")]
private static extern int GetConsoleProcessList(int[] buffer, int size);


// used to check if we should use ReadKey() once we finish
public static bool WillBeDestroyedOnExit() {
return !Debugger.IsAttached && GetConsoleProcessList(new int[2], 2) <= 1;
if (IsWindows())
return !Debugger.IsAttached && GetConsoleProcessList(new int[2], 2) <= 1;
return false; // TODO this is a bit of a hack, see if there's a better solution on linux
}


Expand All @@ -140,8 +143,13 @@ public static bool WillBeDestroyedOnExit() {
}


public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);


// microsoft, you autocomplete dir to '.\dir name\' and then that last single quote escapes into a double quote which fucks everything
public static string[] FixPowerShellBullshit(string[] args) {
if (!IsWindows())
return args;
// example input: '.\nosla 12 50 89\' '.\nosla 12 50 89\' gets converted to [.\nosla 12 50 89" .\nosla, 12, 50, 89"]
var newArgs = new List<string>();
bool fixing = false;
Expand Down
2 changes: 1 addition & 1 deletion DemoParser/DemoParser.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFrameworks>net7.0;net7.0-windows</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Title>UntitledDemoParser</Title>
<Authors>UncraftedName</Authors>
Expand Down
2 changes: 1 addition & 1 deletion Tests/Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFrameworks>net7.0;net7.0-windows</TargetFrameworks>
<IsPackable>false</IsPackable>
<Platforms>AnyCPU;x64</Platforms>
<Configurations>Debug;Release;Debug_ProcessEnts</Configurations>
Expand Down
27 changes: 24 additions & 3 deletions Tests/src/DemoParseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,30 @@ public abstract class DemoParseTests {
private static readonly Dictionary<string, byte[]> RawDemoDataLookup = RawDemoDataLookup = new Dictionary<string, byte[]>();
private static bool _loaded;

public static readonly string ProjectDir =
// bin/Debug/net461 -> ../../..
Directory.GetParent(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!)!.Parent!.Parent!.FullName;
private static string _projectDir;
public static string ProjectDir {
get {
if (_projectDir != null)
return _projectDir;
/*
* I keep running into stupid issues with the executable being nested at different levels in the
* bin folder, and it seems like C# doesn't provide a way for us to know what the project folder
* is (maybe there's some assembly attribute stuff I could use?). So I'll just iterate up the
* folders until I get to the project folder; this should always work and will throw exceptions
* when it doesn't.
*/
string projectName = Assembly.GetCallingAssembly().GetName().Name!;
string dir = Path.GetFullPath(Environment.CurrentDirectory);
for (int i = 0; i < 10; i++) {
if (dir.EndsWith(projectName, StringComparison.OrdinalIgnoreCase)) {
_projectDir = dir;
return _projectDir;
}
dir = Directory.GetParent(dir)!.FullName;
}
throw new DirectoryNotFoundException($"Could not find directory '{projectName}'");
}
}


[OneTimeSetUp]
Expand Down
1 change: 1 addition & 0 deletions publish-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotnet publish ConsoleApp --runtime=linux-x64 --framework=net7.0 -p:PublishSingleFile=true --self-contained=true --configuration=Release

0 comments on commit 48ef22a

Please sign in to comment.