Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fork process proxy for using workloads tools #283

Merged
merged 22 commits into from
Aug 15, 2024
Merged

Conversation

0xF6
Copy link
Member

@0xF6 0xF6 commented Aug 15, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a CompileSettings class for managing project compilation configurations with various customizable options.
    • Added a BuildCommand class to facilitate executing build commands in the CLI.
    • Introduced a WorkloadDb class to manage tools and SDKs asynchronously, improving project capabilities.
    • Created an ObjectDirectory property in CompilerPipeline for better output organization.
  • Bug Fixes

    • Enhanced error handling in the ExecuteAsync method of the BuildCommand class to provide better user feedback on tool availability.
  • Documentation

    • Updated project references and added global using directives for better code organization and readability.
  • Chores

    • Removed unused using directives across multiple files to streamline the codebase and improve maintainability.
    • Updated project dependencies to include new libraries for enhanced functionality and performance.

@0xF6 0xF6 added area-compiler Area of compiler staff feature labels Aug 15, 2024
@0xF6 0xF6 requested a review from code-maid August 15, 2024 08:10
@0xF6 0xF6 self-assigned this Aug 15, 2024
Copy link
Contributor

coderabbitai bot commented Aug 15, 2024

Walkthrough

The recent changes encompass a comprehensive restructuring of the project, enhancing modularity and usability. Key improvements include the introduction of new functionalities for JSON handling, streamlined logging, and refined project dependencies. This update emphasizes better organization in command execution, configuration management, and file handling, ultimately leading to a cleaner and more efficient codebase.

Changes

Files Grouped by Similar Changes Change Summary
.nuke/Build.cs, .nuke/build.csproj Added a new namespace import and project reference to vein.compiler.shared, enhancing build dependencies and modularity.
lib/projectsystem/Workload.converters.cs, lib/projectsystem/Workload.cs Refactored JSON converters for better error handling and improved clarity in Workload and WorkloadPackage records by defining properties explicitly.
lib/vein.cli.core/RawConsole.cs, lib/vein.cli.core/di/SpectreConsoleHostBuilderExtensions.cs Introduced new console handling methods and extension methods for integrating with Spectre.Console, enhancing command-line interface capabilities.
lib/vein.compiler.shared/CompileSettings.cs, lib/vein.compiler.shared/vein.compiler.shared.csproj Added CompileSettings class for command-line argument management and established a new project for shared compiler resources.
runtime/common/extensions/FileEntityEx.cs, runtime/common/reflection/IBaker.cs Enhanced file handling capabilities with new async methods and improved debugging features in the IBaker interface.
tools/compiler/Program.cs, tools/compiler/CompileCommand.cs Transitioned to a host-based application structure, improving dependency management and simplifying command execution logic.
tools/rune-cli/WorkloadDb.cs, tools/rune-cli/cmd/InstallWorkloadCommand.cs Introduced WorkloadInstallingContext to streamline parameter management for workload installations, promoting better encapsulation.
tools/rune-cli/Log.cs, tools/rune-cli/Program.cs Simplified logging functionality by removing context-specific logging methods, focusing on more generic logging capabilities.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI as Command-Line Interface
    participant Host as .NET Host
    participant Command as Build Command
    participant Compiler as Compiler Proxy

    User->>CLI: Execute build command
    CLI->>Host: Create default host
    Host->>Command: Initialize commands
    Command->>Compiler: Execute async compilation
    Compiler-->>Command: Return result
    Command-->>CLI: Send output
    CLI-->>User: Display results
Loading

🐰 In the meadow, changes bloom,
🐇 New paths to explore, dispelling gloom.
With settings and commands aligned,
A joyful hop for the coder's mind!
Let's compile and build with cheer,
For every line brings the future near! 🌼✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 14

Outside diff range, codebase verification and nitpick comments (14)
tools/rune-cli/cmd/BuildCommand.cs (1)

7-8: Consider adding documentation for the class.

Adding XML documentation comments for the BuildCommand class would improve code readability and maintainability by providing context and usage information.

/// <summary>
/// Represents a command to build the project using the specified compiler tool.
/// </summary>
[ExcludeFromCodeCoverage]
public class BuildCommand(WorkloadDb db) : AsyncCommandWithProject<CompileSettings>
tools/rune-cli/cmd/PackageCommand.cs (1)

9-9: Consider adding documentation for the class.

Adding XML documentation comments for the PackageCommand class would enhance code readability and provide context for its purpose and usage.

/// <summary>
/// Represents a command to package the project using the specified compiler tool.
/// </summary>
[ExcludeFromCodeCoverage]
public class PackageCommand(WorkloadDb db) : AsyncCommandWithProject<CompileSettings>
tools/rune-cli/rune-cli.csproj (1)

22-22: Action Required: Address Unresolved References to Spectre.Console

The Spectre.Console library is still referenced in multiple files across the codebase. Ensure these references are updated or removed to prevent build issues due to its removal from the project file.

  • Files with Spectre.Console references:
    • tools/rune-cli/Program.cs
    • tools/rune-cli/Log.cs
    • tools/rune-cli/cmd/UpdateWorkloadCommand.cs
    • ... (and others as listed in the script output)

Please verify and update these references accordingly.

Analysis chain

LGTM! Verify dependency impacts.

The changes in project references suggest a shift in architecture. Ensure that the removal of spectre.console and addition of vein.compiler.shared do not introduce issues.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of dependency changes in the codebase.

