| package dkms | |
| import ( | |
| "fmt" | |
| "path" | |
| "cos.googlesource.com/cos/tools.git/src/pkg/modules" | |
| ) | |
| // PackageStatus is an enum representing the different possible states for a package. | |
| // A package can be Added, Built, Installed, or Broken. See the IsAdded, IsBuilt, etc., | |
| // functions for more detail. | |
| type PackageStatus int | |
| const ( | |
| Broken PackageStatus = iota | |
| Added | |
| Built | |
| Installed | |
| ) | |
| // Trees is the collection of directories which DKMS will use as the root paths for | |
| // adding, compiling, and installing packages. | |
| type Trees struct { | |
| // The path to the DKMS tree, where package sources will be copied and package | |
| // build directories will be maintained. | |
| Dkms string | |
| // The path to the install tree where packages will be installed. | |
| Install string | |
| // The path to the user source tree from which package sources will be copied | |
| // into the DKMS tree. | |
| Source string | |
| // The path to the kernel source directory which will be used for compiling | |
| // the modules within a package. | |
| Kernel string | |
| // The path to the directory where compiled (possibly read-only) kernel modules are | |
| // stored. This is separate from the install tree because the built-in kernel modules | |
| // tree in COS is read-only. | |
| KernelModules string | |
| } | |
| // A Package contains the information necessary to manage a collection of kernel modules. | |
| // Specifically, a Package has all of the fields required for constructing the paths | |
| // required to perform DKMS operations on that package, such as compiling and installing | |
| // modules. | |
| type Package struct { | |
| // These fields disambiguate which package is being referred to. | |
| // For instance, two packages with the same source code but which have been compiled | |
| // for different kernel versions are considered different and will have different | |
| // corresponding paths within the DKMS tree. | |
| Name string | |
| Version string | |
| Arch string | |
| KernelVersion string | |
| BuildId string | |
| Board string | |
| // This is the set of parameters to pass when inserting modules. Each module can | |
| // have its own list of params of the form param1=value1. | |
| ModuleParams modules.ModuleParameters | |
| // This is the collection of trees which will be used as the base directories | |
| // for the paths related to this package. | |
| Trees *Trees | |
| // This is the configuration for the package, as specified in its dkms.conf. | |
| Config *Config | |
| } | |
| // SourceTreeDir returns the path to the package within the user's source tree. | |
| func (pkg *Package) SourceTreeDir() string { | |
| return path.Join(pkg.Trees.Source, fmt.Sprintf("%s-%s", pkg.Name, pkg.Version)) | |
| } | |
| // Path returns the disambiguated path to the package within the DKMS tree. | |
| func (pkg *Package) Path() string { | |
| return path.Join(pkg.Name, pkg.Version, pkg.KernelVersion, pkg.Arch, pkg.BuildId, pkg.Board) | |
| } | |
| // SourceDir returns the path to the package sources within the DKMS tree. | |
| func (pkg *Package) SourceDir() string { | |
| return path.Join(pkg.Trees.Dkms, pkg.Path(), "source") | |
| } | |
| // CacheSourceDir returns the path to the package sources within the cache DKMS tree. | |
| func (pkg *Package) CacheSourceDir() string { | |
| return path.Join(pkg.Path(), "source") | |
| } | |
| // BuildDir returns the path to the package build directory within the DKMS tree. | |
| func (pkg *Package) BuildDir() string { | |
| return path.Join(pkg.Trees.Dkms, pkg.Path(), "build") | |
| } | |
| // CacheBuildDir returns the path to the package build directory within the cache DKMS tree. | |
| func (pkg *Package) CacheBuildDir() string { | |
| return path.Join(pkg.Path(), "build") | |
| } | |
| // ConfigPath returns the path to package's configuration within the DKMS tree. | |
| func (pkg *Package) ConfigPath() string { | |
| return path.Join(pkg.SourceDir(), "dkms.conf") | |
| } | |
| // CacheConfigPath returns the path to package's configuration within the cache DKMS tree. | |
| func (pkg *Package) CacheConfigPath() string { | |
| return path.Join(pkg.CacheSourceDir(), "dkms.conf") | |
| } |