Skip to content

Commit

Permalink
Prepare .net path in a way that avoids weird conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Sushisource committed Aug 6, 2024
1 parent 9865bb7 commit 5b675e4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ workers/java/build
/workers/dotnet/obj/
/workers/dotnet/bin/
/last_fuzz_run.proto
workers/dotnet/Temporalio.Omes.temp.csproj
37 changes: 32 additions & 5 deletions cmd/prepare_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"html"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -205,11 +206,11 @@ func (b *workerBuilder) buildTypeScript(ctx context.Context, baseDir string) (sd
func (b *workerBuilder) buildDotNet(ctx context.Context, baseDir string) (sdkbuild.Program, error) {
// Get version from dotnet.csproj if not present
version := b.version
csprojBytes, err := os.ReadFile(filepath.Join(baseDir, "Temporalio.Omes.csproj"))
if err != nil {
return nil, fmt.Errorf("failed reading dotnet.csproj: %w", err)
}
if version == "" {
csprojBytes, err := os.ReadFile(filepath.Join(baseDir, "Temporalio.Omes.csproj"))
if err != nil {
return nil, fmt.Errorf("failed reading dotnet.csproj: %w", err)
}
const prefix = `<PackageReference Include="Temporalio" Version="`
csproj := string(csprojBytes)
beginIndex := strings.Index(csproj, prefix)
Expand All @@ -221,6 +222,32 @@ func (b *workerBuilder) buildDotNet(ctx context.Context, baseDir string) (sdkbui
version = csproj[beginIndex : beginIndex+length]
}

// Prepare replaced csproj if using path-dependency
if strings.ContainsAny(version, `/\`) {
// Get absolute path of csproj file
absCsproj, err := filepath.Abs(filepath.Join(version, "src/Temporalio/Temporalio.csproj"))
if err != nil {
return nil, fmt.Errorf("cannot make absolute path from version: %w", err)
} else if _, err := os.Stat(absCsproj); err != nil {
return nil, fmt.Errorf("cannot find version path of %v: %w", absCsproj, err)
}
depLine := `<ProjectReference Include="` + html.EscapeString(absCsproj) + `" />`

// Remove whole original package reference tag
csproj := string(csprojBytes)
beginIndex := strings.Index(csproj, `<PackageReference Include="Temporalio"`)
packageRefStr := "</PackageReference>"
endIndex := strings.Index(csproj[beginIndex:], packageRefStr) + beginIndex
csproj = csproj[:beginIndex] + depLine + csproj[endIndex+len(packageRefStr):]

// Write new csproj
if err := os.WriteFile(filepath.Join(baseDir, "Temporalio.Omes.temp.csproj"), []byte(csproj), 0644); err != nil {
if err != nil {
return nil, fmt.Errorf("failed writing temp csproj: %w", err)
}
}
}

prog, err := sdkbuild.BuildDotNetProgram(ctx, sdkbuild.BuildDotNetProgramOptions{
BaseDir: baseDir,
Version: version,
Expand All @@ -232,7 +259,7 @@ func (b *workerBuilder) buildDotNet(ctx context.Context, baseDir string) (sdkbui
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../Temporalio.Omes.csproj" />
<ProjectReference Include="../Temporalio.Omes.temp.csproj" />
</ItemGroup>
</Project>`,
})
Expand Down
2 changes: 1 addition & 1 deletion workers/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require (
github.com/stretchr/testify v1.9.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions workers/go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down

0 comments on commit 5b675e4

Please sign in to comment.