# Test: Search for usages of `spectre.console` and `vein.compiler.shared`. Expect: No unresolved references.
rg --type cs 'Spectre.Console' --files-with-matches
rg --type cs 'vein.compiler.shared' --files-with-matches

Length of output: 1516

tools/compiler/pipes/WriteOutputPipe.cs (1)

32-44: Add exception handling in Parallel.ForEachAsync block.

The Parallel.ForEachAsync block in WriteOutputPipe.cs lacks exception handling, which could lead to unhandled exceptions during execution. Consider adding a try-catch block to manage potential exceptions and ensure robust error handling.

  • File: tools/compiler/pipes/WriteOutputPipe.cs
  • Lines: 32-44
Analysis chain

Efficient parallel processing with Parallel.ForEachAsync.

The use of Parallel.ForEachAsync enhances performance by allowing concurrent execution of baking operations. Ensure that exceptions are properly handled within the asynchronous tasks.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify exception handling within `Parallel.ForEachAsync` in `WriteOutputPipe.cs`.

# Test: Search for exception handling within the `Parallel.ForEachAsync` block. Expect: Proper handling or logging of exceptions.
rg --type cs 'Parallel.ForEachAsync' -A 10

Length of output: 2896

tools/rune-cli/WorkloadDb.cs (2)

7-7: Clarify exception message for NotFoundToolException.

The exception message could be more informative. Consider providing additional context or suggestions for resolution.

- public class NotFoundToolException(string tool, PackageKey key) : Exception($"Tool '{tool}' not found in '{key.key}', maybe not installed package?");
+ public class NotFoundToolException(string tool, PackageKey key) : Exception($"Tool '{tool}' not found in package '{key.key}'. Ensure the package is installed and the tool name is correct.");

11-24: Add Exception Handling to RegistryTool Method

The RegistryTool method lacks exception handling for its async operations and file manipulations. Consider adding try-catch blocks to manage potential exceptions and ensure proper logging and error handling.

  • File: tools/rune-cli/WorkloadDb.cs
  • Lines: 11-24
Analysis chain

Ensure proper exception handling in RegistryTool.

The method RegistryTool performs async operations and file manipulations. Ensure that exceptions are caught and logged appropriately, especially for file operations.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify exception handling in RegistryTool method.

# Test: Search for try-catch blocks in the RegistryTool method. Expect: Proper exception handling.
ast-grep --lang csharp --pattern $'public async Task RegistryTool($_, $_, $_) {
  $$$
  try {
    $$$
  } catch (Exception e) {
    $$$
  }
  $$$
}'

Length of output: 494


Script:

#!/bin/bash
# Description: Extract the implementation of the RegistryTool method to verify exception handling.

# Locate the file containing the RegistryTool method and extract its implementation.
ast-grep --lang csharp --pattern 'public async Task RegistryTool($_, $_, $_) { $$$ }'

Length of output: 87


Script:

#!/bin/bash
# Description: Search for the RegistryTool method by name and extract surrounding lines to check for exception handling.

# Use rg to search for the RegistryTool method and extract surrounding lines for context.
rg 'public async Task RegistryTool' -A 20

Length of output: 1488

tools/rune-cli/cmd/RunCommand.cs (3)

22-23: Consider adding a constructor summary.

Adding a summary comment for the constructor can improve code readability and maintainability.

/// <summary>
/// Initializes a new instance of the <see cref="RunCommand"/> class.
/// </summary>

51-74: Improve user prompt handling.

Consider adding more descriptive messages or logging for user decisions to improve user experience and debugging.

Log.Info($"User selected '{ask}' when prompted to build the project.");

76-82: Ensure tool availability check is robust.

Consider providing more guidance to the user if the tool is not found, such as checking network connectivity or repository settings.

Log.Error($"'{PackageKey.VeinRuntimePackage}' package not found. Please ensure network connectivity and repository settings are correct.");
lib/vein.cli.core/di/SpectreConsoleHostBuilderExtensions.cs (1)

88-113: Ensure robust error handling in command execution.

Consider adding more detailed error logging or retry mechanisms if command execution fails.

logger.LogError(ex, "Command execution failed. Consider checking command syntax or dependencies.");
tools/rune-cli/Program.cs (1)

129-135: Consider enhancing error logging for better context.

While writing exceptions to a file in release mode is useful, consider adding more context to the logs, such as timestamps or additional diagnostic information, to aid in troubleshooting.

runtime/ishtar.base/emit/VeinModuleBuilder.cs (1)

285-285: Add placeholder method BakeDiagnosticDebugString.

The method is a placeholder and throws NotImplementedException. Ensure there are plans to implement this functionality.

Consider adding a comment to explain the intended purpose of this method or tracking its implementation in the future.

tools/rune-cli/cmd/InstallWorkloadCommand.cs (2)

Line range hint 247-265:
Enhance error handling in InstallSdk.

The method handles different alias schemes. Consider logging more detailed error messages for unsupported schemes to aid debugging.

-    throw new PlatformNotSupportedException($"Workload installer not support http scheme. please use https");
+    throw new PlatformNotSupportedException($"Workload installer does not support http scheme for alias '{alias}'. Please use https.");

41-48: Update InstallWorkloadCommand Usage in UpdateWorkloadCommand.cs.

The InstallWorkloadCommand is still being instantiated with the old constructor signature in UpdateWorkloadCommand.cs. Please update it to match the new constructor signature using WorkloadInstallingContext.

  • tools/rune-cli/cmd/UpdateWorkloadCommand.cs: Update the instantiation of InstallWorkloadCommand to the new constructor signature.
