diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bbce20a9..ea0f6fa3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,75 +1,12 @@ -name: "main" +name: "Main" on: - push: - branches: - - main - tags: - - v* - paths-ignore: - - '**.md' + workflow_dispatch: pull_request: - branches: - - main - paths-ignore: - - '**.md' + types: [assigned, opened, synchronize, reopened] jobs: - dotnet-job: - name: ".NET" - runs-on: ${{ matrix.platform.os }} - strategy: - fail-fast: false - matrix: - platform: - - { name: Windows x64, os: windows-latest, shell: bash } - - { name: Linux x64, os: ubuntu-latest, shell: bash } - - { name: macOS x64, os: macos-latest, shell: bash } - defaults: - run: - shell: ${{ matrix.platform.shell }} - steps: - - - name: "Clone Git repository" - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: "Install Clang: Windows" - if: matrix.platform.os == 'windows-latest' - run: | - source "${{ github.workspace }}\.github\scripts\install-clang-x64-windows.sh" - - - name: "Install Clang: Linux" - if: matrix.platform.os == 'ubuntu-latest' - run: | - sudo apt-get update - sudo apt-get install gcc-aarch64-linux-gnu llvm-14 clang-14 - - - name: "Install .NET" - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '7.0.x' - include-prerelease: true - - - name: "Install CAstFfi" - shell: bash - run: dotnet tool install --global bottlenoselabs.CAstFfi.Tool - - - name: ".NET" - uses: bottlenoselabs/github-actions-dotnet@v3 - with: - dotnet-sdk-version: "7.0.x" - solution-or-project: "${{ github.workspace }}/src/cs/C2CS.sln" - is-enabled-upload-myget: "${{ matrix.platform.os == 'ubuntu-latest' && ( github.event_name == 'push' || startsWith(github.ref, 'refs/tags/v') ) }}" - is-enabled-upload-nuget: "${{ matrix.platform.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/v') }}" - myget-access-token: "${{ secrets.MYGET_ACCESS_TOKEN }}" - nuget-access-token: "${{ secrets.NUGET_ACCESS_TOKEN }}" - - # - name: "Snipe test files" - # uses: actions/upload-artifact@v3 - # with: - # name: "Test Data ${{ matrix.platform.name }}" - # path: | - # ${{ github.workspace }}/src/cs/tests/*Tests*/**/*.json + test-job: + name: "Test" + uses: "./.github/workflows/test.yml" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..5485c6bc --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,70 @@ +name: "Release" +on: + workflow_dispatch: + inputs: + pre-release: + description: 'Is pre-release? (NOTE: Pre-releases are uploaded to MyGet.org instead of NuGet.org.)' + required: true + default: 'true' + version: + description: 'Version (NOTE: If left blank, the current date is used as the version.)' + required: false + default: '' + +jobs: + + test-job: + name: "Test .NET solution" + uses: "./.github/workflows/test.yml" + + release-job: + name: "Release" + needs: [test-job] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + + - name: "Clone Git repository" + uses: actions/checkout@v3 + + - name: "Set version" + id: set-version + shell: bash + run: | + VERSION="${{ github.event.inputs.version }}" + if [[ -z "$VERSION" ]]; then + IS_PRERELEASE="${{ github.event.inputs.pre-release }}" + if [[ "$IS_PRERELEASE" = "true" ]]; then + VERSION="$(date +'%Y.%m.%d')-rc" + else + VERSION="$(date +'%Y.%m.%d')" + fi + fi + + echo "VERSION=$VERSION" + echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" + + - name: ".NET pack" + run: dotnet pack "./src/cs" --nologo --verbosity minimal --configuration Release -p:PackageVersion="${{ steps.set-version.outputs.VERSION }}" -p:RepositoryBranch="${{ github.head_ref || github.ref_name }}" -p:RepositoryCommit="${{ github.sha }}" + + - name: "Upload packages to MyGet" + if: github.event_name == 'workflow_dispatch' && github.event.inputs.pre-release == 'true' + env: + MYGET_ACCESS_TOKEN: ${{ secrets.MYGET_ACCESS_TOKEN }} + run: dotnet nuget push "./nupkg/**/*.nupkg" --source https://www.myget.org/F/bottlenoselabs/api/v3/index.json --skip-duplicate --api-key $MYGET_ACCESS_TOKEN + + - name: "Upload packages to NuGet" + if: github.event_name == 'schedule' || github.event.inputs.pre-release == 'false' + env: + NUGET_ACCESS_TOKEN: ${{ secrets.NUGET_ACCESS_TOKEN }} + run: dotnet nuget push "./nupkg/**/*.nupkg" --source https://api.nuget.org/v3/index.json --skip-duplicate --api-key $NUGET_ACCESS_TOKEN + + - name: "Create tag and GitHub release" + uses: softprops/action-gh-release@v1 + if: github.event_name == 'schedule' || github.event.inputs.pre-release == 'false' + with: + generate_release_notes: true + prerelease: "{{ github.event.inputs.pre-release == 'true' }}" + tag_name: "v${{ steps.set-version.outputs.VERSION }}" + \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..8acaf767 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,56 @@ +name: "Test .NET solution" + +on: + workflow_call: + +jobs: + + test-dotnet-job: + name: "Test .NET solution: ${{ matrix.platform.name }}" + runs-on: ${{ matrix.platform.os }} + strategy: + fail-fast: false + matrix: + platform: + - { name: Windows, os: windows-latest } + - { name: Linux, os: ubuntu-latest } + - { name: macOS, os: macos-latest } + defaults: + run: + shell: bash + steps: + + - name: "Clone Git repository" + uses: actions/checkout@v3 + + - name: "Install Clang: Windows" + if: matrix.platform.os == 'windows-latest' + run: | + source "${{ github.workspace }}\.github\scripts\install-clang-x64-windows.sh" + + - name: "Install Clang: Linux" + if: matrix.platform.os == 'ubuntu-latest' + run: | + sudo apt-get update + sudo apt-get install gcc-i686-linux-gnu gcc-x86-64-linux-gnu gcc-aarch64-linux-gnu llvm-14 clang-14 + + - name: "Setup .NET" + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.x' + + - name: "Install CAstFfi" + shell: bash + run: dotnet tool install --global bottlenoselabs.CAstFfi.Tool + + - name: "Test .NET solution" + run: | + dotnet test '${{ github.workspace }}/src/cs' --nologo --verbosity minimal --configuration Release + + - name: "Collect generated test files" + uses: actions/upload-artifact@v3 + if: github.event_name == 'pull_request' + with: + name: "Test Data ${{ matrix.platform.name }}" + path: | + ${{ github.workspace }}/src/cs/tests/*.Tests/Data/Values/**/*.json diff --git a/GitVersion.yml b/GitVersion.yml deleted file mode 100644 index e9d7d2d1..00000000 --- a/GitVersion.yml +++ /dev/null @@ -1,14 +0,0 @@ -assembly-versioning-scheme: None -mode: ContinuousDeployment -tag-prefix: "[vV]" -continuous-delivery-fallback-tag: "" -branches: - develop: - regex: '^main$' - increment: Patch - tag: 'alpha' - main: - regex: '^notused$' -ignore: - sha: [] -merge-message-formats: {} \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 57961b55..7d7ef590 100644 --- a/docs/README.md +++ b/docs/README.md @@ -29,7 +29,7 @@ See [LESSONS-LEARNED.md](./LESSONS-LEARNED.md). ## Installing `C2CS` -`C2CS` is distributed as a NuGet tool. To get started, the .NET 7 software development kit (SDK) is required. +`C2CS` is distributed as a NuGet tool. To get started, the .NET 8 software development kit (SDK) is required. ### Latest release of `C2CS` @@ -75,7 +75,7 @@ The `C2CS.Runtime` C# code is directly added to the bottom of the generated bind ### Prerequisites -1. Install [.NET 7 SDK](https://dotnet.microsoft.com/download). +1. Install [.NET 8 SDK](https://dotnet.microsoft.com/download). 2. Install build tools for C/C++. - Windows: 1. Install Git Bash. (Usually installed with Git for Windows: https://git-scm.com/downloads.) diff --git a/nuget.config b/nuget.config index 1d67fe64..1f1b2fd3 100755 --- a/nuget.config +++ b/nuget.config @@ -4,6 +4,5 @@ - \ No newline at end of file diff --git a/src/c/tests/_container_library/build.sh b/src/c/tests/_container_library/build.sh index 30d5dad2..3721aaa4 100755 --- a/src/c/tests/_container_library/build.sh +++ b/src/c/tests/_container_library/build.sh @@ -1,7 +1,8 @@ #!/bin/bash DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +OUPUT_DIRECTORY=$DIRECTORY/bin -rm -rf ./cmake-build-release -cmake -S . -B cmake-build-release -DCMAKE_BUILD_TYPE=Release -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=/Users/lstranks/Programming/bottlenoselabs/c2cs/bin/C2CS.Tests/Debug/net7.0/c/tests/_container_library/bin -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/Users/lstranks/Programming/bottlenoselabs/c2cs/bin/C2CS.Tests/Debug/net7.0/c/tests/_container_library/bin -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=/Users/lstranks/Programming/bottlenoselabs/c2cs/bin/C2CS.Tests/Debug/net7.0/c/tests/_container_library/bin -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=/Users/lstranks/Programming/bottlenoselabs/c2cs/bin/C2CS.Tests/Debug/net7.0/c/tests/_container_library/bin +rm -rf $DIRECTORY/cmake-build-release +cmake -S $DIRECTORY -B cmake-build-release -DCMAKE_BUILD_TYPE=Release -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=$OUPUT_DIRECTORY -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=$OUPUT_DIRECTORY -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=$OUPUT_DIRECTORY cmake --build cmake-build-release --config Release -rm -rf ./cmake-build-release \ No newline at end of file +rm -rf $DIRECTORY/cmake-build-release \ No newline at end of file diff --git a/src/c/tests/enums/EnumForceSInt32.h b/src/c/tests/enums/EnumForceSInt32.h index 43432ff6..51b55441 100644 --- a/src/c/tests/enums/EnumForceSInt32.h +++ b/src/c/tests/enums/EnumForceSInt32.h @@ -7,7 +7,7 @@ typedef enum EnumForceSInt32 { ENUM_FORCE_SINT32_DAY_WEDNESDAY, ENUM_FORCE_SINT32_DAY_THURSDAY, ENUM_FORCE_SINT32_DAY_FRIDAY, - _ENUM_FORCE_SINT32 = 0x7FFFFF + _ENUM_FORCE_SINT32 = 0x7FFFFFFFUL } EnumForceSInt32; FFI_API_DECL void EnumForceSInt32__print_EnumForceSInt32(const EnumForceSInt32 e) diff --git a/src/c/tests/enums/EnumForceSInt64.h b/src/c/tests/enums/EnumForceSInt64.h deleted file mode 100644 index 3f16d802..00000000 --- a/src/c/tests/enums/EnumForceSInt64.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -typedef enum EnumForceSInt64 { - ENUM_FORCE_SINT64_DAY_UNKNOWN, - ENUM_FORCE_SINT64_DAY_MONDAY, - ENUM_FORCE_SINT64_DAY_TUESDAY, - ENUM_FORCE_SINT64_DAY_WEDNESDAY, - ENUM_FORCE_SINT64_DAY_THURSDAY, - ENUM_FORCE_SINT64_DAY_FRIDAY, - _ENUM_FORCE_SINT64 = 0x7FFFFFFF -} EnumForceSInt64; - -FFI_API_DECL void EnumForceSInt64__print_EnumForceSInt64(const EnumForceSInt64 e) -{ - printf("%d\n", e); // Print used for testing -} - -FFI_API_DECL EnumForceSInt64 EnumForceSInt64__return_EnumForceSInt64(const EnumForceSInt64 e) -{ - return e; -} \ No newline at end of file diff --git a/src/c/tests/enums/EnumForceUInt32.h b/src/c/tests/enums/EnumForceUInt32.h index d56e9576..6907ae8e 100644 --- a/src/c/tests/enums/EnumForceUInt32.h +++ b/src/c/tests/enums/EnumForceUInt32.h @@ -7,7 +7,7 @@ typedef enum EnumForceUInt32 { ENUM_FORCE_UINT32_DAY_WEDNESDAY, ENUM_FORCE_UINT32_DAY_THURSDAY, ENUM_FORCE_UINT32_DAY_FRIDAY, - _ENUM_FORCE_UINT32 = 0xffffffffffffffffL + _ENUM_FORCE_UINT32 = 0xFFFFFFFFUL } EnumForceUInt32; FFI_API_DECL void EnumForceUInt32__print_EnumForceUInt32(const EnumForceUInt32 e) diff --git a/src/c/tests/enums/EnumForceUInt64.h b/src/c/tests/enums/EnumForceUInt64.h deleted file mode 100644 index c6f2d78b..00000000 --- a/src/c/tests/enums/EnumForceUInt64.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -typedef enum EnumForceUInt64 { - ENUM_FORCE_UINT64_DAY_UNKNOWN, - ENUM_FORCE_UINT64_DAY_MONDAY, - ENUM_FORCE_UINT64_DAY_TUESDAY, - ENUM_FORCE_UINT64_DAY_WEDNESDAY, - ENUM_FORCE_UINT64_DAY_THURSDAY, - ENUM_FORCE_UINT64_DAY_FRIDAY, - _ENUM_FORCE_UINT64 = 0xffffffff -} EnumForceUInt64; - -FFI_API_DECL void EnumForceUInt64__print_EnumForceUInt64(const EnumForceUInt64 e) -{ - printf("%d\n", e); // Print used for testing -} - -FFI_API_DECL EnumForceUInt64 EnumForceUInt64__return_EnumForceUInt64(const EnumForceUInt64 e) -{ - return e; -} \ No newline at end of file diff --git a/src/c/tests/enums/_index.h b/src/c/tests/enums/_index.h index e511149d..f5844786 100644 --- a/src/c/tests/enums/_index.h +++ b/src/c/tests/enums/_index.h @@ -3,9 +3,6 @@ #include "EnumForceSInt8.h" #include "EnumForceSInt16.h" #include "EnumForceSInt32.h" -#include "EnumForceSInt64.h" - #include "EnumForceUInt8.h" #include "EnumForceUInt16.h" -#include "EnumForceUInt32.h" -#include "EnumForceUInt64.h" \ No newline at end of file +#include "EnumForceUInt32.h" \ No newline at end of file diff --git a/src/cs/TODO.md b/src/cs/TODO.md deleted file mode 100644 index 726719b6..00000000 --- a/src/cs/TODO.md +++ /dev/null @@ -1,3 +0,0 @@ -# TODO - -1. Add more tests. diff --git a/src/cs/examples/helloworld/helloworld-app/Generated/SourceGenerators/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs b/src/cs/examples/helloworld/helloworld-app/Generated/SourceGenerators/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs index e7ac54c1..b2e946cf 100644 --- a/src/cs/examples/helloworld/helloworld-app/Generated/SourceGenerators/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs +++ b/src/cs/examples/helloworld/helloworld-app/Generated/SourceGenerators/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs @@ -3,7 +3,7 @@ namespace my_c_library_namespace { public static unsafe partial class my_c_library { - [System.Runtime.InteropServices.DllImportAttribute("my_c_library", EntryPoint = "hw_hello_world", ExactSpelling = true)] + [global::System.Runtime.InteropServices.DllImportAttribute("my_c_library", EntryPoint = "hw_hello_world", ExactSpelling = true)] public static extern partial void hw_hello_world(); } } @@ -11,7 +11,7 @@ namespace my_c_library_namespace { public static unsafe partial class my_c_library { - [System.Runtime.InteropServices.DllImportAttribute("my_c_library", EntryPoint = "hw_invoke_callback", ExactSpelling = true)] + [global::System.Runtime.InteropServices.DllImportAttribute("my_c_library", EntryPoint = "hw_invoke_callback", ExactSpelling = true)] public static extern partial void hw_invoke_callback(global::my_c_library_namespace.my_c_library.FnPtr_CString_Void f, global::bottlenoselabs.C2CS.Runtime.CString s); } } @@ -19,7 +19,7 @@ namespace my_c_library_namespace { public static unsafe partial class my_c_library { - [System.Runtime.InteropServices.DllImportAttribute("my_c_library", EntryPoint = "hw_pass_enum", ExactSpelling = true)] + [global::System.Runtime.InteropServices.DllImportAttribute("my_c_library", EntryPoint = "hw_pass_enum", ExactSpelling = true)] public static extern partial void hw_pass_enum(global::my_c_library_namespace.my_c_library.hw_my_enum_week_day e); } } @@ -27,7 +27,7 @@ namespace my_c_library_namespace { public static unsafe partial class my_c_library { - [System.Runtime.InteropServices.DllImportAttribute("my_c_library", EntryPoint = "hw_pass_integers_by_reference", ExactSpelling = true)] + [global::System.Runtime.InteropServices.DllImportAttribute("my_c_library", EntryPoint = "hw_pass_integers_by_reference", ExactSpelling = true)] public static extern partial void hw_pass_integers_by_reference(ushort* a, int* b, ulong* c); } } @@ -35,7 +35,7 @@ namespace my_c_library_namespace { public static unsafe partial class my_c_library { - [System.Runtime.InteropServices.DllImportAttribute("my_c_library", EntryPoint = "hw_pass_integers_by_value", ExactSpelling = true)] + [global::System.Runtime.InteropServices.DllImportAttribute("my_c_library", EntryPoint = "hw_pass_integers_by_value", ExactSpelling = true)] public static extern partial void hw_pass_integers_by_value(ushort a, int b, ulong c); } } @@ -43,7 +43,7 @@ namespace my_c_library_namespace { public static unsafe partial class my_c_library { - [System.Runtime.InteropServices.DllImportAttribute("my_c_library", EntryPoint = "hw_pass_string", ExactSpelling = true)] + [global::System.Runtime.InteropServices.DllImportAttribute("my_c_library", EntryPoint = "hw_pass_string", ExactSpelling = true)] public static extern partial void hw_pass_string(global::bottlenoselabs.C2CS.Runtime.CString s); } } diff --git a/src/cs/examples/helloworld/helloworld-app/helloworld-app.csproj b/src/cs/examples/helloworld/helloworld-app/helloworld-app.csproj index bb3a38aa..2f12996f 100644 --- a/src/cs/examples/helloworld/helloworld-app/helloworld-app.csproj +++ b/src/cs/examples/helloworld/helloworld-app/helloworld-app.csproj @@ -3,7 +3,7 @@ Exe - net7.0 + net8.0 true false diff --git a/src/cs/examples/helloworld/helloworld-compile-c-library-and-generate-bindings/Program.cs b/src/cs/examples/helloworld/helloworld-compile-c-library-and-generate-bindings/Program.cs index ff1e7253..c85ed06a 100644 --- a/src/cs/examples/helloworld/helloworld-compile-c-library-and-generate-bindings/Program.cs +++ b/src/cs/examples/helloworld/helloworld-compile-c-library-and-generate-bindings/Program.cs @@ -3,11 +3,7 @@ using System; using System.IO; -using System.IO.Abstractions; -using C2CS.Features.BuildCLibrary.Domain; -using C2CS.Native; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; +using bottlenoselabs.Common; #pragma warning disable CA1303 @@ -41,7 +37,7 @@ private static bool BuildCLibrary(string sourceDirectoryPath) private static bool GenerateBindingsCSharp(string sourceDirectoryPath) { - var bindgenConfigFileName = NativeUtility.OperatingSystem switch + var bindgenConfigFileName = Native.OperatingSystem switch { NativeOperatingSystem.Windows => "config-extract-windows.json", NativeOperatingSystem.macOS => "config-extract-macos.json", @@ -51,7 +47,7 @@ private static bool GenerateBindingsCSharp(string sourceDirectoryPath) var bindgenConfigFilePath = Path.GetFullPath(Path.Combine(sourceDirectoryPath, bindgenConfigFileName)); - var extractShellOutput = $"castffi extract --config {bindgenConfigFilePath}".ExecuteShell(); + var extractShellOutput = $"castffi extract --config {bindgenConfigFilePath}".ExecuteShellCommand(); if (extractShellOutput.ExitCode != 0) { return false; @@ -59,7 +55,7 @@ private static bool GenerateBindingsCSharp(string sourceDirectoryPath) var abstractSyntaxTreeDirectoryPath = Path.GetFullPath(Path.Combine(sourceDirectoryPath, "ast")); var mergedAbstractSyntaxTreeFilePath = Path.GetFullPath(Path.Combine(sourceDirectoryPath, "ast", "cross-platform.json")); - var astShellOutput = $"castffi merge --inputDirectoryPath {abstractSyntaxTreeDirectoryPath} --outputFilePath {mergedAbstractSyntaxTreeFilePath}".ExecuteShell(); + var astShellOutput = $"castffi merge --inputDirectoryPath {abstractSyntaxTreeDirectoryPath} --outputFilePath {mergedAbstractSyntaxTreeFilePath}".ExecuteShellCommand(); if (astShellOutput.ExitCode != 0) { return false; diff --git a/src/cs/examples/helloworld/helloworld-compile-c-library-and-generate-bindings/helloworld-compile-c-library-and-generate-bindings.csproj b/src/cs/examples/helloworld/helloworld-compile-c-library-and-generate-bindings/helloworld-compile-c-library-and-generate-bindings.csproj index d907f0fe..3351fbdf 100644 --- a/src/cs/examples/helloworld/helloworld-compile-c-library-and-generate-bindings/helloworld-compile-c-library-and-generate-bindings.csproj +++ b/src/cs/examples/helloworld/helloworld-compile-c-library-and-generate-bindings/helloworld-compile-c-library-and-generate-bindings.csproj @@ -3,7 +3,7 @@ Exe - net7.0 + net8.0 true en true @@ -13,7 +13,6 @@ - diff --git a/src/cs/production/C2CS.Tool/C2CS.Tool.csproj b/src/cs/production/C2CS.Tool/C2CS.Tool.csproj index 4f4aab19..fe202b72 100644 --- a/src/cs/production/C2CS.Tool/C2CS.Tool.csproj +++ b/src/cs/production/C2CS.Tool/C2CS.Tool.csproj @@ -2,7 +2,7 @@ - net7.0 + net8.0 Exe enable C2CS @@ -27,17 +27,14 @@ - - + + - - - - - - - + + + + diff --git a/src/cs/production/C2CS.Tool/Foundation/CommandLineArgumentsProvider.cs b/src/cs/production/C2CS.Tool/CommandLineArgumentsProvider.cs similarity index 94% rename from src/cs/production/C2CS.Tool/Foundation/CommandLineArgumentsProvider.cs rename to src/cs/production/C2CS.Tool/CommandLineArgumentsProvider.cs index 979d1f62..1aea7ff1 100644 --- a/src/cs/production/C2CS.Tool/Foundation/CommandLineArgumentsProvider.cs +++ b/src/cs/production/C2CS.Tool/CommandLineArgumentsProvider.cs @@ -1,7 +1,7 @@ // Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. // Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. -namespace C2CS.Foundation; +namespace C2CS; internal sealed class CommandLineArgumentsProvider { diff --git a/src/cs/production/C2CS.Tool/Foundation/CommandLineHost.cs b/src/cs/production/C2CS.Tool/CommandLineHost.cs similarity index 100% rename from src/cs/production/C2CS.Tool/Foundation/CommandLineHost.cs rename to src/cs/production/C2CS.Tool/CommandLineHost.cs diff --git a/src/cs/production/C2CS.Tool/Foundation/CommandLineInterface.cs b/src/cs/production/C2CS.Tool/CommandLineInterface.cs similarity index 100% rename from src/cs/production/C2CS.Tool/Foundation/CommandLineInterface.cs rename to src/cs/production/C2CS.Tool/CommandLineInterface.cs diff --git a/src/cs/production/C2CS.Tool/Features/BuildCLibrary/BuildCLibraryTool.cs b/src/cs/production/C2CS.Tool/Features/BuildCLibrary/BuildCLibraryTool.cs index 041a85c8..9c6e8b0c 100644 --- a/src/cs/production/C2CS.Tool/Features/BuildCLibrary/BuildCLibraryTool.cs +++ b/src/cs/production/C2CS.Tool/Features/BuildCLibrary/BuildCLibraryTool.cs @@ -3,12 +3,12 @@ using System.Collections.Immutable; using System.IO.Abstractions; +using bottlenoselabs.Common.Tools; using C2CS.Features.BuildCLibrary.Domain; using C2CS.Features.BuildCLibrary.Input; using C2CS.Features.BuildCLibrary.Input.Sanitized; using C2CS.Features.BuildCLibrary.Input.Unsanitized; using C2CS.Features.BuildCLibrary.Output; -using C2CS.Foundation.Tool; using Microsoft.Extensions.Logging; namespace C2CS.Features.BuildCLibrary; diff --git a/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Domain/CMakeLibraryBuilder.cs b/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Domain/CMakeLibraryBuilder.cs index 0ba705c5..8392dc78 100644 --- a/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Domain/CMakeLibraryBuilder.cs +++ b/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Domain/CMakeLibraryBuilder.cs @@ -7,8 +7,8 @@ using System.IO; using System.IO.Abstractions; using System.Linq; +using bottlenoselabs.Common; using C2CS.Features.BuildCLibrary.Input.Sanitized; -using C2CS.Native; using Microsoft.Extensions.Logging; namespace C2CS.Features.BuildCLibrary.Domain; @@ -76,14 +76,14 @@ private bool BuildCMakeSharedLibrary( { const string cMakeBuildCommand = "cmake --build cmake-build-release --config Release"; LogCMakeBuildingLibrary(cMakeBuildCommand); - var result = cMakeBuildCommand.ExecuteShell(cMakeDirectoryPath, windowsUsePowerShell: false); + var result = cMakeBuildCommand.ExecuteShellCommand(cMakeDirectoryPath, windowsUsePowerShell: false); if (result.ExitCode != 0) { - LogCMakeBuildingLibraryFailed(result.Output); + LogCMakeBuildingLibraryFailed(result.Output.Trim()); return false; } - var dynamicLinkLibraryFileSearchPattern = NativeUtility.OperatingSystem switch + var dynamicLinkLibraryFileSearchPattern = Native.OperatingSystem switch { NativeOperatingSystem.Windows => "*.dll", NativeOperatingSystem.macOS => "*.dylib", @@ -104,12 +104,12 @@ private bool BuildCMakeSharedLibrary( var installNameToolCommandDeleteRPath = $"install_name_tool -delete_rpath {cMakeOutputDirectoryPath} {outputFilePath}"; installNameToolCommandDeleteRPath - .ExecuteShell(cMakeDirectoryPath, windowsUsePowerShell: false); + .ExecuteShellCommand(cMakeDirectoryPath, windowsUsePowerShell: false); var installNameToolCommandAddRPath = $"install_name_tool -add_rpath @loader_path/. {outputFilePath}"; installNameToolCommandAddRPath - .ExecuteShell(cMakeDirectoryPath, windowsUsePowerShell: false); + .ExecuteShellCommand(cMakeDirectoryPath, windowsUsePowerShell: false); } } @@ -150,14 +150,14 @@ private bool GenerateCMakeBuildFiles( var cMakeGenerateBuildFilesCommand = $"cmake -S . -B cmake-build-release {cMakeArgumentsString}"; LogCMakeGeneratingBuildFiles(cMakeGenerateBuildFilesCommand); var result = cMakeGenerateBuildFilesCommand - .ExecuteShell(cMakeDirectoryPath, windowsUsePowerShell: false); + .ExecuteShellCommand(cMakeDirectoryPath, windowsUsePowerShell: false); if (result.ExitCode != 0) { - LogCMakeGeneratingBuildFilesFailed(result.Output); + LogCMakeGeneratingBuildFilesFailed(result.Output.Trim()); return false; } - LogCMakeGeneratingBuildFilesSuccess(result.Output); + LogCMakeGeneratingBuildFilesSuccess(result.Output.Trim()); return true; } diff --git a/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Input/BuildCLibraryInputSanitizer.cs b/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Input/BuildCLibraryInputSanitizer.cs index 1df30cb0..650abbdf 100644 --- a/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Input/BuildCLibraryInputSanitizer.cs +++ b/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Input/BuildCLibraryInputSanitizer.cs @@ -5,9 +5,9 @@ using System.Collections.Immutable; using System.IO.Abstractions; using System.Linq; +using bottlenoselabs.Common.Tools; using C2CS.Features.BuildCLibrary.Input.Sanitized; using C2CS.Features.BuildCLibrary.Input.Unsanitized; -using C2CS.Foundation.Tool; namespace C2CS.Features.BuildCLibrary.Input; diff --git a/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Input/Unsanitized/BuildCLibraryOptions.cs b/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Input/Unsanitized/BuildCLibraryOptions.cs index 2031102a..eb3b85a0 100644 --- a/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Input/Unsanitized/BuildCLibraryOptions.cs +++ b/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Input/Unsanitized/BuildCLibraryOptions.cs @@ -3,7 +3,7 @@ using System.Collections.Immutable; using System.Text.Json.Serialization; -using C2CS.Foundation.Tool; +using bottlenoselabs.Common.Tools; using JetBrains.Annotations; namespace C2CS.Features.BuildCLibrary.Input.Unsanitized; diff --git a/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Output/BuildCLibraryOutput.cs b/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Output/BuildCLibraryOutput.cs index 1df84f88..d55062d0 100644 --- a/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Output/BuildCLibraryOutput.cs +++ b/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Output/BuildCLibraryOutput.cs @@ -1,8 +1,8 @@ // Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. // Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. +using bottlenoselabs.Common.Tools; using C2CS.Features.BuildCLibrary.Input.Sanitized; -using C2CS.Foundation.Tool; namespace C2CS.Features.BuildCLibrary.Output; diff --git a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Data/CSharpAbstractSyntaxTree.cs b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Data/CSharpAbstractSyntaxTree.cs index f62f5ec2..4e395256 100644 --- a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Data/CSharpAbstractSyntaxTree.cs +++ b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Data/CSharpAbstractSyntaxTree.cs @@ -2,7 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. using System.Collections.Immutable; -using C2CS.Native; +using bottlenoselabs.Common; namespace C2CS.Features.WriteCodeCSharp.Data; diff --git a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Data/CSharpStructField.cs b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Data/CSharpStructField.cs index 4b28a44f..a95e854d 100644 --- a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Data/CSharpStructField.cs +++ b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Data/CSharpStructField.cs @@ -27,7 +27,7 @@ public CSharpStructField( TypeInfo = typeInfo; OffsetOf = offsetOf; IsWrapped = isWrapped; - BackingFieldName = name.StartsWith("@", StringComparison.InvariantCulture) ? $"_{name[1..]}" : $"_{name}"; + BackingFieldName = name.StartsWith('@') ? $"_{name[1..]}" : $"_{name}"; } public override bool Equals(CSharpNode? other) diff --git a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/CSharpCodeGenerator.cs b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/CSharpCodeGenerator.cs index f1e74080..f7afb332 100644 --- a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/CSharpCodeGenerator.cs +++ b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/CSharpCodeGenerator.cs @@ -7,6 +7,7 @@ using System.Globalization; using System.IO; using System.Reflection; +using bottlenoselabs.Common.Diagnostics; using C2CS.Features.WriteCodeCSharp.Data; using C2CS.Features.WriteCodeCSharp.Domain.CodeGenerator.Handlers; using C2CS.Foundation; @@ -37,7 +38,7 @@ public CSharpCodeGenerator( _versionStamp = Assembly.GetEntryAssembly()!.GetName().Version!.ToString(); } - public CSharpProject? Generate(CSharpAbstractSyntaxTree abstractSyntaxTree, DiagnosticCollection diagnostics) + public CSharpProject? Generate(CSharpAbstractSyntaxTree abstractSyntaxTree, DiagnosticsSink diagnostics) { try { diff --git a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/CSharpCodeGeneratorContext.cs b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/CSharpCodeGeneratorContext.cs index 7fada585..865d9a25 100644 --- a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/CSharpCodeGeneratorContext.cs +++ b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/CSharpCodeGeneratorContext.cs @@ -6,8 +6,8 @@ using System.Collections.Immutable; using System.Linq; using System.Text; +using bottlenoselabs.Common.Tools; using C2CS.Features.WriteCodeCSharp.Data; -using C2CS.Foundation.Tool; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; diff --git a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/CSharpLibraryCompiler.cs b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/CSharpLibraryCompiler.cs index f5bb8421..69037899 100644 --- a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/CSharpLibraryCompiler.cs +++ b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/CSharpLibraryCompiler.cs @@ -5,9 +5,9 @@ using System.Collections.Immutable; using System.IO; using System.Reflection; +using bottlenoselabs.Common; +using bottlenoselabs.Common.Diagnostics; using C2CS.Features.WriteCodeCSharp.Domain.CodeGenerator.Diagnostics; -using C2CS.Foundation; -using C2CS.Native; namespace C2CS.Features.WriteCodeCSharp.Domain.CodeGenerator; @@ -16,7 +16,7 @@ public class CSharpLibraryCompiler public Assembly? Compile( CSharpProject project, CSharpCodeGeneratorOptions options, - DiagnosticCollection diagnostics) + DiagnosticsSink diagnostics) { // NOTE: Because `LibraryImportAttribute` uses a C# source generator which can not be referenced in code, we use the .NET SDK directly instead of using Roslyn. @@ -32,7 +32,7 @@ public class CSharpLibraryCompiler private static Assembly? TryCompile( CSharpProject project, CSharpCodeGeneratorOptions options, - DiagnosticCollection diagnostics) + DiagnosticsSink diagnostics) { var temporaryDirectoryPath = Directory.CreateTempSubdirectory("c2cs-").FullName; try @@ -53,17 +53,17 @@ public class CSharpLibraryCompiler string directoryPath, CSharpProject project, CSharpCodeGeneratorOptions options, - DiagnosticCollection diagnostics) + DiagnosticsSink diagnostics) { var cSharpProjectFilePath = Path.Combine(directoryPath, "Project.csproj"); CreateCSharpProjectFile(cSharpProjectFilePath, options); CreateDocumentFiles(directoryPath, project.Documents); - var compilationOutput = "dotnet build --verbosity quiet --nologo --no-incremental".ExecuteShell(workingDirectory: directoryPath); + var compilationOutput = "dotnet build --verbosity quiet --nologo --no-incremental".ExecuteShellCommand(workingDirectory: directoryPath); if (compilationOutput.ExitCode != 0) { - var lines = compilationOutput.Output.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var lines = compilationOutput.Output.Trim().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { diagnostics.Add(new CSharpCompileDiagnostic(line)); @@ -131,13 +131,13 @@ private static void CreateCSharpProjectFile( private static bool CanCompile() { - var shellOutput = "dotnet --list-sdks".ExecuteShell(); + var shellOutput = "dotnet --list-sdks".ExecuteShellCommand(); if (shellOutput.ExitCode != 0) { return false; } - var lines = shellOutput.Output.Split(Environment.NewLine); + var lines = shellOutput.Output.Trim().Split(Environment.NewLine); if (lines.Length == 0) { return false; diff --git a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/Diagnostics/CSharpCompileDiagnostic.cs b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/Diagnostics/CSharpCompileDiagnostic.cs index 5e2c0cb8..b25bec92 100644 --- a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/Diagnostics/CSharpCompileDiagnostic.cs +++ b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/Diagnostics/CSharpCompileDiagnostic.cs @@ -1,7 +1,7 @@ // Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. // Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. -using C2CS.Foundation; +using bottlenoselabs.Common.Diagnostics; namespace C2CS.Features.WriteCodeCSharp.Domain.CodeGenerator.Diagnostics; diff --git a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/Diagnostics/CSharpCompileSkipDiagnostic.cs b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/Diagnostics/CSharpCompileSkipDiagnostic.cs index c4b9d1c9..4d9dd7a3 100644 --- a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/Diagnostics/CSharpCompileSkipDiagnostic.cs +++ b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/Diagnostics/CSharpCompileSkipDiagnostic.cs @@ -1,7 +1,7 @@ // Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. // Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. -using C2CS.Foundation; +using bottlenoselabs.Common.Diagnostics; namespace C2CS.Features.WriteCodeCSharp.Domain.CodeGenerator.Diagnostics; diff --git a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/Mapper/CSharpCodeMapper.cs b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/Mapper/CSharpCodeMapper.cs index 1d29ed56..f9b45a52 100644 --- a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/Mapper/CSharpCodeMapper.cs +++ b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/Mapper/CSharpCodeMapper.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Text.RegularExpressions; using bottlenoselabs.C2CS.Runtime; +using bottlenoselabs.Common.Diagnostics; using C2CS.Features.WriteCodeCSharp.Data; using C2CS.Foundation; using CAstFfi.Data; @@ -66,7 +67,7 @@ public CSharpCodeMapper(CSharpCodeMapperOptions options) } public CSharpAbstractSyntaxTree Map( - DiagnosticCollection diagnostics, CAbstractSyntaxTreeCrossPlatform astC) + DiagnosticsSink diagnostics, CAbstractSyntaxTreeCrossPlatform astC) { var enumNames = astC.Enums.Values.Select(x => x.Name.TrimEnd('_')).ToImmutableHashSet(); var context = new CSharpCodeMapperContext( diff --git a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Input/Unsanitized/WriteCSharpCodeOptions.cs b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Input/Unsanitized/WriteCSharpCodeOptions.cs index 376b3ed2..5f6a2658 100644 --- a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Input/Unsanitized/WriteCSharpCodeOptions.cs +++ b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Input/Unsanitized/WriteCSharpCodeOptions.cs @@ -3,7 +3,7 @@ using System.Collections.Immutable; using System.Text.Json.Serialization; -using C2CS.Foundation.Tool; +using bottlenoselabs.Common.Tools; using JetBrains.Annotations; namespace C2CS.Features.WriteCodeCSharp.Input.Unsanitized; diff --git a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Input/WriteCodeCSharpInputSanitizer.cs b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Input/WriteCodeCSharpInputSanitizer.cs index a212a4c2..ef2757ef 100644 --- a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Input/WriteCodeCSharpInputSanitizer.cs +++ b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Input/WriteCodeCSharpInputSanitizer.cs @@ -6,12 +6,12 @@ using System.IO; using System.IO.Abstractions; using System.Linq; +using bottlenoselabs.Common.Tools; using C2CS.Features.WriteCodeCSharp.Data; using C2CS.Features.WriteCodeCSharp.Domain.CodeGenerator; using C2CS.Features.WriteCodeCSharp.Domain.Mapper; using C2CS.Features.WriteCodeCSharp.Input.Sanitized; using C2CS.Features.WriteCodeCSharp.Input.Unsanitized; -using C2CS.Foundation.Tool; namespace C2CS.Features.WriteCodeCSharp.Input; diff --git a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Output/WriteCodeCSharpOutput.cs b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Output/WriteCodeCSharpOutput.cs index 3ccbe9b3..6c0e49e7 100644 --- a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Output/WriteCodeCSharpOutput.cs +++ b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Output/WriteCodeCSharpOutput.cs @@ -2,9 +2,9 @@ // Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. using System.Reflection; +using bottlenoselabs.Common.Tools; using C2CS.Features.WriteCodeCSharp.Domain.CodeGenerator; using C2CS.Features.WriteCodeCSharp.Input.Sanitized; -using C2CS.Foundation.Tool; namespace C2CS.Features.WriteCodeCSharp.Output; diff --git a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/WriteCodeCSharpTool.cs b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/WriteCodeCSharpTool.cs index 41effc73..abb1b6ed 100644 --- a/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/WriteCodeCSharpTool.cs +++ b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/WriteCodeCSharpTool.cs @@ -5,6 +5,7 @@ using System.IO; using System.IO.Abstractions; using System.Reflection; +using bottlenoselabs.Common.Tools; using C2CS.Features.WriteCodeCSharp.Data; using C2CS.Features.WriteCodeCSharp.Domain.CodeGenerator; using C2CS.Features.WriteCodeCSharp.Domain.Mapper; @@ -12,7 +13,6 @@ using C2CS.Features.WriteCodeCSharp.Input.Sanitized; using C2CS.Features.WriteCodeCSharp.Input.Unsanitized; using C2CS.Features.WriteCodeCSharp.Output; -using C2CS.Foundation.Tool; using CAstFfi.Data; using CAstFfi.Data.Serialization; using Microsoft.Extensions.Logging; diff --git a/src/cs/production/C2CS.Tool/Foundation/Diagnostics/Diagnostic.cs b/src/cs/production/C2CS.Tool/Foundation/Diagnostics/Diagnostic.cs deleted file mode 100644 index 401f4bd3..00000000 --- a/src/cs/production/C2CS.Tool/Foundation/Diagnostics/Diagnostic.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. -// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. - -using System; -using JetBrains.Annotations; - -namespace C2CS.Foundation; - -/// -/// Program runtime feedback that is not necessarily a run-time exception. -/// -[PublicAPI] -public abstract class Diagnostic -{ - /// - /// Gets the severity of this . - /// - public DiagnosticSeverity Severity { get; } - - /// - /// Gets the message of this . - /// - public string Message { get; } - - /// - /// Initializes a new instance of the class. - /// - /// The severity of the . - /// The message of the . - protected Diagnostic(DiagnosticSeverity severity, string message) - { - Severity = severity; - Message = message; - } - - /// - /// Gets the name of this . - /// - /// A representing the name of this . - public string GetName() - { - var type = GetType(); - var typeName = type.Name; - if (!typeName.StartsWith("Diagnostic", StringComparison.InvariantCulture)) - { - return typeName; - } - - return typeName.Replace("Diagnostic", string.Empty, StringComparison.InvariantCulture); - } -} diff --git a/src/cs/production/C2CS.Tool/Foundation/Diagnostics/DiagnosticCollection.cs b/src/cs/production/C2CS.Tool/Foundation/Diagnostics/DiagnosticCollection.cs deleted file mode 100644 index fd2730fd..00000000 --- a/src/cs/production/C2CS.Tool/Foundation/Diagnostics/DiagnosticCollection.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. -// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. - -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Linq; -using JetBrains.Annotations; - -namespace C2CS.Foundation; - -[PublicAPI] -public sealed class DiagnosticCollection -{ - private readonly List _diagnostics = new(); - - public bool HasFaulted => _diagnostics.Any(x => x.Severity is DiagnosticSeverity.Error or DiagnosticSeverity.Panic); - - public void Add(Diagnostic diagnostic) - { - _diagnostics.Add(diagnostic); - } - - public void AddRange(IEnumerable diagnostics) - { - foreach (var diagnostic in diagnostics) - { - Add(diagnostic); - } - } - - public ImmutableArray GetAll() - { - return _diagnostics.ToImmutableArray(); - } -} diff --git a/src/cs/production/C2CS.Tool/Foundation/Diagnostics/DiagnosticPanic.cs b/src/cs/production/C2CS.Tool/Foundation/Diagnostics/DiagnosticPanic.cs deleted file mode 100644 index c0252d26..00000000 --- a/src/cs/production/C2CS.Tool/Foundation/Diagnostics/DiagnosticPanic.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. -// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. - -using System; -using JetBrains.Annotations; - -namespace C2CS.Foundation; - -[PublicAPI] -public sealed class DiagnosticPanic : Diagnostic -{ - public DiagnosticPanic(Exception exception) - : base(DiagnosticSeverity.Panic, CreateMessage(exception)) - { - } - - private static string CreateMessage(Exception exception) - { - return $"{exception.Message}{Environment.NewLine}{exception.StackTrace}"; - } -} diff --git a/src/cs/production/C2CS.Tool/Foundation/Diagnostics/DiagnosticSeverity.cs b/src/cs/production/C2CS.Tool/Foundation/Diagnostics/DiagnosticSeverity.cs deleted file mode 100644 index 80318c7f..00000000 --- a/src/cs/production/C2CS.Tool/Foundation/Diagnostics/DiagnosticSeverity.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. -// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. - -using JetBrains.Annotations; - -namespace C2CS; - -/// -/// Defines different levels of program runtime feedback. -/// -[PublicAPI] -public enum DiagnosticSeverity -{ - /// - /// Verbose and ignorable. - /// - Information, - - /// - /// Suspicious; indicative of an expected but possibly undesired outcome. Does not halt the program. - /// - Warning, - - /// - /// Unacceptable; indicative of an unexpected result. Does not halt the program. - /// - Error, - - /// - /// Crash; gracefully exit the program with a stack trace. - /// - Panic -} diff --git a/src/cs/production/C2CS.Tool/Foundation/Tool/Tool.cs b/src/cs/production/C2CS.Tool/Foundation/Tool/Tool.cs deleted file mode 100644 index 083d92ac..00000000 --- a/src/cs/production/C2CS.Tool/Foundation/Tool/Tool.cs +++ /dev/null @@ -1,239 +0,0 @@ -// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. -// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. - -using System; -using System.ComponentModel; -using System.Diagnostics; -using System.IO.Abstractions; -using System.Text.Json; -using JetBrains.Annotations; -using Microsoft.Extensions.Logging; - -namespace C2CS.Foundation.Tool; - -/// -/// A computation component. -/// -/// The un-sanitized input. -/// The sanitized input. -/// The output. -[PublicAPI] -public abstract class Tool : Tool - where TUnsanitizedInput : ToolUnsanitizedInput - where TOutput : ToolOutput, new() -{ - private readonly Stopwatch _stepStopwatch; - private readonly Stopwatch _stopwatch; - private readonly ToolInputSanitizer _inputSanitizer; - private readonly ILogger> _logger; - - private IDisposable? _loggerScopeStep; - private readonly IFileSystem _fileSystem; - - protected Tool( - ILogger> logger, - ToolInputSanitizer inputSanitizer, - IFileSystem fileSystem) - : base(logger) - { - _logger = logger; - _stopwatch = new Stopwatch(); - _stepStopwatch = new Stopwatch(); - _inputSanitizer = inputSanitizer; - _fileSystem = fileSystem; - } - - protected DiagnosticCollection Diagnostics { get; } = new(); - - public TOutput Run(string configurationFilePath) - { - var fullFilePath = _fileSystem.Path.GetFullPath(configurationFilePath); - if (!_fileSystem.File.Exists(fullFilePath)) - { - throw new ToolInputSanitizationException($"The tool configuration file '{fullFilePath}' does not exist."); - } - - var fileContents = _fileSystem.File.ReadAllText(fullFilePath); - if (string.IsNullOrEmpty(fileContents)) - { - throw new ToolInputSanitizationException($"The extract options file '{fullFilePath}' is empty."); - } - - var serializerOptions = new JsonSerializerOptions - { - AllowTrailingCommas = true - }; - var unsanitizedInput = JsonSerializer.Deserialize(fileContents, serializerOptions); - if (unsanitizedInput == null) - { - throw new ToolInputSanitizationException("Failed to deserialize the tool configuration file path."); - } - - var workingDirectory = _fileSystem.Path.GetDirectoryName(fullFilePath)!; - var output = Run(unsanitizedInput, workingDirectory); - return output; - } - - public TOutput Run(TUnsanitizedInput unsanitizedInput) - { - var output = Run(unsanitizedInput, Environment.CurrentDirectory); - return output; - } - - protected abstract void Execute(TInput input, TOutput output); - - protected void BeginStep(string stepName) - { - _stepStopwatch.Reset(); - _loggerScopeStep = _logger.BeginScope(stepName); - GarbageCollect(); - LogStepStarted(); - _stepStopwatch.Start(); - } - - protected void EndStep() - { - _stepStopwatch.Stop(); - var timeSpan = _stepStopwatch.Elapsed; - - var isSuccess = !Diagnostics.HasFaulted; - if (isSuccess) - { - LogStepSuccess(timeSpan); - } - else - { - LogStepFailure(timeSpan); - } - - _loggerScopeStep?.Dispose(); - _loggerScopeStep = null; - GarbageCollect(); - } - - [DebuggerHidden] - private TOutput Run(TUnsanitizedInput unsanitizedInput, string? workingFileDirectory) - { - var output = new TOutput(); - - var previousCurrentDirectory = Environment.CurrentDirectory; - Environment.CurrentDirectory = workingFileDirectory ?? Environment.CurrentDirectory; - - Begin(); - try - { - output.Input = _inputSanitizer.Sanitize(unsanitizedInput); - Execute(output.Input, output); - } - catch (Exception e) - { - if (Debugger.IsAttached) - { - throw; - } - else - { - Panic(e); - } - } - finally - { - Environment.CurrentDirectory = previousCurrentDirectory; - } - - End(output); - return output; - } - - private void Begin() - { - _stopwatch.Reset(); - _stepStopwatch.Reset(); - GarbageCollect(); - LogStarted(); - _stopwatch.Start(); - } - - private void End(TOutput response) - { - _stopwatch.Stop(); - var timeSpan = _stopwatch.Elapsed; - - response.Complete(Diagnostics.GetAll()); - - if (response.IsSuccess) - { - LogSuccess(timeSpan); - } - else - { - LogFailure(timeSpan); - } - - foreach (var diagnostic in response.Diagnostics) - { - var name = diagnostic.GetName(); - var message = diagnostic.Message; - - var logLevel = diagnostic.Severity switch - { - DiagnosticSeverity.Information => LogLevel.Information, - DiagnosticSeverity.Warning => LogLevel.Warning, - DiagnosticSeverity.Error => LogLevel.Error, - DiagnosticSeverity.Panic => LogLevel.Critical, - _ => LogLevel.Information - }; - -#pragma warning disable CA1848 -#pragma warning disable CA2254 - // ReSharper disable once TemplateIsNotCompileTimeConstantProblem - _logger.Log(logLevel, $"- {name} {message}"); -#pragma warning restore CA2254 -#pragma warning restore CA1848 - } - - GarbageCollect(); - } - - private void Panic(Exception e) - { - var diagnostic = new DiagnosticPanic(e); - Diagnostics.Add(diagnostic); - } - - private static void GarbageCollect() - { - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); - } -} - -[EditorBrowsable(EditorBrowsableState.Never)] -public partial class Tool -{ - private readonly ILogger _logger; - - protected Tool(ILogger logger) - { - _logger = logger; - } - - [LoggerMessage(0, LogLevel.Information, "- Started")] - protected partial void LogStarted(); - - [LoggerMessage(1, LogLevel.Information, @"- Success in {Elapsed:s\\.ffff} seconds")] - protected partial void LogSuccess(TimeSpan elapsed); - - [LoggerMessage(2, LogLevel.Information, @"- Failed in {Elapsed:s\\.ffff} seconds")] - protected partial void LogFailure(TimeSpan elapsed); - - [LoggerMessage(3, LogLevel.Information, "- Step started")] - protected partial void LogStepStarted(); - - [LoggerMessage(4, LogLevel.Information, @"- Step success in {Elapsed:s\\.ffff} seconds")] - protected partial void LogStepSuccess(TimeSpan elapsed); - - [LoggerMessage(5, LogLevel.Information, @"- Step failed in {Elapsed:s\\.ffff} seconds")] - protected partial void LogStepFailure(TimeSpan elapsed); -} diff --git a/src/cs/production/C2CS.Tool/Foundation/Tool/ToolException.cs b/src/cs/production/C2CS.Tool/Foundation/Tool/ToolException.cs deleted file mode 100644 index b936637e..00000000 --- a/src/cs/production/C2CS.Tool/Foundation/Tool/ToolException.cs +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. -// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. - -using System; -using System.Diagnostics; - -namespace C2CS.Foundation.Tool; - -public sealed class ToolException : Exception -{ - public ToolException() - { - } - - public ToolException(string message, Exception innerException) - : base(message, innerException) - { - } - - public ToolException(string message) - : base(CreateMessage(message)) - { - } - - private static string CreateMessage(string message) - { - var featureName = ToolName(); - if (string.IsNullOrEmpty(message)) - { - return featureName; - } - - return featureName + Environment.NewLine + message; - } - - private static string ToolName() - { - var skipFrames = 0; - var featureNamespace = typeof(ToolException).Namespace! + ".Tool"; - - while (true) - { - var stackFrame = new StackFrame(skipFrames, false); - var method = stackFrame.GetMethod(); - if (method == null) - { - return string.Empty; - } - - var declaringType = method.DeclaringType; - var typeNamespace = declaringType?.Namespace!; - if (string.IsNullOrEmpty(typeNamespace)) - { - skipFrames++; - continue; - } - - if (!typeNamespace.StartsWith(featureNamespace, StringComparison.InvariantCulture)) - { - skipFrames++; - continue; - } - - return typeNamespace; - } - } -} diff --git a/src/cs/production/C2CS.Tool/Foundation/Tool/ToolInputSanitizationException.cs b/src/cs/production/C2CS.Tool/Foundation/Tool/ToolInputSanitizationException.cs deleted file mode 100644 index 3e79fc12..00000000 --- a/src/cs/production/C2CS.Tool/Foundation/Tool/ToolInputSanitizationException.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. -// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. - -using System; - -namespace C2CS.Foundation.Tool; - -public sealed class ToolInputSanitizationException : Exception -{ - public ToolInputSanitizationException() - { - } - - public ToolInputSanitizationException(string message) - : base(message) - { - } - - public ToolInputSanitizationException(string message, Exception innerException) - : base(message, innerException) - { - } -} diff --git a/src/cs/production/C2CS.Tool/Foundation/Tool/ToolInputSanitizer.cs b/src/cs/production/C2CS.Tool/Foundation/Tool/ToolInputSanitizer.cs deleted file mode 100644 index ccbbe95a..00000000 --- a/src/cs/production/C2CS.Tool/Foundation/Tool/ToolInputSanitizer.cs +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. -// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. - -namespace C2CS.Foundation.Tool; - -public abstract class ToolInputSanitizer -{ - public abstract TInput Sanitize(TUnsanitizedInput unsanitizedInput); -} diff --git a/src/cs/production/C2CS.Tool/Foundation/Tool/ToolOutput.cs b/src/cs/production/C2CS.Tool/Foundation/Tool/ToolOutput.cs deleted file mode 100644 index 9794c286..00000000 --- a/src/cs/production/C2CS.Tool/Foundation/Tool/ToolOutput.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. -// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. - -using System.Collections.Immutable; - -namespace C2CS.Foundation.Tool; - -public abstract class ToolOutput -{ - public bool IsSuccess { get; private set; } - - public TInput Input { get; internal set; } = default!; - - public ImmutableArray Diagnostics { get; private set; } - - internal void Complete(ImmutableArray diagnostics) - { - Diagnostics = diagnostics; - - if (Input != null) - { - IsSuccess = CalculateIsSuccessful(diagnostics); - OnComplete(); - } - else - { - IsSuccess = false; - } - } - - protected abstract void OnComplete(); - - private static bool CalculateIsSuccessful(ImmutableArray diagnostics) - { - // ReSharper disable once ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator - foreach (var diagnostic in diagnostics) - { - if (diagnostic.Severity is - DiagnosticSeverity.Error or - DiagnosticSeverity.Panic) - { - return false; - } - } - - return true; - } -} diff --git a/src/cs/production/C2CS.Tool/Foundation/Tool/ToolUnsanitizedInput.cs b/src/cs/production/C2CS.Tool/Foundation/Tool/ToolUnsanitizedInput.cs deleted file mode 100644 index 049be86d..00000000 --- a/src/cs/production/C2CS.Tool/Foundation/Tool/ToolUnsanitizedInput.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. -// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. - -using System.Text.Json.Serialization; -using JetBrains.Annotations; - -namespace C2CS.Foundation.Tool; - -/// -/// Represents un-sanitized input for execution of some sort of computation. -/// -[PublicAPI] -public class ToolUnsanitizedInput -{ - /// - /// The working directory to use. - /// - /// - /// Default is null. If null, the current directory is used. - /// - [JsonIgnore] - public string? WorkingFileDirectory { get; set; } -} diff --git a/src/cs/production/C2CS.Tool/Foundation/HashCodeExtensions.cs b/src/cs/production/C2CS.Tool/HashCodeExtensions.cs similarity index 100% rename from src/cs/production/C2CS.Tool/Foundation/HashCodeExtensions.cs rename to src/cs/production/C2CS.Tool/HashCodeExtensions.cs diff --git a/src/cs/production/C2CS.Tool/Native/NativeArchitecture.cs b/src/cs/production/C2CS.Tool/Native/NativeArchitecture.cs deleted file mode 100644 index 583f6cbb..00000000 --- a/src/cs/production/C2CS.Tool/Native/NativeArchitecture.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. -// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. - -using System.Diagnostics.CodeAnalysis; -using JetBrains.Annotations; - -namespace C2CS.Native; - -/// -/// Defines the native computer architectures. -/// -[PublicAPI] -public enum NativeArchitecture -{ - /// - /// Unknown computer architecture. - /// - Unknown = 0, - - /// - /// Intel or AMD (Advanced Micro Devices) x86_x64 64-bit computing architecture. Commonly found in modern - /// desktop platforms such as Windows 10. Also commonly found in some eighth generation consoles such as Xbox - /// One and PlayStation 4. - /// - X64 = 1, - - /// - /// Intel or AMD (Advanced Micro Devices) x86 32-bit computing architecture. Commonly found in legacy desktop - /// platforms. - /// - X86 = 2, - - /// - /// ARM (Advanced RISC (Reduced Instruction Set Computer) Machines) 64-bit computing architecture. Commonly - /// found in modern mobile or some modern console platforms such as iOS, Nintendo Switch, etc. Also observed - /// in some modern laptops such as Apple Silicon. - /// - [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Product name.")] - ARM64, - - /// - /// ARM (Advanced RISC (Reduced Instruction Set Computer) Machines) 32-bit computing architecture. Commonly - /// found in legacy mobile or legacy console platforms. - /// - [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Product name.")] - ARM32 = 4, - - /// - /// WebAssembly 64-bit. - /// - [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Product name.")] - WASM64 = 5, - - /// - /// WebAssembly 32-bit. - /// - [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Product name.")] - WASM32 = 6 -} diff --git a/src/cs/production/C2CS.Tool/Native/NativeOperatingSystem.cs b/src/cs/production/C2CS.Tool/Native/NativeOperatingSystem.cs deleted file mode 100644 index 090cb9bb..00000000 --- a/src/cs/production/C2CS.Tool/Native/NativeOperatingSystem.cs +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. -// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. - -using System.Diagnostics.CodeAnalysis; -using JetBrains.Annotations; - -namespace C2CS.Native; - -/// -/// Defines the native operating systems. -/// -[PublicAPI] -public enum NativeOperatingSystem -{ - /// - /// Unknown operating system. - /// - Unknown = 0, - - /// - /// Versions of Windows operating system. - /// - Windows = 1, - - /// - /// Versions of macOS operating system. - /// - [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Product name.")] - [SuppressMessage( - "StyleCop.Naming", - "SA1300:ElementMustBeginWithUpperCaseLetter", - Justification = "Product name.")] - macOS = 2, - - /// - /// Distributions of the Linux operating system. - /// - Linux = 3, - - /// - /// Versions of FreeBSD operating system. - /// - [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Product name.")] - [SuppressMessage( - "StyleCop.Naming", - "SA1300:ElementMustBeginWithUpperCaseLetter", - Justification = "Product name.")] - FreeBSD = 4, - - /// - /// Mobile versions of Android operating system. - /// - Android = 5, - - /// - /// Mobile versions of iOS operating system. - /// - [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Product name.")] - [SuppressMessage( - "StyleCop.Naming", - "SA1300:ElementMustBeginWithUpperCaseLetter", - Justification = "Product name.")] - iOS = 6, - - /// - /// Micro console versions of tvOS operating system. - /// - [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Product name.")] - [SuppressMessage( - "StyleCop.Naming", - "SA1300:ElementMustBeginWithUpperCaseLetter", - Justification = "Product name.")] - tvOS = 7, - - /// - /// Not really an operating system, but rather versions of WebAssembly on some WASI - /// (WebAssembly System Interface) compliant host program such as a modern web browser. - /// - Browser = 8, - - /// - /// Versions of the PlayStation operating system. Otherwise known as "Orbis OS". Based on . - /// - PlayStation4 = 9, - - /// - /// Versions of the Xbox operating system. - /// - Xbox = 10, - - /// - /// Versions of the Nintendo Switch operating system. - /// - Switch = 11, - - /// - /// Versions of the Nintendo 3DS operating system. - /// - DualScreen3D = 12 -} diff --git a/src/cs/production/C2CS.Tool/Native/NativeUtility.cs b/src/cs/production/C2CS.Tool/Native/NativeUtility.cs deleted file mode 100644 index cdfcf946..00000000 --- a/src/cs/production/C2CS.Tool/Native/NativeUtility.cs +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. -// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. - -using System; -using System.Runtime.InteropServices; - -namespace C2CS.Native; - -public static class NativeUtility -{ - public static NativeOperatingSystem OperatingSystem - { - get - { - if (System.OperatingSystem.IsWindows()) - { - return NativeOperatingSystem.Windows; - } - - if (System.OperatingSystem.IsMacOS()) - { - return NativeOperatingSystem.macOS; - } - - if (System.OperatingSystem.IsLinux()) - { - return NativeOperatingSystem.Linux; - } - - if (System.OperatingSystem.IsAndroid()) - { - return NativeOperatingSystem.Android; - } - - if (System.OperatingSystem.IsIOS()) - { - return NativeOperatingSystem.iOS; - } - - if (System.OperatingSystem.IsTvOS()) - { - return NativeOperatingSystem.tvOS; - } - - if (System.OperatingSystem.IsBrowser()) - { - return NativeOperatingSystem.Browser; - } - - return NativeOperatingSystem.Unknown; - } - } - - public static NativeArchitecture Architecture - { - get - { - return RuntimeInformation.OSArchitecture switch - { - System.Runtime.InteropServices.Architecture.Arm64 => NativeArchitecture.ARM64, - System.Runtime.InteropServices.Architecture.Arm => NativeArchitecture.ARM32, - System.Runtime.InteropServices.Architecture.X86 => NativeArchitecture.X86, - System.Runtime.InteropServices.Architecture.X64 => NativeArchitecture.X64, - System.Runtime.InteropServices.Architecture.Wasm => NativeArchitecture.WASM32, - System.Runtime.InteropServices.Architecture.S390x => NativeArchitecture.Unknown, - _ => NativeArchitecture.Unknown - }; - } - } - - public static TargetPlatform Platform - { - get - { - var operatingSystem = OperatingSystem; - var architecture = Architecture; - - return operatingSystem switch - { - NativeOperatingSystem.Windows when architecture == NativeArchitecture.X64 => TargetPlatform - .x86_64_pc_windows_gnu, - NativeOperatingSystem.Windows when architecture == NativeArchitecture.X86 => TargetPlatform - .i686_pc_windows_gnu, - NativeOperatingSystem.Windows when architecture == NativeArchitecture.ARM64 => TargetPlatform - .aarch64_pc_windows_gnu, - NativeOperatingSystem.macOS when architecture == NativeArchitecture.ARM64 => TargetPlatform - .aarch64_apple_darwin, - NativeOperatingSystem.macOS when architecture == NativeArchitecture.X64 => TargetPlatform - .x86_64_apple_darwin, - NativeOperatingSystem.Linux when architecture == NativeArchitecture.X64 => TargetPlatform - .x86_64_unknown_linux_gnu, - NativeOperatingSystem.Linux when architecture == NativeArchitecture.X86 => TargetPlatform - .i686_unknown_linux_gnu, - NativeOperatingSystem.Linux when architecture == NativeArchitecture.ARM64 => TargetPlatform - .aarch64_unknown_linux_gnu, - _ => throw new InvalidOperationException("Unknown platform host.") - }; - } - } -} diff --git a/src/cs/production/C2CS.Tool/Native/Serialization/NativePlatformJsonConverter.cs b/src/cs/production/C2CS.Tool/Native/Serialization/NativePlatformJsonConverter.cs deleted file mode 100644 index acc05e07..00000000 --- a/src/cs/production/C2CS.Tool/Native/Serialization/NativePlatformJsonConverter.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. -// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. - -using System; -using System.Text.Json; -using System.Text.Json.Serialization; - -namespace C2CS.Native.Serialization; - -public class NativePlatformJsonConverter : JsonConverter -{ - public override TargetPlatform Read( - ref Utf8JsonReader reader, - Type typeToConvert, - JsonSerializerOptions options) - { - var value = reader.GetString(); - if (string.IsNullOrEmpty(value)) - { - return TargetPlatform.Unknown; - } - - var result = new TargetPlatform(value); - return result; - } - - public override void Write( - Utf8JsonWriter writer, - TargetPlatform value, - JsonSerializerOptions options) - { - writer.WriteStringValue(value.TargetName); - } -} diff --git a/src/cs/production/C2CS.Tool/Native/TargetPlatform.cs b/src/cs/production/C2CS.Tool/Native/TargetPlatform.cs deleted file mode 100644 index b7cc65cb..00000000 --- a/src/cs/production/C2CS.Tool/Native/TargetPlatform.cs +++ /dev/null @@ -1,290 +0,0 @@ -// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. -// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. - -using System; -using System.Text.Json.Serialization; -using C2CS.Native.Serialization; -using JetBrains.Annotations; - -namespace C2CS.Native; - -// ReSharper disable InconsistentNaming -#pragma warning disable SA1124 -#pragma warning disable SA1300 -#pragma warning disable SA1307 -#pragma warning disable SA1310 -#pragma warning disable SA1311 -#pragma warning disable SA1313 -#pragma warning disable CA2211 -#pragma warning disable CA1707 -#pragma warning disable IDE1006 - -/// -/// Defines the native platforms. -/// -[PublicAPI] -[JsonConverter(typeof(NativePlatformJsonConverter))] -public record struct TargetPlatform(string TargetName) -{ - /// - /// Unknown runtime platform. - /// - public static readonly TargetPlatform Unknown = new("unknown-unknown-unknown"); - - #region Sony - - /// - /// PlayStation 4 (64-bit). - /// - public static readonly TargetPlatform x86_64_scei_ps4 = new("x86_64-scei-ps4"); - - #endregion - - #region Nintendo - - /// - /// Nintendo 3DS (32-bit). - /// - public static readonly TargetPlatform armv6k_nintendo_3ds = new("armv6k-nintendo-3ds"); - - #endregion - - /// - /// The runtime computer architecture. - /// - public NativeArchitecture Architecture = ParseTargetArchitecture(TargetName); - - /// - /// The runtime operating system. - /// - public NativeOperatingSystem OperatingSystem = ParseTargetOperatingSystem(TargetName); - - internal string TargetName = TargetName; - - private static NativeArchitecture ParseTargetArchitecture(string targetTriple) - { - if (targetTriple.StartsWith("aarch64-", StringComparison.InvariantCultureIgnoreCase) || - targetTriple.StartsWith("arm64-", StringComparison.InvariantCultureIgnoreCase)) - { - return NativeArchitecture.ARM64; - } - - if (targetTriple.StartsWith("x86_64-", StringComparison.InvariantCultureIgnoreCase)) - { - return NativeArchitecture.X64; - } - - if (targetTriple.StartsWith("i686-", StringComparison.InvariantCultureIgnoreCase)) - { - return NativeArchitecture.X86; - } - - if (targetTriple.StartsWith("arm-", StringComparison.InvariantCultureIgnoreCase) || - targetTriple.StartsWith("armv7-", StringComparison.InvariantCultureIgnoreCase) || - targetTriple.StartsWith("armv6k-", StringComparison.InvariantCultureIgnoreCase)) - { - return NativeArchitecture.ARM32; - } - - if (targetTriple.StartsWith("wasm64", StringComparison.InvariantCultureIgnoreCase)) - { - return NativeArchitecture.WASM64; - } - - if (targetTriple.StartsWith("wasm32", StringComparison.InvariantCultureIgnoreCase)) - { - return NativeArchitecture.WASM32; - } - - return NativeArchitecture.Unknown; - } - - private static NativeOperatingSystem ParseTargetOperatingSystem(string targetTriple) - { - if (targetTriple.Contains("-pc-windows", StringComparison.InvariantCultureIgnoreCase)) - { - return NativeOperatingSystem.Windows; - } - - if (targetTriple.Contains("-unknown-linux", StringComparison.InvariantCultureIgnoreCase)) - { - return NativeOperatingSystem.Linux; - } - - if (targetTriple.Contains("-apple-darwin", StringComparison.InvariantCultureIgnoreCase)) - { - return NativeOperatingSystem.macOS; - } - - if (targetTriple.Contains("-apple-ios", StringComparison.InvariantCultureIgnoreCase)) - { - return NativeOperatingSystem.iOS; - } - - if (targetTriple.Contains("-apple-tvos", StringComparison.InvariantCultureIgnoreCase)) - { - return NativeOperatingSystem.tvOS; - } - - if (targetTriple.Contains("-unknown-freebsd", StringComparison.InvariantCultureIgnoreCase)) - { - return NativeOperatingSystem.FreeBSD; - } - - if (targetTriple.Contains("-linux-android", StringComparison.InvariantCultureIgnoreCase)) - { - return NativeOperatingSystem.Android; - } - - if (targetTriple.Contains("-scei-ps4", StringComparison.InvariantCultureIgnoreCase)) - { - return NativeOperatingSystem.PlayStation4; - } - - if (targetTriple.Contains("-nintendo_3ds", StringComparison.InvariantCultureIgnoreCase)) - { - return NativeOperatingSystem.DualScreen3D; - } - - if (targetTriple.StartsWith("wasm", StringComparison.InvariantCultureIgnoreCase)) - { - return NativeOperatingSystem.Browser; - } - - return NativeOperatingSystem.Unknown; - } - - public override string ToString() - { - return TargetName; - } - - #region Windows - - /// - /// X86 Windows (32-bit, Windows 7+) using Microsoft's compiler and linker. - /// - public static readonly TargetPlatform i686_pc_windows_msvc = new("i686-pc-windows-msvc"); - - /// - /// X64 Windows (64-bit, Windows 7+) using Microsoft's compiler and linker. - /// - public static readonly TargetPlatform x86_64_pc_windows_msvc = new("x86_64-pc-windows-msvc"); - - /// - /// ARM64 Windows (64-bit) using Microsoft's compiler and linker. - /// - public static readonly TargetPlatform aarch64_pc_windows_msvc = new("aarch64-pc-windows-msvc"); - - /// - /// X86 Windows (32-bit, Windows 7+) using GNU's Compiler Collection (GCC). - /// - public static readonly TargetPlatform i686_pc_windows_gnu = new("i686-pc-windows-gnu"); - - /// - /// X64 Windows (64-bit, Windows 7+) using GNU's Compiler Collection (GCC). - /// - public static readonly TargetPlatform x86_64_pc_windows_gnu = new("x86_64-pc-windows-gnu"); - - /// - /// ARM64 Windows (64-bit) using GNU's Compiler Collection (GCC). - /// - public static readonly TargetPlatform aarch64_pc_windows_gnu = new("aarch64-pc-windows-gnu"); - - #endregion - - #region Linux - - /// - /// X86 Linux (32-bit, kernel 2.6.32+, glibc 2.11+). - /// - public static readonly TargetPlatform i686_unknown_linux_gnu = new("i686-unknown-linux-gnu"); - - /// - /// X64 Linux (64-bit, kernel 2.6.32+, glibc 2.11+). - /// - public static readonly TargetPlatform x86_64_unknown_linux_gnu = new("x86_64-unknown-linux-gnu"); - - /// - /// ARM64 Linux (64-bit, kernel 4.2, glibc 2.17+). - /// - public static readonly TargetPlatform aarch64_unknown_linux_gnu = new("aarch64-unknown-linux-gnu"); - - #endregion - - #region macOS - - /// - /// X86 macOS (32-bit, 10.7+, Lion+). - /// - public static readonly TargetPlatform i686_apple_darwin = new("i686-apple-darwin"); - - /// - /// X64 macOS (64-bit, 10.7+, Lion+). - /// - public static readonly TargetPlatform x86_64_apple_darwin = new("x86_64-apple-darwin"); - - /// - /// ARM64 macOS (64-bit, 11.0+, Big Sur+). - /// - public static readonly TargetPlatform aarch64_apple_darwin = new("aarch64-apple-darwin"); - - #endregion - - #region iOS - - /// - /// ARM64 iOS (64-bit). - /// - public static readonly TargetPlatform aarch64_apple_ios = new("aarch64-apple-ios"); - - /// - /// ARM64 iOS simulator (64-bit). - /// - public static readonly TargetPlatform aarch64_apple_ios_sim = new("aarch64-apple-ios-sim"); - - /// - /// X64 iOS (64-bit). - /// - public static readonly TargetPlatform x86_64_apple_ios = new("x86_64-apple-ios"); - - #endregion - - #region Android - - /// - /// ARM64 Android (64-bit). - /// - public static readonly TargetPlatform aarch64_linux_android = new("aarch64-linux-android"); - - /// - /// ARM32 (ARMv7) Android (32-bit). - /// - public static readonly TargetPlatform arm_linux_androideabi = new("arm-linux-androideabi"); - - /// - /// X86 Android (32-bit). - /// - public static readonly TargetPlatform i686_linux_android = new("i686-linux-android"); - - /// - /// X64 Android (64-bit). - /// - public static readonly TargetPlatform x86_64_linux_android = new("x86_64-linux-android"); - - #endregion - - #region Browser - - /// - /// WebAssembly (32-bit). - /// - public static readonly TargetPlatform wasm32_unknown_unknown = new("wasm32-unknown-unknown"); - - /// - /// WebAssembly via Emscripten (32-bit). - /// - public static readonly TargetPlatform wasm32_unknown_emscripten = new("wasm32-unknown-emscripten"); - - #endregion -} diff --git a/src/cs/production/C2CS.Tool/Native/Terminal.cs b/src/cs/production/C2CS.Tool/Native/Terminal.cs deleted file mode 100644 index a67c7c3d..00000000 --- a/src/cs/production/C2CS.Tool/Native/Terminal.cs +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. -// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. - -using System; -using System.Diagnostics; -using System.IO; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading; -using JetBrains.Annotations; - -// ReSharper disable once EmptyNamespace -namespace C2CS.Native; - -[PublicAPI] -public static class Terminal -{ - public static ShellOutput ExecuteShell( - this string command, - string? workingDirectory = null, - string? fileName = null, - bool windowsUsePowerShell = true) - { - using var process = CreateShellProcess(command, workingDirectory, fileName, windowsUsePowerShell); - var stringBuilder = new StringBuilder(); - using var stringWriter = new StringWriter(stringBuilder); - var spinLock = default(SpinLock); - - process.OutputDataReceived += OnProcessOnErrorDataReceived; - process.ErrorDataReceived += OnProcessOnErrorDataReceived; - - void OnProcessOnErrorDataReceived(object sender, DataReceivedEventArgs args) - { - var gotLock = false; - spinLock.Enter(ref gotLock); - // ReSharper disable once AccessToDisposedClosure - stringWriter.WriteLine(args.Data); - if (gotLock) - { - spinLock.Exit(); - } - } - - process.Start(); - process.BeginErrorReadLine(); - process.BeginOutputReadLine(); - process.WaitForExit(); - - var outputString = stringBuilder.ToString().Trim('\n', '\r'); - - var result = new ShellOutput - { - ExitCode = process.ExitCode, - Output = outputString - }; - return result; - } - - private static Process CreateShellProcess( - string command, string? workingDirectory, string? fileName, bool windowsUsePowerShell = true) - { - if (workingDirectory != null && !Directory.Exists(workingDirectory)) - { - throw new DirectoryNotFoundException(workingDirectory); - } - - var processStartInfo = new ProcessStartInfo - { - UseShellExecute = false, - RedirectStandardOutput = true, - RedirectStandardError = true, - WorkingDirectory = workingDirectory ?? Environment.CurrentDirectory, - CreateNoWindow = true - }; - - if (!string.IsNullOrEmpty(fileName)) - { - processStartInfo.FileName = fileName; - processStartInfo.Arguments = command; - } - else - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - if (windowsUsePowerShell) - { - processStartInfo.FileName = "powershell.exe"; - } - else - { - var bashFilePath = WindowsBashFilePath(); - if (string.IsNullOrEmpty(bashFilePath)) - { - throw new FileNotFoundException( - "Failed to find a `git-bash.exe` or `bash.exe` on Windows. Did you forget to install Git Bash and/or add it to your PATH?"); - } - - processStartInfo.FileName = bashFilePath; - } - } - else - { - processStartInfo.FileName = "bash"; - } - -#pragma warning disable CA1307 - var escapedArgs = command.Replace("\"", "\\\""); -#pragma warning restore CA1307 - processStartInfo.Arguments = $"-c \"{escapedArgs}\""; - } - - var process = new Process - { - StartInfo = processStartInfo - }; - return process; - } - - private static string WindowsBashFilePath() - { - var candidateBashFilePath = Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Git", "bin", "bash.exe"); - if (File.Exists(candidateBashFilePath)) - { - return candidateBashFilePath; - } - - candidateBashFilePath = Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Git", "bin", "bash.exe"); - if (File.Exists(candidateBashFilePath)) - { - return candidateBashFilePath; - } - - var environmentVariablePath = Environment.GetEnvironmentVariable("PATH"); - var searchDirectories = environmentVariablePath?.Split(';') ?? Array.Empty(); - - foreach (var searchDirectory in searchDirectories) - { - candidateBashFilePath = Path.Combine(searchDirectory, "bash.exe"); - if (File.Exists(candidateBashFilePath)) - { - return candidateBashFilePath; - } - } - - return string.Empty; - } - -#pragma warning disable CA1034 - [PublicAPI] - public class ShellOutput -#pragma warning restore CA1034 - { - public int ExitCode { get; set; } - - public string Output { get; set; } = string.Empty; - } -} diff --git a/src/cs/tests/C2CS.Tests/C2CS.Tests.csproj b/src/cs/tests/C2CS.Tests/C2CS.Tests.csproj index 54951161..363c2703 100644 --- a/src/cs/tests/C2CS.Tests/C2CS.Tests.csproj +++ b/src/cs/tests/C2CS.Tests/C2CS.Tests.csproj @@ -2,7 +2,7 @@ - net7.0 + net8.0 enable false C2CS.Tests @@ -12,19 +12,18 @@ $(NoWarn);CA1707;CA2000;SA1300;IDE1006;CA1034;CA1051;CA1062;CA1724 true - + + + - - - + - runtime; build; native; contentfiles; analyzers; buildtransitive @@ -36,6 +35,11 @@ + + + + + @@ -43,9 +47,10 @@ PreserveNewest - + + - + diff --git a/src/cs/tests/C2CS.Tests/Data/Values/Enums/EnumForceSInt32.json b/src/cs/tests/C2CS.Tests/Data/Values/Enums/EnumForceSInt32.json index eae7a250..edb13bf4 100644 --- a/src/cs/tests/C2CS.Tests/Data/Values/Enums/EnumForceSInt32.json +++ b/src/cs/tests/C2CS.Tests/Data/Values/Enums/EnumForceSInt32.json @@ -28,7 +28,7 @@ }, { "name": "_ENUM_FORCE_SINT32", - "value": "8388607" + "value": "2147483647" } ] } \ No newline at end of file diff --git a/src/cs/tests/C2CS.Tests/Data/Values/Enums/EnumForceSInt64.json b/src/cs/tests/C2CS.Tests/Data/Values/Enums/EnumForceSInt64.json deleted file mode 100644 index fe35c3f1..00000000 --- a/src/cs/tests/C2CS.Tests/Data/Values/Enums/EnumForceSInt64.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "name": "EnumForceSInt64", - "base_type": "int", - "members": [ - { - "name": "ENUM_FORCE_SINT64_DAY_UNKNOWN", - "value": "0" - }, - { - "name": "ENUM_FORCE_SINT64_DAY_MONDAY", - "value": "1" - }, - { - "name": "ENUM_FORCE_SINT64_DAY_TUESDAY", - "value": "2" - }, - { - "name": "ENUM_FORCE_SINT64_DAY_WEDNESDAY", - "value": "3" - }, - { - "name": "ENUM_FORCE_SINT64_DAY_THURSDAY", - "value": "4" - }, - { - "name": "ENUM_FORCE_SINT64_DAY_FRIDAY", - "value": "5" - }, - { - "name": "_ENUM_FORCE_SINT64", - "value": "2147483647" - } - ] -} \ No newline at end of file diff --git a/src/cs/tests/C2CS.Tests/Data/Values/Enums/EnumForceUInt32.json b/src/cs/tests/C2CS.Tests/Data/Values/Enums/EnumForceUInt32.json index 8304509f..381d55b8 100644 --- a/src/cs/tests/C2CS.Tests/Data/Values/Enums/EnumForceUInt32.json +++ b/src/cs/tests/C2CS.Tests/Data/Values/Enums/EnumForceUInt32.json @@ -1,34 +1,34 @@ { "name": "EnumForceUInt32", - "base_type": "long", + "base_type": "int", "members": [ { "name": "ENUM_FORCE_UINT32_DAY_UNKNOWN", - "value": "0L" + "value": "0" }, { "name": "ENUM_FORCE_UINT32_DAY_MONDAY", - "value": "1L" + "value": "1" }, { "name": "ENUM_FORCE_UINT32_DAY_TUESDAY", - "value": "2L" + "value": "2" }, { "name": "ENUM_FORCE_UINT32_DAY_WEDNESDAY", - "value": "3L" + "value": "3" }, { "name": "ENUM_FORCE_UINT32_DAY_THURSDAY", - "value": "4L" + "value": "4" }, { "name": "ENUM_FORCE_UINT32_DAY_FRIDAY", - "value": "5L" + "value": "5" }, { "name": "_ENUM_FORCE_UINT32", - "value": "-1L" + "value": "-1" } ] } \ No newline at end of file diff --git a/src/cs/tests/C2CS.Tests/Data/Values/Enums/EnumForceUInt64.json b/src/cs/tests/C2CS.Tests/Data/Values/Enums/EnumForceUInt64.json deleted file mode 100644 index 12b30e0a..00000000 --- a/src/cs/tests/C2CS.Tests/Data/Values/Enums/EnumForceUInt64.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "name": "EnumForceUInt64", - "base_type": "int", - "members": [ - { - "name": "ENUM_FORCE_UINT64_DAY_UNKNOWN", - "value": "0" - }, - { - "name": "ENUM_FORCE_UINT64_DAY_MONDAY", - "value": "1" - }, - { - "name": "ENUM_FORCE_UINT64_DAY_TUESDAY", - "value": "2" - }, - { - "name": "ENUM_FORCE_UINT64_DAY_WEDNESDAY", - "value": "3" - }, - { - "name": "ENUM_FORCE_UINT64_DAY_THURSDAY", - "value": "4" - }, - { - "name": "ENUM_FORCE_UINT64_DAY_FRIDAY", - "value": "5" - }, - { - "name": "_ENUM_FORCE_UINT64", - "value": "-1" - } - ] -} \ No newline at end of file diff --git a/src/cs/tests/C2CS.Tests/Foundation/Startup.cs b/src/cs/tests/C2CS.Tests/Foundation/Startup.cs deleted file mode 100644 index 09881412..00000000 --- a/src/cs/tests/C2CS.Tests/Foundation/Startup.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. -// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. - -using C2CS.Features.BuildCLibrary.Domain; -using Microsoft.Extensions.DependencyInjection; - -namespace C2CS.Tests.Foundation; - -public static class Startup -{ - public static void ConfigureServices(IServiceCollection services) - { - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - } -} diff --git a/src/cs/tests/C2CS.Tests/Generated/AssemblyAttributes.gen.cs b/src/cs/tests/C2CS.Tests/Generated/AssemblyAttributes.gen.cs index 74c761ff..55ba0502 100644 --- a/src/cs/tests/C2CS.Tests/Generated/AssemblyAttributes.gen.cs +++ b/src/cs/tests/C2CS.Tests/Generated/AssemblyAttributes.gen.cs @@ -1,6 +1,6 @@ // To disable generating this file set `isEnabledGenerateAssemblyAttributes` to `false` in the config file for generating C# code. // -// This code was generated by the following tool on 2023-11-15 18:22:18 GMT-05:00: +// This code was generated by the following tool on 2023-11-22 16:29:55 GMT-05:00: // https://github.com/bottlenoselabs/c2cs (v2.11.1.100) // // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. diff --git a/src/cs/tests/C2CS.Tests/Generated/Runtime.gen.cs b/src/cs/tests/C2CS.Tests/Generated/Runtime.gen.cs index 9f9d7e13..b75d17c9 100644 --- a/src/cs/tests/C2CS.Tests/Generated/Runtime.gen.cs +++ b/src/cs/tests/C2CS.Tests/Generated/Runtime.gen.cs @@ -2,7 +2,7 @@ // To disable generating this file set `isEnabledGeneratingRuntimeCode` to `false` in the config file for generating C# code. // -// This code was generated by the following tool on 2023-11-15 18:22:18 GMT-05:00: +// This code was generated by the following tool on 2023-11-22 16:29:55 GMT-05:00: // https://github.com/bottlenoselabs/c2cs (v2.11.1.100) // // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. diff --git a/src/cs/tests/C2CS.Tests/Generated/_container_library.gen.cs b/src/cs/tests/C2CS.Tests/Generated/_container_library.gen.cs index 61e4be5a..c2c7b007 100644 --- a/src/cs/tests/C2CS.Tests/Generated/_container_library.gen.cs +++ b/src/cs/tests/C2CS.Tests/Generated/_container_library.gen.cs @@ -1,6 +1,6 @@ // -// This code was generated by the following tool on 2023-11-15 18:22:18 GMT-05:00: +// This code was generated by the following tool on 2023-11-22 16:29:55 GMT-05:00: // https://github.com/bottlenoselabs/c2cs (v2.11.1.100) // // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. @@ -131,19 +131,19 @@ public enum EnumForceSInt32 : int ENUM_FORCE_SINT32_DAY_WEDNESDAY = 3, ENUM_FORCE_SINT32_DAY_THURSDAY = 4, ENUM_FORCE_SINT32_DAY_FRIDAY = 5, - _ENUM_FORCE_SINT32 = 8388607 + _ENUM_FORCE_SINT32 = 2147483647 } [CNode(Kind = "Enum")] - public enum EnumForceSInt64 : int + public enum EnumForceSInt64 : long { - ENUM_FORCE_SINT64_DAY_UNKNOWN = 0, - ENUM_FORCE_SINT64_DAY_MONDAY = 1, - ENUM_FORCE_SINT64_DAY_TUESDAY = 2, - ENUM_FORCE_SINT64_DAY_WEDNESDAY = 3, - ENUM_FORCE_SINT64_DAY_THURSDAY = 4, - ENUM_FORCE_SINT64_DAY_FRIDAY = 5, - _ENUM_FORCE_SINT64 = 2147483647 + ENUM_FORCE_SINT64_DAY_UNKNOWN = 0L, + ENUM_FORCE_SINT64_DAY_MONDAY = 1L, + ENUM_FORCE_SINT64_DAY_TUESDAY = 2L, + ENUM_FORCE_SINT64_DAY_WEDNESDAY = 3L, + ENUM_FORCE_SINT64_DAY_THURSDAY = 4L, + ENUM_FORCE_SINT64_DAY_FRIDAY = 5L, + _ENUM_FORCE_SINT64 = 9223372036854775807L } [CNode(Kind = "Enum")] @@ -171,27 +171,27 @@ public enum EnumForceUInt16 : int } [CNode(Kind = "Enum")] - public enum EnumForceUInt32 : long + public enum EnumForceUInt32 : int { - ENUM_FORCE_UINT32_DAY_UNKNOWN = 0L, - ENUM_FORCE_UINT32_DAY_MONDAY = 1L, - ENUM_FORCE_UINT32_DAY_TUESDAY = 2L, - ENUM_FORCE_UINT32_DAY_WEDNESDAY = 3L, - ENUM_FORCE_UINT32_DAY_THURSDAY = 4L, - ENUM_FORCE_UINT32_DAY_FRIDAY = 5L, - _ENUM_FORCE_UINT32 = -1L + ENUM_FORCE_UINT32_DAY_UNKNOWN = 0, + ENUM_FORCE_UINT32_DAY_MONDAY = 1, + ENUM_FORCE_UINT32_DAY_TUESDAY = 2, + ENUM_FORCE_UINT32_DAY_WEDNESDAY = 3, + ENUM_FORCE_UINT32_DAY_THURSDAY = 4, + ENUM_FORCE_UINT32_DAY_FRIDAY = 5, + _ENUM_FORCE_UINT32 = -1 } [CNode(Kind = "Enum")] - public enum EnumForceUInt64 : int + public enum EnumForceUInt64 : long { - ENUM_FORCE_UINT64_DAY_UNKNOWN = 0, - ENUM_FORCE_UINT64_DAY_MONDAY = 1, - ENUM_FORCE_UINT64_DAY_TUESDAY = 2, - ENUM_FORCE_UINT64_DAY_WEDNESDAY = 3, - ENUM_FORCE_UINT64_DAY_THURSDAY = 4, - ENUM_FORCE_UINT64_DAY_FRIDAY = 5, - _ENUM_FORCE_UINT64 = -1 + ENUM_FORCE_UINT64_DAY_UNKNOWN = 0L, + ENUM_FORCE_UINT64_DAY_MONDAY = 1L, + ENUM_FORCE_UINT64_DAY_TUESDAY = 2L, + ENUM_FORCE_UINT64_DAY_WEDNESDAY = 3L, + ENUM_FORCE_UINT64_DAY_THURSDAY = 4L, + ENUM_FORCE_UINT64_DAY_FRIDAY = 5L, + _ENUM_FORCE_UINT64 = -1L } [CNode(Kind = "Enum")] diff --git a/src/cs/tests/C2CS.Tests/Foundation/TestBase.cs b/src/cs/tests/C2CS.Tests/TestBase.cs similarity index 89% rename from src/cs/tests/C2CS.Tests/Foundation/TestBase.cs rename to src/cs/tests/C2CS.Tests/TestBase.cs index 95e7bfc3..7aeeb4e2 100644 --- a/src/cs/tests/C2CS.Tests/Foundation/TestBase.cs +++ b/src/cs/tests/C2CS.Tests/TestBase.cs @@ -10,7 +10,7 @@ using FluentAssertions; using Microsoft.Extensions.DependencyInjection; -namespace C2CS.Tests.Foundation; +namespace C2CS.Tests; public abstract class TestBase { @@ -29,8 +29,10 @@ protected TestBase(string baseDataFilesDirectory, bool regenerateDataFiles = fal Services = TestHost.Services; _fileSystem = Services.GetService()!; + var path = _fileSystem.Path; - _sourceDirectoryPath = Path.Combine(GetGitDirectory(), "src/cs/tests/C2CS.Tests"); + _sourceDirectoryPath = path.Combine(GetGitDirectory(), "src", "cs", "tests", "C2CS.Tests"); + _baseDataFilesDirectory = path.Combine(_sourceDirectoryPath, baseDataFilesDirectory); _regenerateDataFiles = regenerateDataFiles; _jsonSerializerOptions = new JsonSerializerOptions @@ -56,18 +58,12 @@ protected void AssertValue(string name, T value, string directory) nameNormalized = nameAsWordsTitleCased.Replace(" ", string.Empty, StringComparison.InvariantCulture); } - var relativeJsonFilePath = - _fileSystem.Path.Combine(_baseDataFilesDirectory, directory, $"{nameNormalized}.json"); - string jsonFilePath; + var jsonFilePath = _fileSystem.Path.Combine( + _baseDataFilesDirectory, directory, $"{nameNormalized}.json"); if (_regenerateDataFiles) { - jsonFilePath = _fileSystem.Path.Combine(_sourceDirectoryPath, relativeJsonFilePath); RegenerateDataFile(jsonFilePath, value); } - else - { - jsonFilePath = _fileSystem.Path.Combine(AppContext.BaseDirectory, relativeJsonFilePath); - } var expectedValue = ReadValueFromFile(jsonFilePath); value.Should().BeEquivalentTo( diff --git a/src/cs/tests/C2CS.Tests/TestCSharpCode.cs b/src/cs/tests/C2CS.Tests/TestCSharpCode.cs index f8ab6d80..01724109 100644 --- a/src/cs/tests/C2CS.Tests/TestCSharpCode.cs +++ b/src/cs/tests/C2CS.Tests/TestCSharpCode.cs @@ -1,7 +1,6 @@ // Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. // Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. -using C2CS.Tests.Foundation; using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; using Xunit; @@ -16,12 +15,9 @@ public sealed class TestCSharpCode : TestBase "EnumForceSInt8", "EnumForceSInt16", "EnumForceSInt32", - "EnumForceSInt64", - "EnumForceUInt8", "EnumForceUInt16", "EnumForceUInt32", - "EnumForceUInt64" }; [Theory] @@ -54,7 +50,7 @@ public void Compiles() private readonly TestFixtureCSharpCode _fixture; public TestCSharpCode() - : base("Data/Values", regenerateDataFiles: true) + : base("Data/Values", regenerateDataFiles: false) { var services = TestHost.Services; _fixture = services.GetService()!; diff --git a/src/cs/tests/C2CS.Tests/TestFixtureCSharpCode.cs b/src/cs/tests/C2CS.Tests/TestFixtureCSharpCode.cs index bcce5a39..8af0df57 100644 --- a/src/cs/tests/C2CS.Tests/TestFixtureCSharpCode.cs +++ b/src/cs/tests/C2CS.Tests/TestFixtureCSharpCode.cs @@ -7,13 +7,12 @@ using System.IO; using System.Reflection; using System.Runtime.InteropServices; +using bottlenoselabs.Common; using C2CS.Features.BuildCLibrary.Domain; using C2CS.Features.BuildCLibrary.Input.Sanitized; using C2CS.Features.WriteCodeCSharp; using C2CS.Features.WriteCodeCSharp.Output; -using C2CS.Native; using C2CS.Tests.Data.Models; -using C2CS.Tests.Foundation; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.Extensions.DependencyInjection; @@ -32,7 +31,7 @@ public sealed class TestFixtureCSharpCode public TestFixtureCSharpCode() { var sourceDirectoryPath = GetSourceDirectoryPath(); - var bindgenConfigFilePath = GetBindgenConfigFilePath(sourceDirectoryPath); + var bindgenConfigFilePath = Path.Combine(sourceDirectoryPath, "config-extract.json"); GenerateCAbstractSyntaxTree(bindgenConfigFilePath, sourceDirectoryPath); BuildCLibrary(sourceDirectoryPath, ImmutableArray.Empty); @@ -115,7 +114,7 @@ private static void GenerateCAbstractSyntaxTree( string bindgenConfigFilePath, string sourceDirectoryPath) { - var extractShellOutput = $"castffi extract --config {bindgenConfigFilePath}".ExecuteShell(); + var extractShellOutput = $"castffi extract --config {bindgenConfigFilePath}".ExecuteShellCommand(); Assert.True(extractShellOutput.ExitCode == 0, "error extracting platform ASTs"); var abstractSyntaxTreeDirectoryPath = Path.GetFullPath(Path.Combine(sourceDirectoryPath, "ast")); @@ -123,7 +122,7 @@ private static void GenerateCAbstractSyntaxTree( Path.GetFullPath(Path.Combine(sourceDirectoryPath, "ast", "cross-platform.json")); var astShellOutput = $"castffi merge --inputDirectoryPath {abstractSyntaxTreeDirectoryPath} --outputFilePath {mergedAbstractSyntaxTreeFilePath}" - .ExecuteShell(); + .ExecuteShellCommand(); Assert.True(astShellOutput.ExitCode == 0, "error merging platform ASTs"); } @@ -215,7 +214,7 @@ private static nint NativeLibraryResolver( Assembly assembly, DllImportSearchPath? searchPath) { - var fileName = NativeUtility.OperatingSystem switch + var fileName = Native.OperatingSystem switch { NativeOperatingSystem.Windows => "_container_library.dll", NativeOperatingSystem.macOS => "lib_container_library.dylib", @@ -526,18 +525,4 @@ private static string GetGitRepositoryPath() } } } - - private static string GetBindgenConfigFilePath(string sourceDirectoryPath) - { - var bindgenConfigFileName = NativeUtility.OperatingSystem switch - { - NativeOperatingSystem.Windows => "config-windows.json", - NativeOperatingSystem.macOS => "config-macos.json", - NativeOperatingSystem.Linux => "config-linux.json", - _ => throw new NotImplementedException() - }; - - var bindgenConfigFilePath = Path.GetFullPath(Path.Combine(sourceDirectoryPath, bindgenConfigFileName)); - return bindgenConfigFilePath; - } } diff --git a/src/cs/tests/C2CS.Tests/Foundation/TestHost.cs b/src/cs/tests/C2CS.Tests/TestHost.cs similarity index 55% rename from src/cs/tests/C2CS.Tests/Foundation/TestHost.cs rename to src/cs/tests/C2CS.Tests/TestHost.cs index 33609ac7..b2518b4f 100644 --- a/src/cs/tests/C2CS.Tests/Foundation/TestHost.cs +++ b/src/cs/tests/C2CS.Tests/TestHost.cs @@ -2,9 +2,11 @@ // Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. using System; +using C2CS.Features.BuildCLibrary.Domain; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -namespace C2CS.Tests.Foundation; +namespace C2CS.Tests; public static class TestHost { @@ -15,8 +17,16 @@ public static class TestHost private static IHostBuilder HostBuilder() { var result = new HostBuilder() - .BuildHostCommon().ConfigureServices(Startup.ConfigureServices); + .BuildHostCommon() + .ConfigureServices(ConfigureServices); return result; } + + private static void ConfigureServices(IServiceCollection services) + { + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + } } diff --git a/src/cs/tests/C2CS.Tests/appsettings.json b/src/cs/tests/C2CS.Tests/appsettings.json index d5819940..6c46bbfc 100644 --- a/src/cs/tests/C2CS.Tests/appsettings.json +++ b/src/cs/tests/C2CS.Tests/appsettings.json @@ -3,7 +3,7 @@ "Console": { "LogLevel": { "Default": "Warning", - "C2CS": "Warning" + "C2CS": "Information" }, "FormatterOptions": { "ColorBehavior": "Disabled", diff --git a/src/cs/tests/C2CS.Tests/config-extract.json b/src/cs/tests/C2CS.Tests/config-extract.json new file mode 100644 index 00000000..df0d372d --- /dev/null +++ b/src/cs/tests/C2CS.Tests/config-extract.json @@ -0,0 +1,21 @@ +{ + "inputFilePath": "../../../c/tests/_container_library/main.c", + "userIncludeDirectories": [ + "../../../c/production/ffi_helper/include", + "../../../c/tests/_container_library" + ], + "targetPlatforms": { + "windows": { + "x86_64-pc-windows-msvc": {}, + "aarch64-pc-windows-msvc": {} + }, + "macos": { + "aarch64-apple-darwin": {}, + "x86_64-apple-darwin": {} + }, + "linux": { + "x86_64-unknown-linux-gnu": {}, + "aarch64-unknown-linux-gnu": {} + } + } +} diff --git a/src/cs/tests/C2CS.Tests/config-linux.json b/src/cs/tests/C2CS.Tests/config-linux.json deleted file mode 100644 index 51d6c3a7..00000000 --- a/src/cs/tests/C2CS.Tests/config-linux.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "inputFilePath": "../../../c/tests/_container_library/main.c", - "userIncludeDirectories": [ - "../../../c/production/ffi_helper/include", - "../../../c/tests/_container_library" - ], - "platforms": { - "x86_64-unknown-linux-gnu": {}, - "aarch64-unknown-linux-gnu": {} - } -} diff --git a/src/cs/tests/C2CS.Tests/config-macos.json b/src/cs/tests/C2CS.Tests/config-macos.json deleted file mode 100644 index 12786c0a..00000000 --- a/src/cs/tests/C2CS.Tests/config-macos.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "inputFilePath": "../../../c/tests/_container_library/main.c", - "userIncludeDirectories": [ - "../../../c/production/ffi_helper/include", - "../../../c/tests/_container_library" - ], - "platforms": { - "aarch64-apple-darwin": {}, - "x86_64-apple-darwin": {} - } -} diff --git a/src/cs/tests/C2CS.Tests/config-windows.json b/src/cs/tests/C2CS.Tests/config-windows.json deleted file mode 100644 index d67c706d..00000000 --- a/src/cs/tests/C2CS.Tests/config-windows.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "inputFilePath": "../../../c/tests/_container_library/main.c", - "userIncludeDirectories": [ - "../../../c/production/ffi_helper/include", - "../../../c/tests/_container_library" - ], - "platforms": { - "x86_64-pc-windows-msvc": {}, - "aarch64-pc-windows-msvc": {} - } -}