Build in /tmp and immediately discard
This commit is contained in:
@@ -66,6 +66,11 @@ type hakChunk struct {
|
||||
|
||||
type ProgressFunc func(string)
|
||||
|
||||
type BuildHAKOptions struct {
|
||||
Progress ProgressFunc
|
||||
ArchiveNames []string
|
||||
}
|
||||
|
||||
func Build(p *project.Project) (BuildResult, error) {
|
||||
var topPackage topdata.PackageResult
|
||||
var err error
|
||||
@@ -145,6 +150,10 @@ func BuildHAKsWithProgress(p *project.Project, progress ProgressFunc) (BuildResu
|
||||
return buildHAKs(p, progress)
|
||||
}
|
||||
|
||||
func BuildHAKsWithOptions(p *project.Project, opts BuildHAKOptions) (BuildResult, error) {
|
||||
return planOrBuildHAKs(p, opts.Progress, true, opts.ArchiveNames)
|
||||
}
|
||||
|
||||
func PlanHAKs(p *project.Project) (BuildResult, error) {
|
||||
return planHAKs(p, nil)
|
||||
}
|
||||
@@ -154,14 +163,14 @@ func PlanHAKsWithProgress(p *project.Project, progress ProgressFunc) (BuildResul
|
||||
}
|
||||
|
||||
func buildHAKs(p *project.Project, progress ProgressFunc) (BuildResult, error) {
|
||||
return planOrBuildHAKs(p, progress, true)
|
||||
return planOrBuildHAKs(p, progress, true, nil)
|
||||
}
|
||||
|
||||
func planHAKs(p *project.Project, progress ProgressFunc) (BuildResult, error) {
|
||||
return planOrBuildHAKs(p, progress, false)
|
||||
return planOrBuildHAKs(p, progress, false, nil)
|
||||
}
|
||||
|
||||
func planOrBuildHAKs(p *project.Project, progress ProgressFunc, writeArchives bool) (BuildResult, error) {
|
||||
func planOrBuildHAKs(p *project.Project, progress ProgressFunc, writeArchives bool, archiveNames []string) (BuildResult, error) {
|
||||
preserveExistingHAKs := envBool("SOW_BUILD_HAKS_KEEP_EXISTING")
|
||||
|
||||
progressf(progress, "Validating project...")
|
||||
@@ -189,6 +198,10 @@ func planOrBuildHAKs(p *project.Project, progress ProgressFunc, writeArchives bo
|
||||
if err != nil {
|
||||
return BuildResult{}, err
|
||||
}
|
||||
chunks, err = filterHAKChunksByName(chunks, archiveNames)
|
||||
if err != nil {
|
||||
return BuildResult{}, err
|
||||
}
|
||||
progressf(progress, "Resolving module HAK order...")
|
||||
moduleHakOrder, err := resolveModuleHAKOrder(p, chunks)
|
||||
if err != nil {
|
||||
@@ -274,6 +287,50 @@ func planOrBuildHAKs(p *project.Project, progress ProgressFunc, writeArchives bo
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func filterHAKChunksByName(chunks []hakChunk, archiveNames []string) ([]hakChunk, error) {
|
||||
if len(archiveNames) == 0 {
|
||||
return chunks, nil
|
||||
}
|
||||
|
||||
wanted := make(map[string]struct{}, len(archiveNames))
|
||||
for _, name := range archiveNames {
|
||||
trimmed := strings.TrimSpace(strings.ToLower(name))
|
||||
if trimmed == "" {
|
||||
continue
|
||||
}
|
||||
wanted[trimmed] = struct{}{}
|
||||
}
|
||||
if len(wanted) == 0 {
|
||||
return chunks, nil
|
||||
}
|
||||
|
||||
filtered := make([]hakChunk, 0, len(wanted))
|
||||
found := make(map[string]struct{}, len(wanted))
|
||||
for _, chunk := range chunks {
|
||||
key := strings.ToLower(strings.TrimSpace(chunk.Name))
|
||||
if _, ok := wanted[key]; !ok {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, chunk)
|
||||
found[key] = struct{}{}
|
||||
}
|
||||
|
||||
var missing []string
|
||||
for _, name := range archiveNames {
|
||||
key := strings.TrimSpace(strings.ToLower(name))
|
||||
if key == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := found[key]; !ok {
|
||||
missing = append(missing, name)
|
||||
}
|
||||
}
|
||||
if len(missing) > 0 {
|
||||
return nil, fmt.Errorf("unknown hak archive(s): %s", strings.Join(missing, ", "))
|
||||
}
|
||||
return filtered, nil
|
||||
}
|
||||
|
||||
func progressf(progress ProgressFunc, message string) {
|
||||
if progress != nil {
|
||||
progress(message)
|
||||
|
||||
Reference in New Issue
Block a user