Analysis chain

Review changes to InstallWorkloadCommand.

The constructor now uses WorkloadInstallingContext, which simplifies parameter management and enhances maintainability. Ensure that all usages of InstallWorkloadCommand are updated to match the new constructor signature.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all usages of `InstallWorkloadCommand` are updated to match the new constructor signature.

# Test: Search for the constructor usage. Expect: Only occurrences of the new signature.
rg --type cs 'new InstallWorkloadCommand\('

Length of output: 192


Script:

#!/bin/bash
# Description: Find all occurrences of `InstallWorkloadCommand` to verify if they match the new constructor signature.
rg --type cs 'InstallWorkloadCommand'

Length of output: 923

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 543dbda and bb705ed.

Files selected for processing (65)
  • .nuke/Build.cs (1 hunks)
  • .nuke/build.csproj (1 hunks)
  • lib/projectsystem/Workload.converters.cs (7 hunks)
  • lib/projectsystem/Workload.cs (2 hunks)
  • lib/spectre.console (1 hunks)
  • lib/vein.cli.core/RawConsole.cs (1 hunks)
  • lib/vein.cli.core/ShardStorage.cs (3 hunks)
  • lib/vein.cli.core/di/SpectreConsoleHostBuilderExtensions.cs (1 hunks)
  • lib/vein.cli.core/vein.cli.core.csproj (1 hunks)
  • lib/vein.compiler.shared/CompileSettings.cs (1 hunks)
  • lib/vein.compiler.shared/vein.compiler.shared.csproj (1 hunks)
  • runtime/common/extensions/FileEntityEx.cs (2 hunks)
  • runtime/common/reflection/IBaker.cs (1 hunks)
  • runtime/ishtar.base/emit/ClassBuilder.cs (1 hunks)
  • runtime/ishtar.base/emit/ILGenerator.cs (3 hunks)
  • runtime/ishtar.base/emit/MethodBuilder.cs (1 hunks)
  • runtime/ishtar.base/emit/VeinModuleBuilder.cs (1 hunks)
  • runtime/ishtar.base/fs/IshtarAssembly.cs (1 hunks)
  • tools/compiler/CompileCommand.cs (1 hunks)
  • tools/compiler/GlobalUsings.cs (1 hunks)
  • tools/compiler/IAssemblyResolver.cs (1 hunks)
  • tools/compiler/Log.cs (1 hunks)
  • tools/compiler/Program.cs (2 hunks)
  • tools/compiler/compilation/Analyzer.cs (1 hunks)
  • tools/compiler/compilation/Cache.cs (1 hunks)
  • tools/compiler/compilation/Collect.cs (1 hunks)
  • tools/compiler/compilation/CompilationLog.cs (1 hunks)
  • tools/compiler/compilation/CompilationTarget.cs (1 hunks)
  • tools/compiler/compilation/CompilationTask.cs (1 hunks)
  • tools/compiler/compilation/parts/args.cs (1 hunks)
  • tools/compiler/compilation/parts/aspects.cs (1 hunks)
  • tools/compiler/compilation/parts/bodies.cs (1 hunks)
  • tools/compiler/compilation/parts/classes.cs (1 hunks)
  • tools/compiler/compilation/parts/ctors.cs (1 hunks)
  • tools/compiler/compilation/parts/fields.cs (1 hunks)
  • tools/compiler/compilation/parts/inheritance.cs (1 hunks)
  • tools/compiler/compilation/parts/methods.cs (1 hunks)
  • tools/compiler/compilation/parts/props.cs (1 hunks)
  • tools/compiler/compilation/parts/shitcode_plug.cs (1 hunks)
  • tools/compiler/compilation/parts/types.cs (1 hunks)
  • tools/compiler/pipes/CompilerPipeline.cs (1 hunks)
  • tools/compiler/pipes/CopyDependencies.cs (1 hunks)
  • tools/compiler/pipes/GeneratePackage.cs (1 hunks)
  • tools/compiler/pipes/PipelineRunner.cs (1 hunks)
  • tools/compiler/pipes/SingleFileOutputPipe.cs (1 hunks)
  • tools/compiler/pipes/WriteOutputPipe.cs (2 hunks)
  • tools/compiler/veinc.csproj (1 hunks)
  • tools/rune-cli/Log.cs (1 hunks)
  • tools/rune-cli/Program.cs (3 hunks)
  • tools/rune-cli/Properties/launchSettings.json (1 hunks)
  • tools/rune-cli/WorkloadDb.cs (1 hunks)
  • tools/rune-cli/cmd/AddCommand.cs (1 hunks)
  • tools/rune-cli/cmd/BuildCommand.cs (1 hunks)
  • tools/rune-cli/cmd/InstallWorkloadCommand.cs (11 hunks)
  • tools/rune-cli/cmd/ListInstalledWorkloadCommand.cs (1 hunks)
  • tools/rune-cli/cmd/PackageCommand.cs (1 hunks)
  • tools/rune-cli/cmd/RunCommand.cs (1 hunks)
  • tools/rune-cli/cmd/UninstallWorkloadCommand.cs (1 hunks)
  • tools/rune-cli/cmd/UpdateWorkloadCommand.cs (2 hunks)
  • tools/rune-cli/rune-cli.csproj (1 hunks)
  • tools/rune-cli/services/AppMutex.cs (1 hunks)
  • tools/rune-cli/services/VeinCompilerProxy.cs (1 hunks)
  • tools/rune-cli/services/VeinIshtarProxy.cs (1 hunks)
  • vein_lang.sln (3 hunks)
  • vein_lang.sln.DotSettings (3 hunks)
