Skip to content

Commit

Permalink
Add built packages json writing to sysroot
Browse files Browse the repository at this point in the history
  • Loading branch information
mikusaq committed Nov 27, 2024
1 parent fa50883 commit 42beb6e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bap-builder/PackageMode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
42 changes: 42 additions & 0 deletions modules/bringauto_sysroot/BuiltPackages.go
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 6 additions & 1 deletion modules/bringauto_sysroot/Sysroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Sysroot struct {
IsDebug bool
// PlatformString
PlatformString *bringauto_package.PlatformString
builtPackages BuiltPackages
}

func (sysroot *Sysroot) FillDefault(*bringauto_prerequisites.Args) error {
Expand All @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit 42beb6e

Please sign in to comment.