You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3 KiB

  1. package config
  2. import (
  3. "gerrit.wikimedia.org/r/blubber/build"
  4. )
  5. // BuilderConfig contains configuration for the definition of an arbitrary
  6. // build command and the files required to successfully execute the command.
  7. //
  8. type BuilderConfig struct {
  9. Command []string `json:"command"`
  10. Requirements []string `json:"requirements"`
  11. }
  12. // Merge takes another BuilderConfig and merges its fields into this one's,
  13. // overwriting the builder command.
  14. //
  15. func (bc *BuilderConfig) Merge(bc2 BuilderConfig) {
  16. if bc2.Command != nil {
  17. bc.Command = bc2.Command
  18. }
  19. if bc2.Requirements != nil {
  20. bc.Requirements = bc2.Requirements
  21. }
  22. }
  23. // InstructionsForPhase injects instructions into the build related to
  24. // builder commands and required files.
  25. //
  26. // PhasePreInstall
  27. //
  28. // Creates directories for requirements files, copies in requirements files,
  29. // and runs the builder command.
  30. //
  31. func (bc BuilderConfig) InstructionsForPhase(phase build.Phase) []build.Instruction {
  32. if len(bc.Command) == 0 {
  33. return []build.Instruction{}
  34. }
  35. switch phase {
  36. case build.PhasePreInstall:
  37. syncs := build.SyncFiles(bc.Requirements, ".")
  38. run := build.Run{Command: bc.Command[0]}
  39. if len(bc.Command) > 1 {
  40. run.Arguments = bc.Command[1:]
  41. }
  42. return append(syncs, run)
  43. }
  44. return []build.Instruction{}
  45. }