Files skipped from review due to trivial changes (27)
  • .nuke/Build.cs
  • lib/spectre.console
  • lib/vein.compiler.shared/vein.compiler.shared.csproj
  • tools/compiler/GlobalUsings.cs
  • tools/compiler/IAssemblyResolver.cs
  • tools/compiler/Log.cs
  • tools/compiler/compilation/Analyzer.cs
  • tools/compiler/compilation/Cache.cs
  • tools/compiler/compilation/Collect.cs
  • tools/compiler/compilation/CompilationLog.cs
  • tools/compiler/compilation/CompilationTarget.cs
  • tools/compiler/compilation/parts/args.cs
  • tools/compiler/compilation/parts/aspects.cs
  • tools/compiler/compilation/parts/bodies.cs
  • tools/compiler/compilation/parts/classes.cs
  • tools/compiler/compilation/parts/ctors.cs
  • tools/compiler/compilation/parts/fields.cs
  • tools/compiler/compilation/parts/inheritance.cs
  • tools/compiler/compilation/parts/methods.cs
  • tools/compiler/compilation/parts/props.cs
  • tools/compiler/compilation/parts/shitcode_plug.cs
  • tools/compiler/compilation/parts/types.cs
  • tools/compiler/pipes/CopyDependencies.cs
  • tools/compiler/pipes/GeneratePackage.cs
  • tools/compiler/pipes/PipelineRunner.cs
  • tools/compiler/pipes/SingleFileOutputPipe.cs
  • vein_lang.sln.DotSettings
Additional comments not posted (67)
runtime/common/reflection/IBaker.cs (1)

7-7: Addition of BakeDiagnosticDebugString is appropriate.

The new method BakeDiagnosticDebugString() enhances the debugging capabilities of the IBaker interface without affecting existing functionality. This is a beneficial addition for diagnostic purposes.

tools/rune-cli/Properties/launchSettings.json (1)

9-9: Verify the impact of changing command line arguments.

The command line arguments have been altered from workload installation to project building (build proj -O). Ensure this change aligns with the intended functionality and does not disrupt existing processes.

tools/rune-cli/Log.cs (1)

9-13: Simplification of the Log class is noted.

The Log class has been significantly simplified, focusing on basic logging methods. Ensure that this reduction in complexity still meets the project's logging requirements.

tools/rune-cli/cmd/BuildCommand.cs (1)

10-20: Ensure proper error handling and logging.

The ExecuteAsync method handles the case where the tool is not found by logging an error and returning -1. Ensure that this logging is consistent with the rest of the application and consider adding more context if needed.

Verification successful

Logging is consistent across the application. The Log.Error usage in BuildCommand.cs follows a similar pattern to other commands, providing both the error and a suggested action. No changes are needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify logging consistency across the application.

# Test: Search for Log.Error usage to ensure consistency in error messages.
rg --type csharp 'Log\.Error'

Length of output: 4108

tools/rune-cli/cmd/PackageCommand.cs (1)

11-20: Ensure proper error handling and logging.

The ExecuteAsync method handles the case where the tool is not found by logging an error and returning -1. Verify that this approach is consistent with other parts of the application and consider adding additional context to the log message if necessary.

Verification successful

Logging Consistency Verified

The error handling and logging in the ExecuteAsync method of PackageCommand.cs is consistent with other parts of the application. The use of Log.Error across the codebase follows a similar pattern of providing specific details and suggestions, ensuring uniformity in error reporting. No changes are necessary.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify logging consistency across the application.

# Test: Search for Log.Error usage to ensure consistency in error messages.
rg --type csharp 'Log\.Error'

Length of output: 4108

.nuke/build.csproj (1)

26-26: Verify the necessity of the new project reference.

The addition of the project reference to veinc.csproj should be verified to ensure it is necessary and aligns with the project's goals. Confirm that the components from veinc are required for the build process.

tools/compiler/veinc.csproj (1)

14-14: New project reference added.

The addition of vein.compiler.shared.csproj as a project reference enhances modularity and code reuse by incorporating shared functionality. This change aligns with best practices for managing dependencies in a .NET project.

tools/compiler/pipes/CompilerPipeline.cs (1)

12-13: Addition of ObjectDirectory property.

The new ObjectDirectory property enhances the organization of the build process by providing a separate directory for object files. This can help in managing build outputs more effectively.

lib/vein.cli.core/RawConsole.cs (2)

21-28: Introduction of CreateForkConsole method.

The CreateForkConsole method enhances console functionality by supporting ANSI and true color output for forked processes. This is beneficial for applications that require advanced console output features.


31-35: Introduction of ForkConsole class.

The ForkConsole class provides a specialized console output for forked processes, with terminal characteristics based on environment variables. This allows for better control over console dimensions and behavior in forked environments.

tools/rune-cli/services/VeinIshtarProxy.cs (2)

5-19: Validate process initialization parameters.

Ensure that compilerPath, args, and baseFolder are valid and exist before initializing the process. Consider adding validation checks or throwing exceptions if parameters are invalid.

public VeinIshtarProxy(FileInfo compilerPath, IEnumerable<string> args, DirectoryInfo baseFolder)
{
    if (!compilerPath.Exists)
        throw new FileNotFoundException("Compiler path does not exist.", compilerPath.FullName);
    if (!baseFolder.Exists)
        throw new DirectoryNotFoundException("Base folder does not exist.");
    // Initialize process
}

