Skip to content

Commit

Permalink
Fix generator (#13666)
Browse files Browse the repository at this point in the history
* We should never produce null packages, instead we should produce an empty array of packages when there is not any

* Add a prefix for the logs of autorest

* gofmt
  • Loading branch information
ArcturusZhang authored Nov 23, 2020
1 parent 06771b1 commit e6a7ee8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
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

0 comments on commit e6a7ee8

Please sign in to comment.