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

Fix generator #13666

Merged
merged 3 commits into from
Nov 23, 2020
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
1 change: 1 addition & 0 deletions swagger_to_sdk_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"generateScript": {
"path": "go run ./tools/generator/main.go",
"stderr": {
"showInComment": "^\\[AUTOREST\\]",
"scriptError": "^\\[ERROR\\]",
"scriptWarning": "^\\[WARNING\\]"
}
Expand Down
34 changes: 31 additions & 3 deletions tools/generator/autorest/autorest.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package autorest

import (
"bufio"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -35,9 +36,36 @@ func (t *Task) executeAutorest(options []string) error {
arguments := append(options, t.AbsReadmeMd)
c := exec.Command("autorest", arguments...)
log.Printf("Executing autorest with parameters: %+v", arguments)
c.Stdout = os.Stdout
c.Stderr = os.Stderr
c.Start()

stdout, _ := c.StdoutPipe()
stderr, _ := c.StderrPipe()
errScanner := bufio.NewScanner(stderr)
errScanner.Split(bufio.ScanLines)
outScanner := bufio.NewScanner(stdout)
outScanner.Split(bufio.ScanLines)

if err := c.Start(); err != nil {
return &TaskError{
AbsReadmeMd: t.AbsReadmeMd,
Script: "autorest",
Message: err.Error(),
}
}

go func() {
for errScanner.Scan() {
line := errScanner.Text()
fmt.Fprintln(os.Stderr, "[AUTOREST] "+line)
}
}()

go func() {
for outScanner.Scan() {
line := outScanner.Text()
fmt.Fprintln(os.Stdout, "[AUTOREST] "+line)
}
}()

if err := c.Wait(); err != nil {
return &TaskError{
AbsReadmeMd: t.AbsReadmeMd,
Expand Down
3 changes: 0 additions & 3 deletions tools/generator/changelog/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package changelog

import (
"fmt"
"log"
"os"

"github.com/Azure/azure-sdk-for-go/tools/apidiff/exports"
Expand All @@ -22,7 +21,6 @@ func NewChangelogForPackage(pkgDir string) (c *Changelog, err error) {
if err != nil {
return nil, err
}
log.Printf("Exports of package '%s': %+v", pkgDir, rhs)
// stash everything and get the previous status of the package
if err := stashEverything(); err != nil {
return nil, err
Expand All @@ -36,7 +34,6 @@ func NewChangelogForPackage(pkgDir string) (c *Changelog, err error) {
if err != nil {
return nil, err
}
log.Printf("Exports of original package '%s': %+v", pkgDir, lhs)
return getChangelogForPackage(pkgDir, lhs, rhs)
}

Expand Down
4 changes: 2 additions & 2 deletions tools/generator/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"fmt"
"github.com/Azure/azure-sdk-for-go/tools/generator/changelog"
"log"
"os"
"os/exec"
Expand All @@ -11,6 +10,7 @@ import (
"strings"

"github.com/Azure/azure-sdk-for-go/tools/generator/autorest"
"github.com/Azure/azure-sdk-for-go/tools/generator/changelog"
"github.com/Azure/azure-sdk-for-go/tools/generator/model"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -109,7 +109,7 @@ func generate(input *model.GenerateInput, optionPath string) (*model.GenerateOut
log.Printf("Autorest options: \n%s", options.String())

// iterate over all the readme
var results []model.PackageResult
results := make([]model.PackageResult, 0)
for _, readme := range input.RelatedReadmeMdFiles {
log.Printf("Processing readme '%s'...", readme)
task := autorest.Task{
Expand Down
2 changes: 1 addition & 1 deletion tools/generator/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type InstallInstructionScriptInput struct {

// GenerateOutput ...
type GenerateOutput struct {
Packages []PackageResult `json:"packages,omitempty"`
Packages []PackageResult `json:"packages"`
}

// String ...
Expand Down