38-38: LGTM! Ensure proper disposal of resources.

The Dispose method correctly disposes of the _process object. Ensure that Dispose is called when the VeinIshtarProxy instance is no longer needed.

lib/vein.cli.core/vein.cli.core.csproj (1)

16-19: Verify compatibility of new package references.

The added package references enhance interprocess communication, hosting, NuGet protocol interactions, and configuration management. Ensure these packages are compatible with the project's target framework (net8.0) and do not introduce conflicts with existing dependencies.

lib/vein.compiler.shared/CompileSettings.cs (1)

1-44: LGTM! The CompileSettings class is well-structured.

The class is correctly implementing command-line options using attributes, and the descriptions are clear. This aligns with best practices for defining command settings in CLI applications.

tools/rune-cli/cmd/UpdateWorkloadCommand.cs (1)

Line range hint 24-42:
LGTM! The use of dependency injection improves modularity.

The constructor now requires dependencies to be injected, which enhances testability and reduces reliance on static state. The ExecuteAsync method is well-implemented with the new design.

tools/rune-cli/cmd/ListInstalledWorkloadCommand.cs (1)

Line range hint 8-50:
LGTM! Dependency injection enhances flexibility.

The constructor now accepts a ShardStorage instance, which promotes better testability and adherence to object-oriented design principles. The ExecuteAsync method is well-implemented with the new design.

tools/compiler/Program.cs (3)

Line range hint 28-36:
LGTM!

The JSON settings are well-configured for consistent serialization behavior.


38-54: LGTM! Verify logging configurations.

The transition to Host.CreateDefaultBuilder enhances lifecycle management and logging. Ensure that logging configurations meet the application's requirements.


17-18: LGTM! Verify environment variable usage.

The use of RawConsole.CreateForkConsole enhances console management. Ensure that environment variables are correctly set and used.

Verification successful

Environment Variable Usage Verified

The usage of environment variables across the codebase is consistent and aligns with the intended functionality for console management. The specific use of FORK_CONSOLE in tools/compiler/Program.cs is correctly implemented.

  • Environment variables like NO_CONSOLE, VEINC_NOVID, NO_COLOR, FORK_CONSOLE_W, and FORK_CONSOLE_H are used consistently to manage console behavior.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify environment variable usage in the codebase.

# Test: Search for environment variable checks. Expect: Consistent handling of environment variables.
rg --type cs 'Environment\.GetEnvironmentVariable\('

Length of output: 874

tools/rune-cli/services/VeinCompilerProxy.cs (3)

6-26: LGTM!

The process initialization is well-configured, ensuring the compiler runs with the correct settings and environment variables.


28-46: LGTM!

The asynchronous execution pattern is efficient and correctly handles process output. The use of ValueTask is appropriate.


48-49: LGTM!

The implementation of IDisposable ensures proper resource cleanup.

tools/compiler/pipes/WriteOutputPipe.cs (4)

16-20: Streamlined file handling is efficient.

The changes to file handling logic improve efficiency by consolidating file deletions and initializing necessary directories.


31-31: Correct use of File.WriteAllBytes.

The operation correctly writes byte data to the specified file.


45-45: Appropriate use of JSON serialization.

The code correctly serializes a dictionary to a JSON file using JsonConvert.SerializeObject.


46-46: Correct writing of debug data.

The operation correctly writes debug data to the specified file.

tools/rune-cli/cmd/UninstallWorkloadCommand.cs (3)

15-15: Enhanced immutability of PackageName.

Changing PackageName to an immutable property improves the robustness of the settings object.


19-19: Improved encapsulation of WorkloadDirectory.

Changing the field to private restricts access and enhances encapsulation.


20-20: Improved encapsulation of Symlink.

Changing the field to private enhances encapsulation and aligns with best practices.

tools/compiler/CompileCommand.cs (1)

1-1: Verify handling of settings in CompileCommand.

The removal of CompileSettings suggests a refactor in settings management. Ensure that the CompileCommand can still operate correctly with the new approach.

tools/rune-cli/WorkloadDb.cs (1)

36-48: Review logic for TakeTool.

The method TakeTool returns null if the tool is not found and throwIfNotFound is false. Ensure that all calling code handles null appropriately.

runtime/common/extensions/FileEntityEx.cs (1)

52-55: Ensure cancellation is handled in async methods.

The async methods WriteAllTextAsync and WriteAllBytesAsync accept a CancellationToken. Ensure that the cancellation is respected and handled appropriately.

Verification successful

Cancellation Handling is Delegated to .NET Methods

The WriteAllTextAsync and WriteAllBytesAsync methods in FileEntityEx.cs delegate their work to System.IO.File.WriteAllTextAsync and System.IO.File.WriteAllBytesAsync, which handle the cancellation token internally. No additional cancellation handling is necessary in these extension methods.

  • runtime/common/extensions/FileEntityEx.cs: Lines 52-55
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify cancellation handling in async methods.

# Test: Search for cancellation token usage in async methods. Expect: Proper handling of cancellation.
ast-grep --lang csharp --pattern $'public static Task $_(this FileInfo info, $_, CancellationToken ct = default) {
  $$$
  ct.ThrowIfCancellationRequested();
  $$$
}'

Length of output: 167


Script:

#!/bin/bash
# Check for usage of System.IO.File.WriteAllTextAsync and System.IO.File.WriteAllBytesAsync in the codebase
rg "System\.IO\.File\.WriteAllTextAsync|System\.IO\.File\.WriteAllBytesAsync" -A 2

