Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev-tools/mage/dockerbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (b *dockerBuilder) Build() error {
}

if err := b.copyFiles(); err != nil {
return err
return fmt.Errorf("error copying files for docker variant %q: %w", b.DockerVariant, err)
}

if err := b.prepareBuild(); err != nil {
Expand Down
47 changes: 42 additions & 5 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,7 @@ func downloadBinary(ctx context.Context, project string, packageName string, bin
}

compl.Add(1)
fmt.Printf("Done downloading %s\n", packageName)
fmt.Printf("Done downloading %s into %s\n", packageName, targetPath)
return nil
}
}
Expand Down Expand Up @@ -1590,7 +1590,8 @@ func movePackagesToArchive(dropPath string, platformPackageSuffixes []string, pa
if mg.Verbose() {
log.Printf("--- Evaluating moving dependency %s to archive path %s\n", f, archivePath)
}
if !strings.Contains(f, packageSuffix) && !isPythonWheelPackage(f, packageVersion) {
// if the matched file name does not contain the platform suffix and it's not a platform-independent package, skip it
if !strings.Contains(f, packageSuffix) && !isPlatformIndependentPackage(f, packageVersion) {
if mg.Verbose() {
log.Printf("--- Skipped moving dependency %s to archive path\n", f)
}
Expand All @@ -1613,9 +1614,18 @@ func movePackagesToArchive(dropPath string, platformPackageSuffixes []string, pa
if err := os.MkdirAll(targetDir, 0750); err != nil {
fmt.Printf("warning: failed to create directory %s: %s", targetDir, err)
}
if err := os.Rename(f, targetPath); err != nil {
panic(fmt.Errorf("failed renaming file: %w", err))

// Platform-independent packages need to be placed in the archive sub-folders for all platforms, copy instead of moving
if isPlatformIndependentPackage(f, packageVersion) {
if err := copyFile(f, targetPath); err != nil {
panic(fmt.Errorf("failed copying file: %w", err))
}
} else {
if err := os.Rename(f, targetPath); err != nil {
panic(fmt.Errorf("failed renaming file: %w", err))
}
}

if mg.Verbose() {
log.Printf("--- Moved dependency in archive path %s => %s\n", f, targetPath)
}
Expand All @@ -1625,10 +1635,37 @@ func movePackagesToArchive(dropPath string, platformPackageSuffixes []string, pa
return archivePath
}

func isPythonWheelPackage(f string, packageVersion string) bool {
func copyFile(src, dst string) error {
srcStat, err := os.Stat(src)
if err != nil {
return fmt.Errorf("stat source file %q: %w", src, err)
}

srcF, err := os.Open(src)
if err != nil {
return fmt.Errorf("opening source file %q: %w", src, err)
}
defer srcF.Close()

dstF, err := os.OpenFile(dst, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, srcStat.Mode()|os.ModePerm)
if err != nil {
return fmt.Errorf("opening/creating destination file %q: %w", dst, err)
}
defer dstF.Close()

_, err = io.Copy(dstF, srcF)
if err != nil {
return fmt.Errorf("copying file %q to %q: %w", src, dst, err)
}

return nil
}

func isPlatformIndependentPackage(f string, packageVersion string) bool {
fileBaseName := filepath.Base(f)
for _, spec := range manifest.ExpectedBinaries {
packageName := spec.GetPackageName(packageVersion, "")
// as of now only python wheels packages are platform-independent
if spec.PythonWheel && (fileBaseName == packageName || fileBaseName == packageName+sha512FileExt) {
return true
}
Expand Down