From f6ecbc0b5ab5d876a986c9961b062e3fb98817f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Duchesneau?= Date: Fri, 6 Dec 2024 16:25:45 -0500 Subject: [PATCH] fix conflict while running multiple 'protogen' or 'build' commands on at the same time --- cmd/substreams/build.go | 4 ++++ codegen/proto_generator.go | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/substreams/build.go b/cmd/substreams/build.go index 9c0be9a0..d0afac6b 100644 --- a/cmd/substreams/build.go +++ b/cmd/substreams/build.go @@ -397,5 +397,9 @@ func runCommandInDir(ctx context.Context, dir string, cmdArgs []string) error { return fmt.Errorf("error running `%s`: %w", strings.Join(cmdArgs, " "), err) } + if cmd.ProcessState.ExitCode() != 0 { + return fmt.Errorf("command %q failed with exit code %d", strings.Join(cmdArgs, " "), cmd.ProcessState.ExitCode()) + } + return nil } diff --git a/codegen/proto_generator.go b/codegen/proto_generator.go index 47314671..9b0af205 100644 --- a/codegen/proto_generator.go +++ b/codegen/proto_generator.go @@ -36,7 +36,14 @@ func NewProtoGenerator(outputPath string, excludedPaths []string, generateMod bo } func (g *ProtoGenerator) GenerateProto(pkg *pbsubstreams.Package) error { - spkgTemporaryFilePath := filepath.Join(os.TempDir(), pkg.PackageMeta[0].Name+".tmp.spkg") + + tmpDir, err := os.MkdirTemp("", "substreams_protogen") + if err != nil { + return err + } + defer os.RemoveAll(tmpDir) + + spkgTemporaryFilePath := filepath.Join(tmpDir, pkg.PackageMeta[0].Name+".tmp.spkg") cnt, err := proto.Marshal(pkg) if err != nil { return fmt.Errorf("marshalling package: %w", err)