Length of output: 607

tools/rune-cli/cmd/AddCommand.cs (1)

13-14: Ensure proper dependency injection setup for AddCommand.

The constructor now uses dependency injection for ShardRegistryQuery. Ensure that the dependency is correctly configured in the DI container.

tools/rune-cli/cmd/RunCommand.cs (1)

10-20: LGTM!

The RunSettings class is well-structured for managing command options.

lib/vein.cli.core/di/SpectreConsoleHostBuilderExtensions.cs (5)

9-25: LGTM!

The UseSpectreConsole method is well-implemented with appropriate null checks and service configuration.


27-47: LGTM!

The UseSpectreConsole<TDefaultCommand> method is correctly implemented, providing flexibility for default command configuration.


49-70: LGTM!

The TypeResolver class is correctly implemented with proper disposal logic.


71-86: LGTM!

The TypeRegistrar class is well-implemented for type registration and lazy initialization.


115-119: LGTM!

The StopAsync method correctly sets the exit code and completes the task.

runtime/ishtar.base/emit/MethodBuilder.cs (1)

116-125: LGTM!

The string construction for the diagnostic debug string is well-implemented.

lib/projectsystem/Workload.cs (3)

15-21: Transition to explicit properties with required modifier is beneficial.

The change from positional parameters to explicit properties with the required modifier improves clarity and ensures necessary properties are initialized.


Line range hint 23-33:
Consistent use of explicit properties with required modifier.

The transition to explicit properties with the required modifier in WorkloadPackage aligns with best practices and ensures all properties are initialized.


136-137: Addition of static properties enhances usability.

The static properties VeinCompilerPackage and VeinRuntimePackage provide predefined instances, which are useful for common scenarios.

tools/rune-cli/Program.cs (4)

71-74: Transition to Host setup improves application architecture.

Using Host.CreateDefaultBuilder enhances configuration management and dependency injection, aligning with modern .NET practices.


75-127: Streamlined command registration enhances readability.

The use of UseSpectreConsole for command registration integrates well with dependency injection and improves code readability.


137-145: Service configuration aligns with dependency injection best practices.

Using ConfigureServices enhances modularity and maintainability, aligning with modern .NET development practices.


146-146: Asynchronous execution improves application performance.

Using RunConsoleAsync enhances the application's ability to handle asynchronous operations, improving performance and responsiveness.

runtime/ishtar.base/fs/IshtarAssembly.cs (2)

196-196: Simplification of WriteTo method reduces complexity.

The removal of debug data writing simplifies the method and reduces potential I/O overhead. Ensure that any necessary debug logging is handled elsewhere if needed.


197-197: Addition of GetDebugData method enhances debugging capabilities.

The GetDebugData method allows programmatic access to debug data, which is useful for debugging without altering the writing logic.

lib/vein.cli.core/ShardStorage.cs (6)

18-19: Introduce VeinRootFolder for base directory management.

The new VeinRootFolder provides a centralized location for the application's base directory, enhancing clarity and maintainability.


21-22: Rename RootFolder to ShardRootFolder.

The renaming clarifies the purpose of this directory, specifically for shard storage, improving code readability.


33-33: Update directory check to use ShardRootFolder.

The logic correctly checks for the existence of ShardRootFolder, aligning with the updated directory structure.


80-82: Use ShardRootFolder for package space.

The method now correctly operates within the context of the shard-specific directory, ensuring package operations are directed to the correct location.


85-86: Prune operation uses ShardRootFolder.

The pruning logic now targets files within the shard-specific directory, ensuring that cleanup operations are correctly scoped.


Line range hint 89-93:
Retrieve available versions from ShardRootFolder.

The method accurately enumerates directories within the shard-specific path, aligning with the updated storage structure.

tools/compiler/compilation/CompilationTask.cs (1)

1-10: Review removed using directives.

The removal of using directives may simplify dependencies, but verify that no required namespaces are missing from the file.

lib/projectsystem/Workload.converters.cs (1)

182-214: Review the new DictionaryWithPackageKeyConverter<T> class.

The new class DictionaryWithPackageKeyConverter<T> is well-implemented for handling JSON serialization and deserialization of dictionaries with PackageKey keys. Ensure that the type T is compatible with JSON serialization.

runtime/ishtar.base/emit/ClassBuilder.cs (1)

249-263: Review the new BakeDiagnosticDebugString method.

The BakeDiagnosticDebugString method provides a detailed and well-formatted diagnostic string representation of the class. It enhances debugging capabilities by offering insights into the class structure and its methods.

tools/rune-cli/cmd/InstallWorkloadCommand.cs (3)

32-39: Review the new WorkloadInstallingContext record.

The WorkloadInstallingContext record effectively encapsulates parameters for workload installation, improving code clarity and organization. This aligns with modern C# practices for handling immutable data.


Line range hint 52-113:
Review changes to WorkloadRegistryLoader and InstallWorkloadAsync.

The updates to use WorkloadInstallingContext improve the method signature and maintainability. The logic for workload installation is clear and well-structured.


175-175: Ensure correct usage of InstallWorkloadAsync.

The method call now uses WorkloadInstallingContext. Verify that all calls to InstallWorkloadAsync are updated to use the new context.

Verification successful

All calls to InstallWorkloadAsync use WorkloadInstallingContext.

The method InstallWorkloadAsync is consistently called with WorkloadInstallingContext across the InstallWorkloadCommand.cs file. No discrepancies were found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all calls to `InstallWorkloadAsync` are updated to use `WorkloadInstallingContext`.

