()
| 503 | } |
| 504 | |
| 505 | func (b BuildConfig) ApplyPatches() error { |
| 506 | if len(b.Patches) > 0 { |
| 507 | // Apply all patches. |
| 508 | for _, patch := range b.Patches { |
| 509 | patch = strings.TrimSpace(patch) |
| 510 | if patch == "" { |
| 511 | continue |
| 512 | } |
| 513 | |
| 514 | // Find patch file to apply. |
| 515 | portDir := filepath.Dir(b.PortConfig.PortFile) |
| 516 | patchPath := filepath.Join(portDir, patch) |
| 517 | if !fileio.PathExists(patchPath) { |
| 518 | return fmt.Errorf("patch file not exist for %s", patchPath) |
| 519 | } |
| 520 | |
| 521 | // Apply patch (linux patch or git patch). |
| 522 | if err := git.ApplyPatch(b.PortConfig.nameVersion(), b.PortConfig.RepoDir, patchPath); err != nil { |
| 523 | return err |
| 524 | } |
| 525 | |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | // Copy files under port dir if they are exist. |
| 530 | overrideFiles := func(portDir string) error { |
| 531 | entities, err := os.ReadDir(portDir) |
| 532 | if err != nil { |
| 533 | return fmt.Errorf("failed to read port dir: %s", portDir) |
| 534 | } |
| 535 | for _, entity := range entities { |
| 536 | if entity.Name() != "port.toml" && |
| 537 | entity.Name() != "cmake_config.toml" && |
| 538 | entity.Name() != "README.md" && |
| 539 | !strings.Contains(entity.Name(), ".patch") { |
| 540 | srcFile := filepath.Join(portDir, entity.Name()) |
| 541 | destFile := filepath.Join(b.PortConfig.SrcDir, entity.Name()) |
| 542 | if !fileio.PathExists(destFile) { |
| 543 | if err := fileio.CopyFile(srcFile, destFile); err != nil { |
| 544 | return fmt.Errorf("failed to patch files -> %w", err) |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | } |
| 549 | return nil |
| 550 | } |
| 551 | portDir := filepath.Dir(b.PortConfig.PortFile) |
| 552 | if err := overrideFiles(portDir); err != nil { |
| 553 | return fmt.Errorf("failed to override files from port dir -> %w", err) |
| 554 | } |
| 555 | if err := overrideFiles(portDir); err != nil { |
| 556 | return fmt.Errorf("failed to override files from project port dir -> %w", err) |
| 557 | } |
| 558 | |
| 559 | return nil |
| 560 | } |
| 561 | |
| 562 | func (b BuildConfig) UpdateSubmodules() error { |
nothing calls this directly
no test coverage detected