Permalink
Browse files

properly handle context

  • Loading branch information...
peter-edge committed Dec 3, 2015
1 parent b4e6f78 commit 153ef28f6c2100d80cee4d2d6ebba3138e30b350
Showing with 44 additions and 24 deletions.
  1. +13 −1 api_server.go
  2. +2 −23 server_compiler.go
  3. +29 −0 util.go
View
@@ -34,6 +34,11 @@ func (a *apiServer) Compile(ctx context.Context, request *CompileRequest) (respo
if filepath.IsAbs(relContext) {
return nil, fmt.Errorf("protoeasy: expected relative path, got %s", relContext)
}
// TODO(pedge)
relOutDirPaths := getRelOutDirPaths(request.CompileOptions)
if len(relOutDirPaths) != 0 {
return nil, fmt.Errorf("protoeasy, context not supported with rel_out options, %v", relOutDirPaths)
}
}
dirPath, err := ioutil.TempDir("", "protoeasy-input")
if err != nil {
@@ -54,11 +59,16 @@ func (a *apiServer) Compile(ctx context.Context, request *CompileRequest) (respo
}
}()
fullDirPath := dirPath
fullOutDirPath := outDirPath
if relContext != "" {
fullDirPath = filepath.Join(dirPath, relContext)
if err := os.MkdirAll(fullDirPath, 0755); err != nil {
return nil, err
}
fullOutDirPath = filepath.Join(outDirPath, relContext)
if err := os.MkdirAll(fullOutDirPath, 0755); err != nil {
return nil, err
}
}
if err := untar(request.Tar, fullDirPath); err != nil {
return nil, err
@@ -67,7 +77,9 @@ func (a *apiServer) Compile(ctx context.Context, request *CompileRequest) (respo
if err != nil {
return nil, err
}
tar, err := tar(outDirPath, []string{"."})
// TODO(pedge): this is what preventing rel_out options with context
// we would need to move the output from each rel out outside of context
tar, err := tar(fullOutDirPath, []string{"."})
if err != nil {
return nil, err
}
View
@@ -2,7 +2,6 @@ package protoeasy
import (
"fmt"
"os"
"path/filepath"
"go.pedge.io/pkg/exec"
@@ -30,7 +29,8 @@ func (c *serverCompiler) Compile(dirPath string, outDirPath string, compileOptio
if err != nil {
return nil, err
}
if err := makeOutDirs(outDirPath, compileOptions); err != nil {
relOutDirPaths := getRelOutDirPaths(compileOptions)
if err := mkdir(outDirPath, relOutDirPaths...); err != nil {
return nil, err
}
for _, command := range commands {
@@ -111,24 +111,3 @@ func getPlugins(compileOptions *CompileOptions) []plugin {
}
return plugins
}
func makeOutDirs(outDirPath string, compileOptions *CompileOptions) error {
if err := os.MkdirAll(outDirPath, 0755); err != nil {
return err
}
for _, relDirPath := range []string{
compileOptions.CppRelOut,
compileOptions.CsharpRelOut,
compileOptions.GoRelOut,
compileOptions.ObjcRelOut,
compileOptions.PythonRelOut,
compileOptions.RubyRelOut,
} {
if relDirPath != "" {
if err := os.MkdirAll(filepath.Join(outDirPath, relDirPath), 0755); err != nil {
return err
}
}
}
return nil
}
View
29 util.go
@@ -21,6 +21,35 @@ type protoSpec struct {
RelDirPathToFiles map[string][]string
}
func mkdir(dirPath string, subDirPaths ...string) error {
if err := os.MkdirAll(dirPath, 0755); err != nil {
return err
}
for _, subDirPath := range subDirPaths {
if err := os.MkdirAll(filepath.Join(dirPath, subDirPath), 0755); err != nil {
return err
}
}
return nil
}
func getRelOutDirPaths(compileOptions *CompileOptions) []string {
var relOutDirPaths []string
for _, relOutDirPath := range []string{
compileOptions.CppRelOut,
compileOptions.CsharpRelOut,
compileOptions.GoRelOut,
compileOptions.ObjcRelOut,
compileOptions.PythonRelOut,
compileOptions.RubyRelOut,
} {
if relOutDirPath != "" {
relOutDirPaths = append(relOutDirPaths, relOutDirPath)
}
}
return relOutDirPaths
}
func getAllRelProtoFilePaths(dirPath string) ([]string, error) {
var relProtoFilePaths []string
if err := filepath.Walk(

0 comments on commit 153ef28

Please sign in to comment.