# Test: Search for the method usage. Expect: Only occurrences of the new signature.
rg --type cs 'InstallWorkloadAsync\('

Length of output: 516

runtime/ishtar.base/emit/ILGenerator.cs (3)

24-24: Addition of _diagnosticDebugBuilder enhances debugging capabilities.

The introduction of _diagnosticDebugBuilder is a good step towards capturing more detailed diagnostic information. Ensure its usage aligns with the intended debugging improvements.


587-588: BakeDiagnosticDebugString method complements existing debugging functionalities.

This method effectively utilizes _diagnosticDebugBuilder to provide additional diagnostic insights, enhancing the debugging process.


671-676: Modification to DebugAppendLine improves traceability.

Appending to both _debugBuilder and _diagnosticDebugBuilder, along with the stack trace, enhances the ability to trace and diagnose issues effectively.

vein_lang.sln (3)

76-77: Addition of "vein.compiler.shared" project entry enhances solution structure.

The inclusion of "vein.compiler.shared" in the solution file is a positive step towards expanding the project's capabilities and organization.


398-409: Updates to SolutionConfigurationPlatforms ensure proper integration.

The addition of build configurations for "vein.compiler.shared" ensures it is correctly included in the solution's build process.


437-437: Updates to SolutionProperties align new project with existing structure.

Associating "vein.compiler.shared" with existing solution properties ensures consistency and proper organization within the solution.

