Skip to content

Commit e1a7159

Browse files
biruntsJonathan Watson
authored andcommitted
chore: Encode and Decode for providers
All used providers are obligated now to implement blueprint's `gobtools.CustomEnc` and `gobtools.CustomDec`. Change-Id: I6f2bcb20b51ee779cb0da50840e22d7d905104f6 Signed-off-by: Sebastian Birunt <sebastian.birunt@arm.com>
1 parent 9964a02 commit e1a7159

3 files changed

Lines changed: 131 additions & 0 deletions

File tree

core/androidbp_backend.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,17 @@ func (s *androidBpSingleton) GenerateBuildActions(ctx blueprint.SingletonContext
471471
text = strings.Replace(text, "@@PROJ_UID@@", projUid, -1)
472472
text = strings.Replace(text, "@@BOB_DIR@@", srcToBobDir, -1)
473473
text = strings.Replace(text, "@@SOONG_COMPAT@@", soongCompatFile, -1)
474+
var deps string
474475

475476
if soongCompatFile == "soong_compat_04_ModuleProxy.go" {
476477
text = strings.Replace(text, "@@GENRULEBOB@@", "genrule_module_proxy.go", -1)
478+
deps = "\"blueprint-gobtools\","
477479
} else {
478480
text = strings.Replace(text, "@@GENRULEBOB@@", "genrule.go", -1)
479481
}
480482

483+
text = strings.Replace(text, "@@DEPS@@", deps, -1)
484+
481485
if getConfig(ctx).Properties.GetBool("android_bp_use_soong_namespace") {
482486
sb.WriteString("soong_namespace {}\n\n")
483487
}

plugins/Android.bp.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ bootstrap_go_package {
3838
name: "bob-plugins-genrulebob-@@PROJ_UID@@",
3939
pluginFor: ["soong_build"],
4040
deps: [
41+
@@DEPS@@
4142
"blueprint",
4243
"soong-android",
4344
"soong-cc",

plugins/genrulebob/genrule_module_proxy.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package genrulebob
55

66
import (
7+
"bytes"
78
"fmt"
89
"os"
910
"path/filepath"
@@ -18,8 +19,14 @@ import (
1819
"github.com/ARM-software/bob-build/internal/utils"
1920

2021
"github.com/google/blueprint"
22+
"github.com/google/blueprint/gobtools"
2123
)
2224

25+
func init() {
26+
GenruleOutputInfoId = gobtools.RegisterType(func() gobtools.CustomDec { return new(GenruleOutputInfo) })
27+
GenruleExportInclInfoId = gobtools.RegisterType(func() gobtools.CustomDec { return new(GenruleExportInclInfo) })
28+
}
29+
2330
type commonProps struct {
2431
Srcs []string `android:"path"`
2532
Export_gen_include_dirs []string
@@ -276,6 +283,79 @@ type GenruleOutputInfo struct {
276283
ImplicitOutputs android.Paths
277284
}
278285

286+
var GenruleOutputInfoId int16
287+
288+
func (s GenruleOutputInfo) Encode(ctx gobtools.EncContext, buf *bytes.Buffer) error {
289+
var err error
290+
291+
// encode s.Outputs length
292+
if err = gobtools.EncodeInt(buf, len(s.Outputs)); err != nil {
293+
return err
294+
}
295+
296+
// encode s.ImplicitOutputs length
297+
if err = gobtools.EncodeInt(buf, len(s.ImplicitOutputs)); err != nil {
298+
return err
299+
}
300+
301+
for _, path := range s.Outputs {
302+
if err = gobtools.EncodeInterface(ctx, buf, path); err != nil {
303+
return err
304+
}
305+
}
306+
307+
for _, path := range s.ImplicitOutputs {
308+
if err = gobtools.EncodeInterface(ctx, buf, path); err != nil {
309+
return err
310+
}
311+
}
312+
313+
return err
314+
}
315+
316+
func (s GenruleOutputInfo) GetTypeId() int16 {
317+
return GenruleOutputInfoId
318+
}
319+
320+
func (s *GenruleOutputInfo) Decode(ctx gobtools.EncContext, buf *bytes.Reader) error {
321+
var err error
322+
var outputsLen int
323+
var implicitOutputsLen int
324+
325+
if err = gobtools.DecodeInt(buf, &outputsLen); err != nil {
326+
return err
327+
}
328+
329+
if err = gobtools.DecodeInt(buf, &implicitOutputsLen); err != nil {
330+
return err
331+
}
332+
333+
s.Outputs = make(android.Paths, outputsLen)
334+
s.ImplicitOutputs = make(android.Paths, implicitOutputsLen)
335+
336+
for i := 0; i < outputsLen; i++ {
337+
if val, err := gobtools.DecodeInterface(ctx, buf); err != nil {
338+
return err
339+
} else if val == nil {
340+
s.Outputs[i] = nil
341+
} else {
342+
s.Outputs[i] = val.(android.Path)
343+
}
344+
}
345+
346+
for i := 0; i < implicitOutputsLen; i++ {
347+
if val, err := gobtools.DecodeInterface(ctx, buf); err != nil {
348+
return err
349+
} else if val == nil {
350+
s.ImplicitOutputs[i] = nil
351+
} else {
352+
s.ImplicitOutputs[i] = val.(android.Path)
353+
}
354+
}
355+
356+
return err
357+
}
358+
279359
var GenruleOutputInfoProvider = blueprint.NewProvider[GenruleOutputInfo]()
280360

281361
func (m *genrulebobCommon) getArgs(ctx android.ModuleContext) (args map[string]string, dependents []android.Path) {
@@ -561,6 +641,52 @@ type GenruleExportInclInfo struct {
561641
ExportIncludes android.Paths
562642
}
563643

644+
var GenruleExportInclInfoId int16
645+
646+
func (s GenruleExportInclInfo) Encode(ctx gobtools.EncContext, buf *bytes.Buffer) error {
647+
var err error
648+
649+
// encode s.ExportIncludes length
650+
if err = gobtools.EncodeInt(buf, len(s.ExportIncludes)); err != nil {
651+
return err
652+
}
653+
654+
for _, path := range s.ExportIncludes {
655+
if err = gobtools.EncodeInterface(ctx, buf, path); err != nil {
656+
return err
657+
}
658+
}
659+
660+
return err
661+
}
662+
663+
func (s GenruleExportInclInfo) GetTypeId() int16 {
664+
return GenruleExportInclInfoId
665+
}
666+
667+
func (s *GenruleExportInclInfo) Decode(ctx gobtools.EncContext, buf *bytes.Reader) error {
668+
var err error
669+
var exportIncludesLen int
670+
671+
if err = gobtools.DecodeInt(buf, &exportIncludesLen); err != nil {
672+
return err
673+
}
674+
675+
s.ExportIncludes = make(android.Paths, exportIncludesLen)
676+
677+
for i := 0; i < exportIncludesLen; i++ {
678+
if val, err := gobtools.DecodeInterface(ctx, buf); err != nil {
679+
return err
680+
} else if val == nil {
681+
s.ExportIncludes[i] = nil
682+
} else {
683+
s.ExportIncludes[i] = val.(android.Path)
684+
}
685+
}
686+
687+
return err
688+
}
689+
564690
var GenruleExportInclInfoProvider = blueprint.NewProvider[GenruleExportInclInfo]()
565691

566692
func (m *genrulebobCommon) setupBuildActions(ctx android.ModuleContext) (args map[string]string, implicits []android.Path) {

0 commit comments

Comments
 (0)