Skip to content

Modernization Phase 1: Complete File Operations Component implementation to eliminate shell dependencies #40

@avrabe

Description

@avrabe

Problem

The Universal File Operations Component in tools/bazel_helpers/file_ops_actions.bzl was designed to replace shell scripts with cross-platform WebAssembly component calls. However, it still uses shell commands internally, defeating its own purpose.

Current Implementation Issues

File: tools/bazel_helpers/file_ops_actions.bzl (Lines 188-221)

# Ironically, the "Universal File Operations" still uses shell commands!
def prepare_workspace_action(ctx, config):
    commands = ["mkdir -p {}".format(workspace_dir.path)]
    
    # Programmatic shell command generation
    for source_info in config.get("sources", []):
        commands.append("cp {} {}/{}".format(src_file.path, workspace_dir.path, dest_name))
    
    # Multi-command shell execution
    ctx.actions.run_shell(
        command = " && ".join(commands),  # Shell dependency!
        # ...
    )

Impact

  • Windows incompatibility: Shell commands like cp and mkdir -p don't work on Windows
  • Defeats the purpose: Component was created to eliminate shell dependencies but still uses them
  • Hermetic build violations: Relies on system shell and utilities
  • Inconsistent approach: Other parts of codebase have been modernized to use Bazel-native operations

Solution

Replace shell command generation with actual usage of the File Operations Component that the module is building.

Implementation Plan

  1. Use the component for individual operations instead of shell commands:

    def prepare_workspace_action(ctx, config):
        workspace_dir = ctx.actions.declare_directory(config["work_dir"])
        
        # Use the actual File Operations Component
        for source_info in config.get("sources", []):
            file_ops_action(ctx, "copy_file", 
                           src=source_info["source"], 
                           dest=workspace_dir.path + "/" + source_info.get("destination"))
        
        # No more shell commands!
        return workspace_dir
  2. Alternative: Use Bazel Skylib for cross-platform file operations:

    load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
    # Use copy_file, write_file, etc. instead of shell commands

Files to Update

  • tools/bazel_helpers/file_ops_actions.bzl - Replace shell commands with component calls
  • Any rules using prepare_workspace_action - Verify compatibility

Testing

  • Test workspace preparation on Windows, macOS, and Linux
  • Verify Go module setup still works correctly
  • Check that all file operations maintain proper permissions

Acceptance Criteria

  • No shell commands (cp, mkdir) in prepare_workspace_action
  • All file operations use either the File Operations Component or Bazel Skylib
  • Cross-platform compatibility verified
  • All existing functionality preserved
  • Tests pass on all platforms

Priority

HIGH - This is an easy win that demonstrates our commitment to cross-platform Bazel-native operations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions