Skip to content

Commit

Permalink
Small Cleanups (#261)
Browse files Browse the repository at this point in the history
* Start cleanup
* dont send list when disabled
* Fix up C# new value types
  • Loading branch information
mwasplund authored Sep 19, 2024
1 parent e5aa3cf commit 7051066
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Samples/Cpp/ConsoleApplication/PackageLock.sml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Closures: {
}
Build0: {
Wren: {
'mwasplund|Soup.Cpp': { Version: '0.12.0' }
'mwasplund|Soup.Cpp': { Version: '0.13.0' }
}
}
Tool0: {
Expand Down
5 changes: 1 addition & 4 deletions Samples/Cpp/ConsoleApplication/Recipe.sml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
Name: 'Samples.Cpp.ConsoleApplication'
Language: (C++@0)
Type: 'Executable'
Version: 1.0.0
Source: [
'Main.cpp'
]
Version: 1.0.0
2 changes: 1 addition & 1 deletion Scripts/Windows/build-view.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SET SWhereDir=%SourceDir%\GenerateSharp\SoupView
SET OutDir=%RootDir%\out

REM - Cleanup old publish to work around bug in publish
rmdir /S /Q %OutDir%\msbuild\bin\SoupView\Release\net8.0\win-x64\publish\
rmdir /S /Q %OutDir%\msbuild\bin\SoupView\%Flavor%\net8.0\win-x64\publish\

REM - Build SWhere tool
echo dotnet publish %SWhereDir% -c %Flavor% -f net8.0 -r win-x64 --self-contained
Expand Down
15 changes: 10 additions & 5 deletions Source/Client/Core/Source/Build/BuildEvaluateEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,14 @@ namespace Soup::Core
environment.emplace("TMP", temporaryDirectory.ToString());

// Allow access to the declared inputs/outputs
auto allowedReadAccess = _fileSystemState.GetFilePaths(operationInfo.ReadAccess);
auto allowedWriteAccess = _fileSystemState.GetFilePaths(operationInfo.WriteAccess);
bool enableAccessChecks = true;
auto allowedReadAccess = std::vector<Path>();
auto allowedWriteAccess = std::vector<Path>();
if (enableAccessChecks)
{
allowedReadAccess = _fileSystemState.GetFilePaths(operationInfo.ReadAccess);
allowedWriteAccess = _fileSystemState.GetFilePaths(operationInfo.WriteAccess);
}

// Allow access to the global overrides
std::copy(globalAllowedReadAccess.begin(), globalAllowedReadAccess.end(), std::back_inserter(allowedReadAccess));
Expand All @@ -400,7 +406,6 @@ namespace Soup::Core
for (auto& file : allowedWriteAccess)
Log::Diag(file.ToString());

bool enableAccessChecks = true;
std::shared_ptr<System::IProcess> process = nullptr;
if (_disableMonitor)
{
Expand All @@ -419,8 +424,8 @@ namespace Soup::Core
environment,
callback,
enableAccessChecks,
allowedReadAccess,
allowedWriteAccess);
std::move(allowedReadAccess),
std::move(allowedWriteAccess));
}

process->Start();
Expand Down
1 change: 0 additions & 1 deletion Source/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<Project>
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public MainWindowViewModel(string? packagePath)

if (packagePath is not null)
{
RecipeFile = new Path(packagePath);
RecipeFile = Path.Parse(packagePath);
}
}

Expand Down
28 changes: 24 additions & 4 deletions Source/GenerateSharp/SoupView/ViewModels/TaskDetailsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,18 @@ private void BuildValueTable(
type = ValueTableItemType.Table;
BuildValueTable(value.Value.AsTable(), children);
break;
case ValueType.Empty:
throw new NotImplementedException();
case ValueType.Version:
title = $"{value.Key}: {value.Value}";
type = ValueTableItemType.Value;
break;
case ValueType.PackageReference:
title = $"{value.Key}: {value.Value}";
type = ValueTableItemType.Value;
break;
case ValueType.LanguageReference:
title = $"{value.Key}: {value.Value}";
type = ValueTableItemType.Value;
break;
default:
throw new InvalidOperationException("Unknown Value type");
}
Expand Down Expand Up @@ -125,8 +135,18 @@ private void BuildValueList(
type = ValueTableItemType.Table;
BuildValueTable(value.AsTable(), children);
break;
case ValueType.Empty:
throw new NotImplementedException();
case ValueType.Version:
title = $"{value}";
type = ValueTableItemType.Value;
break;
case ValueType.PackageReference:
title = $"{value}";
type = ValueTableItemType.Value;
break;
case ValueType.LanguageReference:
title = $"{value}";
type = ValueTableItemType.Value;
break;
default:
throw new InvalidOperationException("Unknown Value type");
}
Expand Down
68 changes: 61 additions & 7 deletions Source/GenerateSharp/Utilities/ValueTable/Value.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright (c) Soup. All rights reserved.
// </copyright>

