mirror of
https://github.com/clearlinux/mixer-tools.git
synced 2026-09-04 12:41:37 +00:00
Fixes #391 This patch greatly improves code readability by breaking up the goliath builder.go into several new files containing similar functionality. Now builder.go only contains the top-level build functions, constructors, and types. This patch contains no code functionality changes, the code is simply moved around. The builder.go file has been split out as follows: * builder.go: contains all the top-level commands accessible via the commandline, such as BuildBundles, BuildUpdate, BuildImage etc. along with the type and const definitions. * bundle_control.go: contains the mixer bundle * top-level commands and all the helpers that are used only by this functionality. * bundle_validate.go: contains the bundle validation functions. * bundles.go: added getClosestAncestorOwner to this file as it was the only file using this function (plus one reference in builder.go by the top-level BuildBundles). * deltapacks.go: contains the internal function createDeltaPacks used by exported function in builder.go. * repo_control.go: contains the dnf configuration controlling functions such as AddRepo, SetURLRepo, etc. Ideally this will eventually be moved to the config package. * helpers.go: contains generic helper functions used by several files in the builder package. * init.go: contains the functions to initialize the mix via mixer init. * metadata.go: contains various metadata getters and setters for reading and updating versions, formats, and metadata files. * update.go: contains the internal functions used by mixer build update. Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
// Copyright © 2018 Intel Corporation
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package builder
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
|
|
"github.com/clearlinux/mixer-tools/helpers"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// ValidateLocalBundles runs bundle parsing validation on all local bundles.
|
|
func (b *Builder) ValidateLocalBundles(lvl ValidationLevel) error {
|
|
files, err := helpers.ListVisibleFiles(b.Config.Mixer.LocalBundleDir)
|
|
if err != nil {
|
|
return errors.Wrap(err, "Failed to read local-bundles")
|
|
}
|
|
|
|
bundles := make([]string, len(files))
|
|
for i, file := range files {
|
|
bundles[i] = file
|
|
}
|
|
|
|
return b.ValidateBundles(bundles, lvl)
|
|
}
|
|
|
|
// ValidateBundles runs bundle parsing validation on a list of local bundles. In
|
|
// addition to parsing errors, errors are generated if the bundle is not found
|
|
// in local-bundles.
|
|
func (b *Builder) ValidateBundles(bundles []string, lvl ValidationLevel) error {
|
|
invalid := false
|
|
for _, bundle := range bundles {
|
|
path := filepath.Join(b.Config.Mixer.LocalBundleDir, bundle)
|
|
|
|
if err := validateBundleFile(path, lvl); err != nil {
|
|
invalid = true
|
|
fmt.Printf("Invalid: %q:\n%s\n\n", bundle, err)
|
|
}
|
|
}
|
|
|
|
if invalid {
|
|
return errors.New("Invalid bundles found")
|
|
}
|
|
|
|
return nil
|
|
}
|