summaryrefslogtreecommitdiff
path: root/sdk/update.go
diff options
context:
space:
mode:
author Paul Duffin <paulduffin@google.com> 2020-05-19 07:53:27 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2020-05-19 07:53:27 +0000
commit6b3ca917b0061c751d62ef99a76c15d56a53e084 (patch)
tree953931b70e556941677c7d75f6511ca23f2ebe2b /sdk/update.go
parent7b7aa8c3ef5ffa669b7baca9150a62703e9ddeb0 (diff)
parentf88d8e032f494cc0d649f38fa8574103700dc59c (diff)
Merge "Syntax check generated Android.bp snapshot"
Diffstat (limited to 'sdk/update.go')
-rw-r--r--sdk/update.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/sdk/update.go b/sdk/update.go
index 476a4a5ea..1ba58064d 100644
--- a/sdk/update.go
+++ b/sdk/update.go
@@ -350,6 +350,9 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) andro
bp = newGeneratedFile(ctx, "snapshot", "Android.bp")
generateBpContents(&bp.generatedContents, bpFile)
+ contents := bp.content.String()
+ syntaxCheckSnapshotBpFile(ctx, contents)
+
bp.build(pctx, ctx, nil)
filesToZip := builder.filesToZip
@@ -394,6 +397,36 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) andro
return outputZipFile
}
+// Check the syntax of the generated Android.bp file contents and if they are
+// invalid then log an error with the contents (tagged with line numbers) and the
+// errors that were found so that it is easy to see where the problem lies.
+func syntaxCheckSnapshotBpFile(ctx android.ModuleContext, contents string) {
+ errs := android.CheckBlueprintSyntax(ctx, "Android.bp", contents)
+ if len(errs) != 0 {
+ message := &strings.Builder{}
+ _, _ = fmt.Fprint(message, `errors in generated Android.bp snapshot:
+
+Generated Android.bp contents
+========================================================================
+`)
+ for i, line := range strings.Split(contents, "\n") {
+ _, _ = fmt.Fprintf(message, "%6d: %s\n", i+1, line)
+ }
+
+ _, _ = fmt.Fprint(message, `
+========================================================================
+
+Errors found:
+`)
+
+ for _, err := range errs {
+ _, _ = fmt.Fprintf(message, "%s\n", err.Error())
+ }
+
+ ctx.ModuleErrorf("%s", message.String())
+ }
+}
+
func extractCommonProperties(ctx android.ModuleContext, extractor *commonValueExtractor, commonProperties interface{}, inputPropertiesSlice interface{}) {
err := extractor.extractCommonProperties(commonProperties, inputPropertiesSlice)
if err != nil {