Updating profileBuilder to pass original path.
@@ -15,8 +15,10 @@ package main
// limitations under the License.
import (
+ "bytes"
"errors"
"flag"
+ "fmt"
"go/ast"
"go/parser"
"go/printer"
@@ -51,6 +53,7 @@ type WellKnownStrategy string
const (
WellKnownStrategyList WellKnownStrategy = "list"
WellKnownStrategyLatest WellKnownStrategy = "latest"
+ WellKnownStrategyPreview WellKnownStrategy = "preview"
)
// If not the empty string, this string should be stamped into files generated by the profileBuilder.
@@ -88,7 +91,7 @@ func main() {
return
}
files := token.NewFileSet()
- parsed, err := parser.ParseDir(files, cast, nil, parser.ParseComments)
+ parsed, err := parser.ParseDir(files, cast, nil, 0)
if err != nil {
return
}
@@ -101,20 +104,21 @@ func main() {
return results
}).ParallelSelect(func(x interface{}) interface{} {
+ var err error
+ var subject *goalias.AliasPackage
cast, ok := x.(*ast.Package)
if !ok {
return nil
}
var bundle alias
- subject, err := goalias.NewAliasPackage(cast)
+ for filename := range cast.Files {
+ bundle.TargetPath = filepath.Dir(filename)
+ subject, err = goalias.NewAliasPackage(cast, bundle.TargetPath)
if err != nil {
+ errLog.Print(err)
return nil
}
-
- bundle.AliasPackage = subject
- for filename := range cast.Files {
- bundle.TargetPath = filepath.Dir(filename)
bundle.TargetPath, err = getAliasPath(bundle.TargetPath, profileName)
if err != nil {
errLog.Print(err)
@@ -123,6 +127,8 @@ func main() {
break
}
+ bundle.AliasPackage = subject
+
outputLog.Printf("Alias created for package: %s", cast.Name)
return &bundle
}).Where(func(x interface{}) bool {
@@ -150,6 +156,20 @@ func main() {
return false
}
+ // TODO: This should really be added by the `goalias` package itself. Doing it here is a work around
+ fmt.Fprintln(outputFile, "// +build go1.9")
+ fmt.Fprintln(outputFile)
+
+ generatorStampBuilder := new(bytes.Buffer)
+
+ fmt.Fprintln(generatorStampBuilder, "// This code was auto-generated by:")
+ fmt.Fprintln(generatorStampBuilder, "// github.com/Azure/azure-sdk-for-go/tools/profileBuilder")
+
+ if version != "" {
+ fmt.Fprintln(generatorStampBuilder, "// commit ID:", version)
+ }
+ fmt.Fprint(outputFile, generatorStampBuilder.String())
+
outputLog.Printf("Writing File: %s", outputPath)
printer.Fprint(outputFile, files, cast.ModelFile())
@@ -223,7 +243,8 @@ func init() {
wellKnownStrategies := map[WellKnownStrategy]collection.Enumerable{
WellKnownStrategyList: ListStrategy{Reader: inputList},
- WellKnownStrategyLatest: LatestStrategy{Root: inputRoot},
+ WellKnownStrategyLatest: LatestStrategy{Root: inputRoot, Predicate: IgnorePreview},
+ WellKnownStrategyPreview: LatestStrategy{Root: inputRoot, Predicate: AcceptAll},
}
if s, ok := wellKnownStrategies[WellKnownStrategy(selectedStrategy)]; ok {
