func()

in targets/linux/deb/distro/install.go [130:178]


func (d *Config) InstallBuildDeps(sOpt dalec.SourceOpts, spec *dalec.Spec, targetKey string, opts ...llb.ConstraintsOpt) llb.StateOption {
	return func(in llb.State) llb.State {
		buildDeps := spec.GetBuildDeps(targetKey)
		if len(buildDeps) == 0 {
			return in
		}

		depsSpec := &dalec.Spec{
			Name:     spec.Name + "-build-deps",
			Packager: "Dalec",
			Version:  spec.Version,
			Revision: spec.Revision,
			Dependencies: &dalec.PackageDependencies{
				Runtime: buildDeps,
			},
			Description: "Build dependencies for " + spec.Name,
		}

		return in.Async(func(ctx context.Context, in llb.State, c *llb.Constraints) (llb.State, error) {
			opts := append(opts, dalec.ProgressGroup("Install build dependencies"))
			opts = append([]llb.ConstraintsOpt{dalec.WithConstraint(c)}, opts...)

			debRoot, err := deb.Debroot(ctx, sOpt, depsSpec, in, llb.Scratch(), targetKey, "", d.VersionID, deb.SourcePkgConfig{}, opts...)
			if err != nil {
				return in, err
			}

			pkg, err := deb.BuildDebBinaryOnly(in, depsSpec, debRoot, "", opts...)
			if err != nil {
				return in, errors.Wrap(err, "error creating intermediate package for installing build dependencies")
			}

			repos := dalec.GetExtraRepos(d.ExtraRepos, "build")
			repos = append(repos, spec.GetBuildRepos(targetKey)...)

			customRepos, err := d.RepoMounts(repos, sOpt, opts...)
			if err != nil {
				return in, err
			}

			return in.Run(
				dalec.WithConstraints(opts...),
				customRepos,
				InstallLocalPkg(pkg, false, opts...),
				dalec.WithMountedAptCache(d.AptCachePrefix),
			).Root(), nil
		})
	}
}