using Opal;
using System;
using System.Globalization;

Expand All @@ -19,12 +20,6 @@ private Value(ValueType type, object? rawValue)
RawValue = rawValue;
}

public Value()
{
Type = ValueType.Empty;
RawValue = null;
}

public Value(bool value)
{
Type = ValueType.Boolean;
Expand Down Expand Up @@ -61,6 +56,24 @@ public Value(ValueList value)
RawValue = value;
}

public Value(SemanticVersion value)
{
Type = ValueType.Version;
RawValue = value;
}

public Value(LanguageReference value)
{
Type = ValueType.LanguageReference;
RawValue = value;
}

public Value(PackageReference value)
{
Type = ValueType.PackageReference;
RawValue = value;
}

public Value Clone()
{
return new Value(Type, RawValue);
Expand Down Expand Up @@ -144,6 +157,45 @@ public bool AsBoolean()
throw new InvalidOperationException("Attempt to get value as incorrect type: Boolean");
}

public bool IsVersion()
{
return Type == ValueType.Version;
}

public SemanticVersion AsVersion()
{
if (IsVersion() && RawValue is SemanticVersion result)
return result;
else
throw new InvalidOperationException("Attempt to get value as incorrect type: Version");
}

public bool IsLanguageReference()
{
return Type == ValueType.LanguageReference;
}

public LanguageReference AsLanguageReference()
{
if (IsLanguageReference() && RawValue is LanguageReference result)
return result;
else
throw new InvalidOperationException("Attempt to get value as incorrect type: LanguageReference");
}

public bool IsPackageReference()
{
return Type == ValueType.PackageReference;
}

public PackageReference AsPackageReference()
{
if (IsPackageReference() && RawValue is PackageReference result)
return result;
else
throw new InvalidOperationException("Attempt to get value as incorrect type: PackageReference");
}

public override string ToString()
{
return Type switch
Expand All @@ -154,7 +206,9 @@ public override string ToString()
ValueType.Integer => AsInteger().ToString(CultureInfo.InvariantCulture),
ValueType.Float => AsFloat().ToString(CultureInfo.InvariantCulture),
ValueType.Boolean => AsBoolean().ToString(),
ValueType.Empty => string.Empty,
ValueType.Version => AsVersion().ToString(),
ValueType.PackageReference => AsPackageReference().ToString(),
ValueType.LanguageReference => AsLanguageReference().ToString(),
_ => "UNKNOWN",
};
}
Expand Down
23 changes: 22 additions & 1 deletion Source/GenerateSharp/Utilities/ValueTable/ValueTableReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright (c) Soup. All rights reserved.
// </copyright>

using Opal;
using System;

namespace Soup.Build.Utilities;
Expand Down Expand Up @@ -66,7 +67,9 @@ private static Value ReadValue(System.IO.BinaryReader reader)
ValueType.Integer => new Value(reader.ReadInt64()),
ValueType.Float => new Value(reader.ReadDouble()),
ValueType.Boolean => new Value(ReadBoolean(reader)),
ValueType.Empty => throw new NotImplementedException(),
ValueType.Version => new Value(ReadVersion(reader)),
ValueType.PackageReference => new Value(ReadPackageReference(reader)),
ValueType.LanguageReference => new Value(ReadLanguageReference(reader)),
_ => throw new InvalidOperationException("Unknown ValueType"),
};
}
Expand Down Expand Up @@ -121,4 +124,22 @@ private static string ReadString(System.IO.BinaryReader reader)

return new string(result);
}

private static SemanticVersion ReadVersion(System.IO.BinaryReader reader)
{
var result = ReadString(reader);
return SemanticVersion.Parse(result);
}

private static LanguageReference ReadLanguageReference(System.IO.BinaryReader reader)
{
var result = ReadString(reader);
return LanguageReference.Parse(result);
}

