From c733645df4056e1aa82b1f212bbb80775d36d390 Mon Sep 17 00:00:00 2001 From: Thomas Hardy Date: Sun, 22 Mar 2026 16:39:11 -0700 Subject: [PATCH] Make Ruby sdkbuild BaseDir consistent with Python/TS Previously, BuildRubyProgram hardcoded `sourceDir = BaseDir + "/harness/ruby"`, requiring callers to pass a parent directory as BaseDir. This was inconsistent with Python and TypeScript where BaseDir IS the source directory containing the project files. Now BaseDir points directly to the directory containing the gemspec and runner.rb, and RubyProgramFromDir derives the source from the parent of the build dir. Callers (run_ruby.go, run.go) updated to pass `harness/ruby` as BaseDir. This enables other repos (e.g. omes) to use BuildRubyProgram with their own directory layout without needing a `harness/ruby` subdirectory. --- cmd/run.go | 2 +- cmd/run_ruby.go | 10 ++++++---- sdkbuild/ruby.go | 23 +++++++++++++---------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index 01c51130..52233852 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -353,7 +353,7 @@ func (r *Runner) Run(ctx context.Context, patterns []string) error { if r.config.DirName != "" { r.program, err = sdkbuild.RubyProgramFromDir( filepath.Join(r.rootDir, r.config.DirName), - r.rootDir, + filepath.Join(r.rootDir, "harness", "ruby"), ) } if err == nil { diff --git a/cmd/run_ruby.go b/cmd/run_ruby.go index adc2142e..e0fe46d8 100644 --- a/cmd/run_ruby.go +++ b/cmd/run_ruby.go @@ -20,9 +20,10 @@ func (p *Preparer) BuildRubyProgram(ctx context.Context) (sdkbuild.Program, erro // Get version from harness/ruby/Gemfile if not present. // If no version constraint is specified in the Gemfile, version stays empty // and the package manager will resolve to the latest release. + rubyDir := filepath.Join(p.rootDir, "harness", "ruby") version := p.config.Version if version == "" { - b, err := os.ReadFile(filepath.Join(p.rootDir, "harness", "ruby", "Gemfile")) + b, err := os.ReadFile(filepath.Join(rubyDir, "Gemfile")) if err != nil { return nil, fmt.Errorf("failed reading harness/ruby/Gemfile: %w", err) } @@ -41,9 +42,10 @@ func (p *Preparer) BuildRubyProgram(ctx context.Context) (sdkbuild.Program, erro } prog, err := sdkbuild.BuildRubyProgram(ctx, sdkbuild.BuildRubyProgramOptions{ - BaseDir: p.rootDir, - DirName: p.config.DirName, - Version: version, + BaseDir: p.rootDir, + SourceDir: rubyDir, + DirName: p.config.DirName, + Version: version, }) if err != nil { return nil, fmt.Errorf("failed preparing: %w", err) diff --git a/sdkbuild/ruby.go b/sdkbuild/ruby.go index 5a2eacc6..6390d91d 100644 --- a/sdkbuild/ruby.go +++ b/sdkbuild/ruby.go @@ -14,6 +14,8 @@ import ( type BuildRubyProgramOptions struct { // Directory that will have a temporary directory created underneath. BaseDir string + // Directory containing the Ruby source (gemspec + runner.rb). + SourceDir string // If not set, no version constraint is applied and the package manager // resolves to the latest release. If it contains a slash it is assumed // to be a path to the Ruby SDK repo. Otherwise it is a specific version @@ -42,7 +44,7 @@ func BuildRubyProgram(ctx context.Context, options BuildRubyProgramOptions) (*Ru return nil, fmt.Errorf("base dir required") } - sourceDir := filepath.Join(options.BaseDir, "harness", "ruby") + sourceDir := options.SourceDir // Create temp dir if needed that we will remove if creating is unsuccessful success := false @@ -74,7 +76,9 @@ func BuildRubyProgram(ctx context.Context, options BuildRubyProgramOptions) (*Ru return cmd.Run() } - // Build the Gemfile content + // Build the Gemfile content. We use Bundler's `gemspec` directive to + // auto-discover the gemspec in the source directory (via path: option). + // This works for any gem name (harness, omes, etc.). var gemfileContent string if strings.ContainsAny(options.Version, `/\`) { // It's a path to a local SDK repo @@ -94,21 +98,20 @@ func BuildRubyProgram(ctx context.Context, options BuildRubyProgramOptions) (*Ru gemfileContent = fmt.Sprintf(`source "https://rubygems.org" gem "temporalio", path: %q -gem "harness", path: %q +gemspec path: %q `, gemPath, sourceDir) } else if options.Version != "" { version := strings.TrimPrefix(options.Version, "v") gemfileContent = fmt.Sprintf(`source "https://rubygems.org" gem "temporalio", "%s" -gem "harness", path: %q +gemspec path: %q `, version, sourceDir) } else { // No version constraint — Bundler resolves to latest from RubyGems gemfileContent = fmt.Sprintf(`source "https://rubygems.org" -gem "temporalio" -gem "harness", path: %q +gemspec path: %q `, sourceDir) } @@ -155,13 +158,13 @@ gem "harness", path: %q } // RubyProgramFromDir recreates the Ruby program from a Dir() result of a -// BuildRubyProgram(). Note, the base directory of dir when it was built must -// also be present. -func RubyProgramFromDir(dir string, rootDir string) (*RubyProgram, error) { +// BuildRubyProgram(). The sourceDir should point to the directory containing +// the gemspec and runner.rb. +func RubyProgramFromDir(dir string, sourceDir string) (*RubyProgram, error) { if _, err := os.Stat(filepath.Join(dir, "Gemfile")); err != nil { return nil, fmt.Errorf("failed finding Gemfile in dir: %w", err) } - return &RubyProgram{dir: dir, source: filepath.Join(rootDir, "harness", "ruby")}, nil + return &RubyProgram{dir: dir, source: sourceDir}, nil } // Dir is the directory to run in.