Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

srcd parse: do not check the list of languages #449

Merged
merged 2 commits into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@

- The commands fail gracefully if an incompatible Docker installation is found, such as Docker Toolbox ([#417](https://github.com/src-d/engine/issues/417)).

### Known Issues

- [#297](https://github.com/src-d/engine/issues/297): `srcd parse` does not detect the language automatically for bash files. For this language you will need to set `--lang` manually. For example:
```
$ srcd parse uast file.bash --lang bash
```

</details>

## [v0.12.0](https://github.com/src-d/engine/releases/tag/v0.12.0) - 2019-04-04
Expand Down
28 changes: 13 additions & 15 deletions cmd/srcd/cmd/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ func (cmd *parseUASTCmd) Execute(args []string) error {
}

lang := cmd.Lang
var resp *api.ListDriversResponse

if lang == "" {
lang, err = parseLang(ctx, c, cmd.Args.Path, b)
started()
Expand All @@ -89,21 +87,10 @@ func (cmd *parseUASTCmd) Execute(args []string) error {
}

log.Infof("detected language: %s", lang)
resp, err = c.ListDrivers(ctx, &api.ListDriversRequest{})
} else {
resp, err = c.ListDrivers(ctx, &api.ListDriversRequest{})
started()
}

if err != nil {
return humanizef(err, "could not list drivers")
}

err = checkSupportedLanguage(resp.Drivers, lang)
if err != nil {
return err
}

stream, err := c.ParseWithLogs(ctx, &api.ParseRequest{
Kind: api.ParseRequest_UAST,
Name: cmd.Args.Path,
Expand All @@ -123,6 +110,12 @@ func (cmd *parseUASTCmd) Execute(args []string) error {
}

if err != nil {
if strings.Contains(err.Error(), "missing driver for language") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have an issue in bblfsh to export this error instead of strings.Contains?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait. this is an issue in engine about aliasing.

I'm talking about an issue in bblfsh-sdk / bblfsh-go-client that would differentiate lang not found error from any other error.
I don't see any link or any conversation about it in 297.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carlosms ping

if err := checkSupportedLanguage(ctx, c, lang); err != nil {
return err
}
}

return humanizef(err, "could not stream")
}

Expand Down Expand Up @@ -211,10 +204,15 @@ func parseLang(ctx context.Context, client api.EngineClient, path string, b []by
return res.Lang, nil
}

func checkSupportedLanguage(supportedDrivers []*api.ListDriversResponse_DriverInfo, desired string) error {
func checkSupportedLanguage(ctx context.Context, c api.EngineClient, desired string) error {
resp, errList := c.ListDrivers(ctx, &api.ListDriversRequest{})
if errList != nil {
return humanizef(errList, "could not list drivers")
}

var langs []string
isSupported := false
for _, driver := range supportedDrivers {
for _, driver := range resp.Drivers {
langs = append(langs, driver.Lang)
if driver.Lang == desired {
isSupported = true
Expand Down
28 changes: 17 additions & 11 deletions cmdtests/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ var testCases = []testCase{
filename: "hello-py3.py",
lang: "python",
},
{
path: filepath.FromSlash("testdata/hello.cpp"),
filename: "hello.cpp",
lang: "c++",
},
// Disabled cpp parsing, see https://github.com/bblfsh/cpp-driver/issues/31
/*
{
path: filepath.FromSlash("testdata/hello.cpp"),
filename: "hello.cpp",
lang: "c++",
},
*/
{
path: filepath.FromSlash("testdata/hello.java"),
filename: "hello.java",
Expand All @@ -72,11 +75,14 @@ var testCases = []testCase{
filename: "hello.go",
lang: "go",
},
{
path: filepath.FromSlash("testdata/hello.cs"),
filename: "hello.cs",
lang: "c#",
},
// Disabled csharp parsing, see https://github.com/bblfsh/bblfshd/issues/259
/*
{
path: filepath.FromSlash("testdata/hello.cs"),
filename: "hello.cs",
lang: "c#",
},
*/
{
path: filepath.FromSlash("testdata/hello.php"),
filename: "hello.php",
Expand Down Expand Up @@ -177,7 +183,7 @@ func (s *ParseTestSuite) TestUast() {
// ----------------
// TODO Temporary test skip, it fails for cpp, bash, and csharp.
// See https://github.com/src-d/engine/issues/297
if tc.lang == "c++" || tc.lang == "shell" || tc.lang == "c#" {
if tc.lang == "shell" {
// This Error assertion will fail when #297 is fixed, to remind us to remove this skip
require.Error(r.Error)
t.Skip("TEST FAILURE IS A KNOWN ISSUE (#297): " + r.Stdout())
Expand Down