Skip to content

Commit

Permalink
don't recheck runtime architecture
Browse files Browse the repository at this point in the history
This patch reduces the number of calls to the OS's `arch` to one.
There's a good chance that the CPU architecture doesn't change while the
program is running.
  • Loading branch information
mkisielewski-arista authored and aajith-arista committed Dec 6, 2024
1 parent d44b6fd commit bfcb9d1
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var buildCmd = &cobra.Command{
extraMockArgs := impl.MockExtraCmdlineArgs{
NoCheck: noCheck,
}
return impl.Build(repo, pkg, defaultArch(), extraCreateSrpmArgs, extraMockArgs)
return impl.Build(repo, pkg, defaultArch, extraCreateSrpmArgs, extraMockArgs)
},
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"strings"
)

func defaultArch() string {
var defaultArch = func() string {
var output []byte
var err error
if output, err = exec.Command("arch").Output(); err != nil {
panic(err)
}
return strings.TrimRight(string(output), "\n")
}
}()

// SetViperDefaults sets defaults for viper configs
func SetViperDefaults() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var mockCmd = &cobra.Command{
func init() {
mockCmd.Flags().StringP("repo", "r", "", "Repository name (OPTIONAL)")
mockCmd.Flags().StringP("package", "p", "", "package name (OPTIONAL)")
mockCmd.Flags().StringP("target", "t", defaultArch(), "target architecture for the rpmbuild (OPTIONAL)")
mockCmd.Flags().StringP("target", "t", defaultArch, "target architecture for the rpmbuild (OPTIONAL)")
mockCmd.Flags().Bool("only-create-cfg", false, "Just create mock configuration, don't run mock (OPTIONAL)")
mockCmd.Flags().Bool("nocheck", false, "Pass --nocheck to rpmbuild (OPTIONAL)")
rootCmd.AddCommand(mockCmd)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func runMockAndVerify(t *testing.T, destDir string,
quiet bool,
expectedFiles []ExpectedRpmFile,
expectedTags map[string]string) {
args := []string{"mock", "--target", defaultArch(), "--repo", repoName}
args := []string{"mock", "--target", defaultArch, "--repo", repoName}
testutil.RunCmd(t, rootCmd, args, quiet, true)
for _, expectedFile := range expectedFiles {
fileAbsPath := filepath.Join(destDir, "RPMS",
Expand Down

0 comments on commit bfcb9d1

Please sign in to comment.