Skip to content

Commit

Permalink
Linux Soup View (#296)
Browse files Browse the repository at this point in the history
* Get view working on linux
* Fix paths
* Fix open flags for linux monitor
  • Loading branch information
mwasplund authored Jan 18, 2025
1 parent 5b9f9c8 commit 2a169a9
Show file tree
Hide file tree
Showing 19 changed files with 123 additions and 37 deletions.
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
"stopAtEntry": false,
"console": "internalConsole"
},
{
"name": "Debug Soup View",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "",
"program": "${workspaceFolder}/out/msbuild/bin/SoupView/Debug/net9.0/linux-x64/SoupView.dll",
"args": [ "${workspaceFolder}/code/client/cli/Recipe.sml" ],
"cwd": "${workspaceFolder}/out/run",
"stopAtEntry": false,
"console": "internalConsole"
},
{
"name": "Debug Soup",
"type": "cppdbg",
Expand Down
2 changes: 1 addition & 1 deletion code/client/cli/source/Program.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace Soup::Client
System::IProcessManager::Register(std::make_shared<System::LinuxProcessManager>());
Monitor::IMonitorProcessManager::Register(std::make_shared<Monitor::Linux::LinuxMonitorProcessManager>());
#else
#error "Unknown Platform"
#error "Unknown Platform"
#endif
IO::IConsoleManager::Register(std::make_shared<IO::SystemConsoleManager>());

Expand Down
6 changes: 3 additions & 3 deletions code/client/cli/source/commands/BuildCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ namespace Soup::Client

// Platform specific defaults
#if defined(_WIN32)
arguments.HostPlatform = "Windows";
arguments.HostPlatform = "Windows";
#elif defined(__linux__)
arguments.HostPlatform = "Linux";
arguments.HostPlatform = "Linux";
#else
#error "Unknown Platform"
#error "Unknown Platform"
#endif

// Process well known parameters
Expand Down
6 changes: 5 additions & 1 deletion code/client/cli/source/commands/ViewCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,17 @@ namespace Soup::Client
#error "Unknown platform"
#endif

// Find the folder root
auto processFilename = System::IProcessManager::Current().GetCurrentProcessFileName();
auto processDirectory = processFilename.GetParent();

// Execute the requested target
Log::Info("CreateProcess");
Log::Diag(executable.ToString());
auto process = System::IProcessManager::Current().CreateProcess(
executable,
std::move(arguments),
workingDirectory,
processDirectory,
false);
process->Start();
process->WaitForExit();
Expand Down
2 changes: 1 addition & 1 deletion code/client/core/source/build/BuildLoadEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ namespace Soup::Core
Log::HighPriority("The installation may be corrupted");

// Nothing we can do, exit
throw HandledException(1123124);
throw HandledException(1723124);
}

// Built in packages do not load the lock
Expand Down
20 changes: 14 additions & 6 deletions code/client/tools/Public.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Include all standard library headers in the global module
#include <filesystem>
#include <format>
#include <memory>
#include <string>