private static PackageReference ReadPackageReference(System.IO.BinaryReader reader)
{
var result = ReadString(reader);
return PackageReference.Parse(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ private static void WriteValue(BinaryWriter writer, Value value)
case ValueType.Boolean:
WriteValue(writer, value.AsBoolean());
break;
case ValueType.Empty:
case ValueType.Version:
WriteValue(writer, value.AsVersion().ToString());
break;
case ValueType.LanguageReference:
WriteValue(writer, value.AsLanguageReference().ToString());
break;
case ValueType.PackageReference:
WriteValue(writer, value.AsPackageReference().ToString());
break;
default:
throw new InvalidOperationException("Unknown ValueType");
Expand Down
14 changes: 12 additions & 2 deletions Source/GenerateSharp/Utilities/ValueTable/ValueType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ public enum ValueType
Boolean = 6,

/// <summary>
/// Empty
/// Version
/// </summary>
Empty = 7,
Version = 7,

/// <summary>
/// PackageReference
/// </summary>
PackageReference = 8,

/// <summary>
/// LanguageReference
/// </summary>
LanguageReference = 9,
}
4 changes: 2 additions & 2 deletions Source/Monitor/Client/FileSystemAccessSandbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ namespace Monitor
return true;

auto normalizedFileName = NormalizePath(fileName);
for (const auto& allowedDiractory : m_allowedReadDirectories)
for (const auto& allowedDirectory : m_allowedReadDirectories)
{
if (IsUnderDirectory(normalizedFileName, allowedDiractory))
if (IsUnderDirectory(normalizedFileName, allowedDirectory))
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions Source/Monitor/Host/IMonitorProcessManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ namespace Monitor
const std::map<std::string, std::string>& environmentVariables,
std::shared_ptr<IMonitorCallback> callback,
bool enableAccessChecks,
const std::vector<Path>& allowedReadAccess,
const std::vector<Path>& allowedWriteAccess) = 0;
std::vector<Path> allowedReadAccess,
std::vector<Path> allowedWriteAccess) = 0;

private:
static std::shared_ptr<IMonitorProcessManager> _current;
Expand Down
4 changes: 2 additions & 2 deletions Source/Monitor/Host/Linux/LinuxMonitorProcessManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace Monitor::Linux
const std::map<std::string, std::string>& environmentVariables,
std::shared_ptr<IMonitorCallback> callback,
bool enableAccessChecks,
const std::vector<Path>& allowedReadAccess,
const std::vector<Path>& allowedWriteAccess) override final
std::vector<Path> allowedReadAccess,
std::vector<Path> allowedWriteAccess) override final
{
return std::make_shared<LinuxMonitorProcess>(
executable,
Expand Down
4 changes: 2 additions & 2 deletions Source/Monitor/Host/Mock/MockMonitorProcessManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ namespace Monitor
const std::map<std::string, std::string>& environmentVariables,
std::shared_ptr<IMonitorCallback> callback,
bool enableAccessChecks,
const std::vector<Path>& allowedReadAccess,
const std::vector<Path>& allowedWriteAccess) override final
std::vector<Path> allowedReadAccess,
std::vector<Path> allowedWriteAccess) override final
{
std::stringstream message;
auto id = m_uniqueId++;
Expand Down
4 changes: 2 additions & 2 deletions Source/Monitor/Host/Windows/WindowsMonitorProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ namespace Monitor::Windows
const std::map<std::string, std::string>& environmentVariables,
std::shared_ptr<IMonitorCallback> callback,
bool enableAccessChecks,
const std::vector<Path>& allowedReadAccess,
const std::vector<Path>& allowedWriteAccess) :
std::vector<Path> allowedReadAccess,
std::vector<Path> allowedWriteAccess) :
m_executable(executable),
m_arguments(std::move(arguments)),
m_workingDirectory(workingDirectory),
Expand Down
8 changes: 4 additions & 4 deletions Source/Monitor/Host/Windows/WindowsMonitorProcessManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ namespace Monitor::Windows
const std::map<std::string, std::string>& environmentVariables,
std::shared_ptr<IMonitorCallback> callback,
bool enableAccessChecks,
const std::vector<Path>& allowedReadAccess,
const std::vector<Path>& allowedWriteAccess) override final
std::vector<Path> allowedReadAccess,
std::vector<Path> allowedWriteAccess) override final
{
return std::make_shared<WindowsMonitorProcess>(
executable,
Expand All @@ -41,8 +41,8 @@ namespace Monitor::Windows
environmentVariables,
std::move(callback),
enableAccessChecks,
allowedReadAccess,
allowedWriteAccess);
std::move(allowedReadAccess),
std::move(allowedWriteAccess));
}
};
}

0 comments on commit 7051066

Please sign in to comment.