Comment on lines +9 to +23
public static async Task Begin()
{
if (LockFile.Exists)
{
var pid = int.Parse(await LockFile.ReadToEndAsync());
if (Process.GetCurrentProcess().Id == pid)
return;
if (ProcessHasExist(pid))
{
AnsiConsole.Markup($"Lockfile [gray]{LockFile.FullName}[/] exist, currently rune cli already active, processId: [red]{pid}[/]");
Environment.Exit(-1);
}
}
await LockFile.WriteAllTextAsync(Process.GetCurrentProcess().Id.ToString());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper error handling for file operations.

The Begin method performs file I/O operations without handling potential exceptions. Consider wrapping file operations in try-catch blocks to handle exceptions such as IOException or UnauthorizedAccessException.

public static async Task Begin()
{
    try
    {
        if (LockFile.Exists)
        {
            var pid = int.Parse(await LockFile.ReadToEndAsync());
            if (Process.GetCurrentProcess().Id == pid)
                return;
            if (ProcessHasExist(pid))
            {
                AnsiConsole.Markup($"Lockfile [gray]{LockFile.FullName}[/] exist, currently rune cli already active, processId: [red]{pid}[/]");
                Environment.Exit(-1);
            }
        }
        await LockFile.WriteAllTextAsync(Process.GetCurrentProcess().Id.ToString());
    }
    catch (Exception ex)
    {
        AnsiConsole.Markup($"[red]Error handling lock file: {ex.Message}[/]");
        Environment.Exit(-1);
    }
}

Comment on lines +25 to +28
public static async Task End()
{
if (LockFile.Exists)
LockFile.Delete();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle exceptions when deleting lock file.

The End method deletes the lock file but does not handle potential exceptions. Consider wrapping the delete operation in a try-catch block to handle exceptions such as IOException.

public static async Task End()
{
    try
    {
        if (LockFile.Exists)
            LockFile.Delete();
    }
    catch (Exception ex)
    {
        AnsiConsole.Markup($"[red]Error deleting lock file: {ex.Message}[/]");
    }
}

Comment on lines +31 to +41
private static bool ProcessHasExist(int pid)
{
try
{
Process.GetProcessById(pid);
return true;
}
catch (Exception e)
{
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refine exception handling for process checking.

The ProcessHasExist method catches a general Exception, which is too broad. Consider catching specific exceptions like ArgumentException or InvalidOperationException.

private static bool ProcessHasExist(int pid)
{
    try
    {
        Process.GetProcessById(pid);
        return true;
    }
    catch (ArgumentException)
    {
        return false;
    }
    catch (InvalidOperationException)
    {
        return false;
    }
}

Comment on lines +21 to +35
public async ValueTask<int> ExecuteAsync()
{
var outputTask = Task.Run(async () =>
{
_process.Start();
using var reader = _process.StandardOutput;
char[] buffer = new char[1024];
int charsRead;
while ((charsRead = await reader.ReadAsync(buffer, 0, buffer.Length)) > 0)
await Console.Out.WriteAsync(new string(buffer, 0, charsRead));
});

await Task.WhenAll(outputTask, _process.WaitForExitAsync());

return _process.ExitCode;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper error handling during process execution.

The ExecuteAsync method starts a process and reads its output asynchronously. Consider adding try-catch blocks to handle exceptions such as InvalidOperationException or IOException during process start and output reading.

public async ValueTask<int> ExecuteAsync()
{
    try
    {
        var outputTask = Task.Run(async () =>
        {
            _process.Start();
            using var reader = _process.StandardOutput;
            char[] buffer = new char[1024];
            int charsRead;
            while ((charsRead = await reader.ReadAsync(buffer, 0, buffer.Length)) > 0)
                await Console.Out.WriteAsync(new string(buffer, 0, charsRead));
        });

        await Task.WhenAll(outputTask, _process.WaitForExitAsync());
    }
    catch (Exception ex)
    {
        Console.Error.WriteLine($"Error executing process: {ex.Message}");
        return -1;
    }

    return _process.ExitCode;
}

Comment on lines +27 to +34
public async Task RegistrySdkAsync(string sdkTarget, string alias, DirectoryInfo baseFolder)
{
var db = await OpenAsync();
db.sdks.TryAdd(sdkTarget, new UniqueList<string>());

db.sdks[sdkTarget].Add(baseFolder.Combine(new FileInfo(alias)).FullName);
await SaveAsync(db);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider combining similar logic in RegistrySdkAsync.

The logic for handling SDKs is similar to tools. Consider refactoring to reduce duplication and improve maintainability.

private async Task AddToRegistry<T>(Dictionary<T, List<string>> registry, T key, string item)
{
    registry.TryAdd(key, new List<string>());
    registry[key].Add(item);
    await SaveAsync(db);
}

Comment on lines +17 to +19
if (reader.Value is not string str)
throw new InvalidOperationException();
return new(str);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve exception message for WorkloadKeyContactConverter.

The InvalidOperationException thrown when reader.Value is not a string lacks a descriptive message. Providing a message can help with debugging.

-    throw new InvalidOperationException();
+    throw new InvalidOperationException("Expected a string value for WorkloadKey.");
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (reader.Value is not string str)
throw new InvalidOperationException();
return new(str);
if (reader.Value is not string str)
throw new InvalidOperationException("Expected a string value for WorkloadKey.");
return new(str);

Comment on lines +30 to +32
if (reader.Value is not string str)
throw new InvalidOperationException();
return new(str);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve exception message for PackageKeyContactConverter.

The InvalidOperationException should include a descriptive message to aid in debugging.

-    throw new InvalidOperationException();
+    throw new InvalidOperationException("Expected a string value for PackageKey.");
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (reader.Value is not string str)
throw new InvalidOperationException();
return new(str);
if (reader.Value is not string str)
throw new InvalidOperationException("Expected a string value for PackageKey.");
return new(str);

Comment on lines +86 to +110
if (!string.IsNullOrEmpty(settings.OverrideBootCfg))
{
var fullyPath = "";
if (!Path.IsPathFullyQualified(settings.OverrideBootCfg))
{
if (settings.OverrideBootCfg.StartsWith("@")) // this a root of project
fullyPath = Path.Combine(project.WorkDir.FullName, settings.OverrideBootCfg.Replace("@", ""));
else
{
Log.Error($"Relative '[orange]{settings.OverrideBootCfg}[/]' not supported, use a @ symbol for mark a root path (at project base)");
return -1;
}
}


var file = new FileInfo(fullyPath);

if (!file.Exists)
{
Log.Error($"'[orange]{settings.OverrideBootCfg}[/]' not found, [red]failed[/] override boot config '[gray]rune workload install vein.compiler[/]'?");
return -1;
}

boot_config_data = await file.ReadToEndAsync();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor boot configuration path handling.

The logic for determining the fullyPath variable can be simplified and clarified. Consider using a helper method for path resolution.

private string ResolveBootConfigPath(string path, VeinProject project)
{
    if (Path.IsPathFullyQualified(path))
        return path;

    if (path.StartsWith("@"))
        return Path.Combine(project.WorkDir.FullName, path.Replace("@", ""));

    Log.Error($"Relative path '{path}' not supported. Use '@' for project root.");
    return string.Empty;
}

Comment on lines +106 to +115
public string BakeDiagnosticDebugString()
{
var str = new StringBuilder();
var args = Signature.ToTemplateString(true);
if (Flags.HasFlag(Extern))
return "";
if (Flags.HasFlag(Extern))
return "";
if (Flags.HasFlag(Abstract))
return "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant flag checks.

The checks for Extern flags are repeated. Consider consolidating them for clarity.

-    if (Flags.HasFlag(Extern))
-        return "";
-    if (Flags.HasFlag(Extern))
-        return "";
+    if (Flags.HasFlag(Extern) || Flags.HasFlag(Abstract))
+        return "";
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public string BakeDiagnosticDebugString()
{
var str = new StringBuilder();
var args = Signature.ToTemplateString(true);
if (Flags.HasFlag(Extern))
return "";
if (Flags.HasFlag(Extern))
return "";
if (Flags.HasFlag(Abstract))
return "";
public string BakeDiagnosticDebugString()
{
var str = new StringBuilder();
var args = Signature.ToTemplateString(true);
if (Flags.HasFlag(Extern) || Flags.HasFlag(Abstract))
return "";

Comment on lines +44 to +45
public static string SanitizeFileSystemName(this string name)
=> Path.GetInvalidFileNameChars().Concat([' ', ')', '(', '\\', '/', ',', '@']).Aggregate(name, (current, c) => current.Replace(c.ToString(), ""));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize SanitizeFileSystemName for performance.

The method SanitizeFileSystemName uses Aggregate, which can be inefficient. Consider using StringBuilder for better performance.

public static string SanitizeFileSystemName(this string name)
{
    var invalidChars = Path.GetInvalidFileNameChars().Concat(new[] { ' ', ')', '(', '\\', '/', ',', '@' });
    var builder = new StringBuilder(name.Length);
    foreach (var c in name)
    {
        if (!invalidChars.Contains(c))
            builder.Append(c);
    }
    return builder.ToString();
}

@0xF6 0xF6 merged commit b87dc5c into master Aug 15, 2024
5 of 6 checks passed
@0xF6 0xF6 deleted the feature/fork_process_tools branch August 15, 2024 08:36
@vein-lang vein-lang locked and limited conversation to collaborators Aug 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-compiler Area of compiler staff feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant