MCPcopy Create free account
hub / github.com/celer-pkg/celer / doInstallFromSource

Method doInstallFromSource

configs/port_install.go:667–746  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

665}
666
667func (p *Port) doInstallFromSource() error {
668 var installFailed bool
669 defer func() {
670 // Remove package dir if install failed.
671 if installFailed {
672 if err := os.RemoveAll(p.PackageDir); err != nil {
673 fmt.Printf("remove broken package dir %s: %s\n", p.PackageDir, err)
674 }
675 }
676 }()
677
678 // Clean package directory.
679 if err := os.RemoveAll(p.PackageDir); err != nil {
680 installFailed = true
681 return fmt.Errorf("failed to clean package dir %s -> %w", p.PackageDir, err)
682 }
683
684 // Check if need to store pkgcache and remember the skip reason.
685 skipReason, err := p.pkgCacheStoreSkipReason()
686 if err != nil {
687 return err
688 }
689 p.pkgCacheStoreSkippedReason = skipReason
690
691 // Call matched buildsystem to configure, build and install.
692 if err := p.MatchedConfig.Install(p.Package.Url, p.Package.Ref, p.Package.Archive); err != nil {
693 installFailed = true
694 return err
695 }
696
697 // Generate meta file and store cache.
698 buildSystem := p.MatchedConfig.BuildSystem
699 if buildSystem != "nobuild" {
700 // Skip meta file and cache for ports with url="_".
701 // port with url="_" means no source repo and just in development.
702 if p.Package.Url == "_" {
703 color.Printf(color.Warning, "\n======== virtual project, skipping meta file generation and cache storing. ========\n")
704 return nil
705 }
706
707 // Write meta file with installed files and build environment.
708 metaData, err := p.buildMeta()
709 if err != nil {
710 installFailed = true
711 return err
712 }
713 metaFile := filepath.Join(p.PackageDir, p.meta2hash(metaData)) + ".meta"
714 if err := fileio.MkdirAll(filepath.Dir(metaFile), os.ModePerm); err != nil {
715 installFailed = true
716 return err
717 }
718 if err := os.WriteFile(metaFile, []byte(metaData), os.ModePerm); err != nil {
719 installFailed = true
720 return err
721 }
722
723 // Store package cache with meta file inside.
724 pkgCache := p.ctx.PkgCacheConfig()

Callers 2

InstallFromPackageMethod · 0.95
InstallFromSourceMethod · 0.95

Calls 14

buildMetaMethod · 0.95
meta2hashMethod · 0.95
PrintfFunction · 0.92
MkdirAllFunction · 0.92
WriteFileMethod · 0.80
InstallMethod · 0.65
PkgCacheConfigMethod · 0.65
IsWritableMethod · 0.65
GetArtifactCacheMethod · 0.65
StoreMethod · 0.65

Tested by

no test coverage detected