From 42beb6e5ad4acf3d5acfe287a35575fc0c5344c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikul=C3=A1=C5=A1=20=C5=A0=C5=A5astn=C3=BD?= Date: Wed, 27 Nov 2024 10:14:13 +0200 Subject: [PATCH] Add built packages json writing to sysroot --- bap-builder/PackageMode.go | 2 +- modules/bringauto_sysroot/BuiltPackages.go | 42 ++++++++++++++++++++++ modules/bringauto_sysroot/Sysroot.go | 7 +++- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 modules/bringauto_sysroot/BuiltPackages.go diff --git a/bap-builder/PackageMode.go b/bap-builder/PackageMode.go index 19f5ffc..2a7f088 100644 --- a/bap-builder/PackageMode.go +++ b/bap-builder/PackageMode.go @@ -452,7 +452,7 @@ func buildAndCopyPackage( } logger.InfoIndent("Copying to local sysroot directory") - err = sysroot.CopyToSysroot(buildConfig.GetLocalInstallDirPath()) + err = sysroot.CopyToSysroot(buildConfig.GetLocalInstallDirPath(), buildConfig.Package.GetShortPackageName()) if err != nil { break } diff --git a/modules/bringauto_sysroot/BuiltPackages.go b/modules/bringauto_sysroot/BuiltPackages.go new file mode 100644 index 0000000..c43b6e9 --- /dev/null +++ b/modules/bringauto_sysroot/BuiltPackages.go @@ -0,0 +1,42 @@ +package bringauto_sysroot + +import ( + "encoding/json" + "os" + "path" +) + +const ( + jsonFileName = "built_packages.json" +) + +// Contains built packages in sysroot and have functions for Json encoding and decoding of built +// packages. +type BuiltPackages struct { + Packages []string +} + +func (builtPackages *BuiltPackages) AddToBuiltPackages(packageName string) error { + err := builtPackages.updateBuiltPackages() + if err != nil { + return err + } + + builtPackages.Packages = append(builtPackages.Packages, packageName) + bytes, err := json.Marshal(builtPackages.Packages) + if err != nil { + return err + } + err = os.WriteFile(path.Join(sysrootDirectoryName, jsonFileName), bytes, 0644) + return err +} + +func (builtPackages *BuiltPackages) updateBuiltPackages() error { + bytes, err := os.ReadFile(path.Join(sysrootDirectoryName, jsonFileName)) + if err != nil { + return nil + } + + err = json.Unmarshal(bytes, &builtPackages.Packages) + return err +} diff --git a/modules/bringauto_sysroot/Sysroot.go b/modules/bringauto_sysroot/Sysroot.go index aa6b6f5..36283a2 100644 --- a/modules/bringauto_sysroot/Sysroot.go +++ b/modules/bringauto_sysroot/Sysroot.go @@ -27,6 +27,7 @@ type Sysroot struct { IsDebug bool // PlatformString PlatformString *bringauto_package.PlatformString + builtPackages BuiltPackages } func (sysroot *Sysroot) FillDefault(*bringauto_prerequisites.Args) error { @@ -45,7 +46,7 @@ func (sysroot *Sysroot) CheckPrerequisites(args *bringauto_prerequisites.Args) e } // CopyToSysroot copy source to a sysroot -func (sysroot *Sysroot) CopyToSysroot(source string) error { +func (sysroot *Sysroot) CopyToSysroot(source string, packageName string) error { err := sysroot.checkForOverwritingFiles(source) if err != nil { return err @@ -59,6 +60,10 @@ func (sysroot *Sysroot) CopyToSysroot(source string) error { if err != nil { return err } + err = sysroot.builtPackages.AddToBuiltPackages(packageName) + if err != nil { + return err + } return nil }