-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exporter: allow to specify the path to ccache
Signed-off-by: VirtualTam <[email protected]>
- Loading branch information
1 parent
7c6cc9d
commit 40e62a1
Showing
3 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2018 VirtualTam. | ||
// Use of this source code is governed by a MIT license | ||
// that can be found in the LICENSE file. | ||
|
||
package ccache | ||
|
||
import "os/exec" | ||
|
||
const ( | ||
DefaultBinaryPath = "/usr/bin/ccache" | ||
) | ||
|
||
// Wrapper exposes supported ccache commands. | ||
type Wrapper interface { | ||
ShowStats() (string, error) | ||
Version() (string, error) | ||
} | ||
|
||
// BinaryWrapper runs ccache commands locally. | ||
type BinaryWrapper struct { | ||
path string | ||
} | ||
|
||
func (w *BinaryWrapper) exec(option string) (string, error) { | ||
out, err := exec.Command(w.path, option).Output() | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return string(out[:]), nil | ||
} | ||
|
||
// ShowStats returns the result of ``ccache --show-stats''. | ||
func (w *BinaryWrapper) ShowStats() (string, error) { | ||
return w.exec("--show-stats") | ||
} | ||
|
||
// Version returns the result of ``ccache --version''. | ||
func (w *BinaryWrapper) Version() (string, error) { | ||
return w.exec("--version") | ||
} | ||
|
||
// NewBinaryWrapper ensures the ccache executable exists and can be invoked, and | ||
// returns an initialized BinaryWrapper. | ||
func NewBinaryWrapper(path string) (*BinaryWrapper, error) { | ||
err := exec.Command(path, "-s").Run() | ||
if err != nil { | ||
return &BinaryWrapper{}, err | ||
} | ||
|
||
return &BinaryWrapper{path: path}, nil | ||
} |