Skip to content

Commit 2a1403e

Browse files
authored
Make Ruby sdkbuild BaseDir consistent with Python/TS (#780)
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.
1 parent 98d3004 commit 2a1403e

3 files changed

Lines changed: 20 additions & 15 deletions

File tree

cmd/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func (r *Runner) Run(ctx context.Context, patterns []string) error {
353353
if r.config.DirName != "" {
354354
r.program, err = sdkbuild.RubyProgramFromDir(
355355
filepath.Join(r.rootDir, r.config.DirName),
356-
r.rootDir,
356+
filepath.Join(r.rootDir, "harness", "ruby"),
357357
)
358358
}
359359
if err == nil {

cmd/run_ruby.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ func (p *Preparer) BuildRubyProgram(ctx context.Context) (sdkbuild.Program, erro
2020
// Get version from harness/ruby/Gemfile if not present.
2121
// If no version constraint is specified in the Gemfile, version stays empty
2222
// and the package manager will resolve to the latest release.
23+
rubyDir := filepath.Join(p.rootDir, "harness", "ruby")
2324
version := p.config.Version
2425
if version == "" {
25-
b, err := os.ReadFile(filepath.Join(p.rootDir, "harness", "ruby", "Gemfile"))
26+
b, err := os.ReadFile(filepath.Join(rubyDir, "Gemfile"))
2627
if err != nil {
2728
return nil, fmt.Errorf("failed reading harness/ruby/Gemfile: %w", err)
2829
}
@@ -41,9 +42,10 @@ func (p *Preparer) BuildRubyProgram(ctx context.Context) (sdkbuild.Program, erro
4142
}
4243

4344
prog, err := sdkbuild.BuildRubyProgram(ctx, sdkbuild.BuildRubyProgramOptions{
44-
BaseDir: p.rootDir,
45-
DirName: p.config.DirName,
46-
Version: version,
45+
BaseDir: p.rootDir,
46+
SourceDir: rubyDir,
47+
DirName: p.config.DirName,
48+
Version: version,
4749
})
4850
if err != nil {
4951
return nil, fmt.Errorf("failed preparing: %w", err)

sdkbuild/ruby.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
type BuildRubyProgramOptions struct {
1515
// Directory that will have a temporary directory created underneath.
1616
BaseDir string
17+
// Directory containing the Ruby source (gemspec + runner.rb).
18+
SourceDir string
1719
// If not set, no version constraint is applied and the package manager
1820
// resolves to the latest release. If it contains a slash it is assumed
1921
// 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
4244
return nil, fmt.Errorf("base dir required")
4345
}
4446

45-
sourceDir := filepath.Join(options.BaseDir, "harness", "ruby")
47+
sourceDir := options.SourceDir
4648

4749
// Create temp dir if needed that we will remove if creating is unsuccessful
4850
success := false
@@ -74,7 +76,9 @@ func BuildRubyProgram(ctx context.Context, options BuildRubyProgramOptions) (*Ru
7476
return cmd.Run()
7577
}
7678

77-
// Build the Gemfile content
79+
// Build the Gemfile content. We use Bundler's `gemspec` directive to
80+
// auto-discover the gemspec in the source directory (via path: option).
81+
// This works for any gem name (harness, omes, etc.).
7882
var gemfileContent string
7983
if strings.ContainsAny(options.Version, `/\`) {
8084
// It's a path to a local SDK repo
@@ -94,21 +98,20 @@ func BuildRubyProgram(ctx context.Context, options BuildRubyProgramOptions) (*Ru
9498
gemfileContent = fmt.Sprintf(`source "https://rubygems.org"
9599
96100
gem "temporalio", path: %q
97-
gem "harness", path: %q
101+
gemspec path: %q
98102
`, gemPath, sourceDir)
99103
} else if options.Version != "" {
100104
version := strings.TrimPrefix(options.Version, "v")
101105
gemfileContent = fmt.Sprintf(`source "https://rubygems.org"
102106
103107
gem "temporalio", "%s"
104-
gem "harness", path: %q
108+
gemspec path: %q
105109
`, version, sourceDir)
106110
} else {
107111
// No version constraint — Bundler resolves to latest from RubyGems
108112
gemfileContent = fmt.Sprintf(`source "https://rubygems.org"
109113
110-
gem "temporalio"
111-
gem "harness", path: %q
114+
gemspec path: %q
112115
`, sourceDir)
113116
}
114117

@@ -155,13 +158,13 @@ gem "harness", path: %q
155158
}
156159

157160
// RubyProgramFromDir recreates the Ruby program from a Dir() result of a
158-
// BuildRubyProgram(). Note, the base directory of dir when it was built must
159-
// also be present.
160-
func RubyProgramFromDir(dir string, rootDir string) (*RubyProgram, error) {
161+
// BuildRubyProgram(). The sourceDir should point to the directory containing
162+
// the gemspec and runner.rb.
163+
func RubyProgramFromDir(dir string, sourceDir string) (*RubyProgram, error) {
161164
if _, err := os.Stat(filepath.Join(dir, "Gemfile")); err != nil {
162165
return nil, fmt.Errorf("failed finding Gemfile in dir: %w", err)
163166
}
164-
return &RubyProgram{dir: dir, source: filepath.Join(rootDir, "harness", "ruby")}, nil
167+
return &RubyProgram{dir: dir, source: sourceDir}, nil
165168
}
166169

167170
// Dir is the directory to run in.

0 commit comments

Comments
 (0)