#ifdef _WIN32
#include <combaseapi.h>
#define SOUP_TOOLS_API __declspec(dllexport)
#ifdef GetCurrentDirectory
#undef GetCurrentDirectory
#endif
#else
#define SOUP_TOOLS_API
#define CoTaskMemAlloc(p) malloc(p)
Expand Down Expand Up @@ -88,6 +92,7 @@ std::string LoadBuildGraphContent(const Path& workingDirectory)
{
// Setup the filter
auto defaultTypes =
static_cast<uint32_t>(TraceEventFlag::Information) |
static_cast<uint32_t>(TraceEventFlag::HighPriority) |
static_cast<uint32_t>(TraceEventFlag::Warning) |
static_cast<uint32_t>(TraceEventFlag::Error) |
Expand All @@ -109,14 +114,17 @@ std::string LoadBuildGraphContent(const Path& workingDirectory)

auto globalParameters = ValueTable();

// Find the built in folder root
auto rootDirectory = System::IFileSystem::Current().GetCurrentDirectory();
auto builtInPackageDirectory = rootDirectory + Path("./BuiltIn/");

// Load user config state
auto builtInPackageDirectory = Path("C:/Program Files/SoupBuild/Soup/Soup/BuiltIn/");
auto userDataPath = BuildEngine::GetSoupUserDataPath();

auto recipeCache = RecipeCache();

auto packageProvider = BuildEngine::LoadBuildGraph(
builtInPackageDirectory,
builtInPackageDirectory,
workingDirectory,
globalParameters,
userDataPath,
Expand All @@ -139,18 +147,18 @@ std::string LoadBuildGraphContent(const Path& workingDirectory)
auto value = jsonResult.dump();
return value;
}
catch (const HandledException&)
catch (const HandledException& ex)
{
json11::Json jsonResult = json11::Json::object({
{ "Message", "FAILED" },
{ "Message", std::format("HANDLED ERROR: {0}", ex.GetExitCode()) },
{ "IsSuccess", false },
});
return jsonResult.dump();
}
catch(const std::exception& e)
catch(const std::exception& ex)
{
json11::Json jsonResult = json11::Json::object({
{ "Message", e.what() },
{ "Message", ex.what() },
{ "IsSuccess", false },
});
return jsonResult.dump();
Expand Down
21 changes: 14 additions & 7 deletions code/generate-sharp/soup-view/SoupView.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@
<PublishTrimmed>false</PublishTrimmed>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<SoupConfigHash>OZlIVjblazFuKXg-raWUNoGEnG4</SoupConfigHash>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<SoupConfigHash>Oltq7cGwk0Rbgy1I-3mCMDDE5yM</SoupConfigHash>
</PropertyGroup>
<PropertyGroup Condition="'$(OS)'=='Windows_NT'">
<SoupToolsDll>SoupTools.dll</SoupToolsDll>
</PropertyGroup>
<PropertyGroup Condition="'$(OS)'=='Unix'">
<SoupToolsDll>SoupTools.so</SoupToolsDll>
</PropertyGroup>
<ItemGroup>
<None Remove="assets/Soup.ico" />
<AvaloniaResource Include="assets/Soup.ico" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Debug' And '$(OS)'=='Windows_NT'">
<None Include="../../../out/C++/Local/SoupTools/1.0.0/OZlIVjblazFuKXg-raWUNoGEnG4/bin/SoupTools.dll" Link="SoupTools.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Release' And '$(OS)'=='Windows_NT'">
<None Include="../../../out/C++/Local/SoupTools/1.0.0/Oltq7cGwk0Rbgy1I-3mCMDDE5yM/bin/SoupTools.dll" Link="SoupTools.dll">
<ItemGroup >
<None Include="../../../out/C++/Local/SoupTools/1.0.0/$(SoupConfigHash)/bin/$(SoupToolsDll)" Link="$(SoupToolsDll)">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion code/generate-sharp/soup-view/properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"profiles": {
"SoupView": {
"commandName": "Project",
"commandLineArgs": "C:\\Users\\mwasp\\Dev\\Repos\\Soup\\Source\\Client\\CLI\\Recipe.sml",
"commandLineArgs": "C:\\Users\\mwasp\\source\\repos\\soup\\code\\client\\cli\\Recipe.sml",
"workingDirectory": "C:\\Users\\mwasp\\source\\repos\\soup\\out\\run\\Soup",
"nativeDebugging": true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,21 @@ private List<GraphNodeViewModel> BuildGraphNodes(

private async Task<Path> GetTargetPathAsync(Path packageDirectory)
{
var processInfo = new ProcessStartInfo("C:\\Program Files\\SoupBuild\\Soup\\Soup\\Soup.exe", $"target {packageDirectory}")
string soupExe;
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
{
soupExe = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "Soup.exe");
}
else if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux))
{
soupExe = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "soup");
}
else
{
throw new NotSupportedException("Unknown OS Platform");
}

var processInfo = new ProcessStartInfo(soupExe, $"target {packageDirectory}")
{
RedirectStandardOutput = true,
CreateNoWindow = true,
Expand Down
16 changes: 15 additions & 1 deletion code/generate-sharp/soup-view/view-models/TaskGraphViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,22 @@ private List<GraphNodeViewModel> BuildGraphNodes(

private async Task<Path> GetTargetPathAsync(Path packageDirectory, string? owner)
{
string soupExe;
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
{
soupExe = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "Soup.exe");
}
else if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux))
{
soupExe = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "soup");
}
else
{
throw new NotSupportedException("Unknown OS Platform");
}

var optionalOwnerFlag = owner is null ? string.Empty : $" -owner {owner}";
var processInfo = new ProcessStartInfo("C:\\Program Files\\SoupBuild\\Soup\\Soup\\Soup.exe", $"target {packageDirectory}{optionalOwnerFlag}")
var processInfo = new ProcessStartInfo(soupExe, $"target {packageDirectory}{optionalOwnerFlag}")
{
RedirectStandardOutput = true,
CreateNoWindow = true,
Expand Down
18 changes: 9 additions & 9 deletions code/monitor/host/linux/LinuxSystemAccessMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ namespace Monitor::Linux

void OnOpen(std::string_view path, int32_t oflag, int32_t result) override final
{
bool isWriteOnly = (oflag & O_WRONLY) != 0;
bool isReadWrite = (oflag & O_RDWR) != 0;
bool isReadOnly = (oflag & O_RDONLY) != 0;
bool isWriteOnly = (oflag & O_ACCMODE) == O_WRONLY;
bool isReadWrite = (oflag & O_ACCMODE) == O_RDWR;
bool isReadOnly = (oflag & O_ACCMODE) == O_RDONLY;
bool wasBlocked = false;
bool exists = result != -1;

Expand All @@ -84,9 +84,9 @@ namespace Monitor::Linux

void OnOpenAt(int32_t dirfd, std::string_view pathname, int32_t flags, int32_t result) override final
{
bool isWriteOnly = (flags & O_WRONLY) != 0;
bool isReadWrite = (flags & O_RDWR) != 0;
bool isReadOnly = (flags & O_RDONLY) != 0;
bool isWriteOnly = (flags & O_ACCMODE) == O_WRONLY;
bool isReadWrite = (flags & O_ACCMODE) == O_RDWR;
bool isReadOnly = (flags & O_ACCMODE) == O_RDONLY;
bool wasBlocked = false;
bool exists = result != -1;

Expand All @@ -106,9 +106,9 @@ namespace Monitor::Linux

void OnOpenAt2(int32_t dirfd, std::string_view pathname, int32_t flags, int32_t result) override final
{
bool isWriteOnly = (flags & O_WRONLY) != 0;
bool isReadWrite = (flags & O_RDWR) != 0;
bool isReadOnly = (flags & O_RDONLY) != 0;
bool isWriteOnly = (flags & O_ACCMODE) == O_WRONLY;
bool isReadWrite = (flags & O_ACCMODE) == O_RDWR;
bool isReadOnly = (flags & O_ACCMODE) == O_RDONLY;
bool wasBlocked = false;
bool exists = result != -1;

Expand Down
2 changes: 1 addition & 1 deletion docs/cli/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ soup run

Run a release Recipe in a different directory and pass in a single parameter to the child executable.
```
soup run ./Code/MyProject/ -flavor release -args MyParameter
soup run ./Code/MyProject/ -flavor Release -args MyParameter
```
2 changes: 1 addition & 1 deletion docs/cli/target.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ soup target

Print the target directory for a release Recipe in a different directory with the release flavor.
```
soup target ./Code/MyProject/ -flavor release
soup target ./Code/MyProject/ -flavor Release
```
4 changes: 4 additions & 0 deletions scripts/linux/build
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ eval $SCRIPTS_DIR/build-swhere $FLAVOR
echo $SCRIPTS_DIR/build-packagemanager $FLAVOR
eval $SCRIPTS_DIR/build-packagemanager $FLAVOR

# Build Tools
echo $SCRIPTS_DIR/build-tools $FLAVOR
eval $SCRIPTS_DIR/build-tools $FLAVOR

# Build View
echo $SCRIPTS_DIR/build-view $FLAVOR
eval $SCRIPTS_DIR/build-view $FLAVOR
4 changes: 4 additions & 0 deletions scripts/linux/build-client
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ CODE_DIR=$ROOT_DIR/code
OUTPUT_DIR=$ROOT_DIR/out
CLIENT_CLI_DIR=$CODE_DIR/client/cli

# Restore the client
echo soup restore $CLIENT_CLI_DIR
eval soup restore $CLIENT_CLI_DIR

# Build the client
echo soup build $CLIENT_CLI_DIR -flavor $FLAVOR
eval soup build $CLIENT_CLI_DIR -flavor $FLAVOR
11 changes: 8 additions & 3 deletions scripts/linux/build-tools
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#!/bin/bash
echo "Build SoupView!"
echo "Build SoupTools!"

# Stop on first error
set -e

FLAVOR="$1"
SCRIPTS_DIR=$(dirname "$0")
CODE_DIR=$SCRIPTS_DIR/../../code
TOOLS_DIR=$CODE_DIR/client/tools

# Restore tools
echo soup restore $TOOLS_DIR
eval soup restore $TOOLS_DIR

# Build tools
echo soup build $TOOLS_DIR -flavor Release
eval soup build $TOOLS_DIR -flavor Release
echo soup build $TOOLS_DIR -flavor $FLAVOR
eval soup build $TOOLS_DIR -flavor $FLAVOR
6 changes: 5 additions & 1 deletion scripts/linux/build-view
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ set -e

FLAVOR="$1"
SCRIPTS_DIR=$(dirname "$0")
CODE_DIR=$SCRIPTS_DIR/../../code
ROOT_DIR=$SCRIPTS_DIR/../..
CODE_DIR=$ROOT_DIR/code
SWHERE_DIR=$CODE_DIR/generate-sharp/soup-view

# Cleanup old publish to work around bug in publish
rm -r -f $ROOT_DIR/out/msbuild/bin/SoupView/$FLAVOR/net9.0/linux-x64/publish/

# Build SWhere tool
echo dotnet publish $SWHERE_DIR -c $FLAVOR -r linux-x64 --self-contained
eval dotnet publish $SWHERE_DIR -c $FLAVOR -r linux-x64 --self-contained
5 changes: 5 additions & 0 deletions scripts/windows/build-client.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ SET OutputDir=%RootDir%\out
SET ClientCLIDir=%CodeDir%\client\cli
SET MonitorClientDir=%CodeDir%\monitor\client

REM - Restore the client
echo soup restore %ClientCLIDir%
call soup restore %ClientCLIDir%
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%

REM - Build each version of the monitor client dll
echo soup build %MonitorClientDir% -architecture x64 -flavor %Flavor%
call soup build %MonitorClientDir% -architecture x64 -flavor %Flavor%
Expand Down
5 changes: 5 additions & 0 deletions scripts/windows/build-tools.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ SET RootDir=%ScriptsDir%..\..
SET CodeDir=%RootDir%\code
SET ToolsDir=%CodeDir%\client\tools

REM - Restore Tools
echo soup restore %ToolsDir%
call soup restore %ToolsDir%
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%

REM - Build Tools
echo soup build %ToolsDir% -flavor %Flavor%
call soup build %ToolsDir% -flavor %Flavor%
Expand Down

0 comments on commit 2a169a9

Please sign in to comment.