mirror of https://github.com/bazelbuild/rules_cc
Fix paths resolving for --crosstool and --output_location.
This is to make the script usable from bazel run PiperOrigin-RevId: 232472300
This commit is contained in:
parent
ba06942f95
commit
1576db8e94
|
@ -17,6 +17,9 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/user"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"log"
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
@ -32,17 +35,45 @@ var (
|
|||
"output_location", "", "Location of the output .bzl file")
|
||||
)
|
||||
|
||||
func toAbsolutePath(pathString string) (string, error) {
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
homeDir := usr.HomeDir
|
||||
|
||||
if strings.HasPrefix(pathString, "~") {
|
||||
return path.Join(homeDir, pathString[1:]), nil
|
||||
}
|
||||
|
||||
if path.IsAbs(pathString) {
|
||||
return pathString, nil
|
||||
}
|
||||
|
||||
workingDirectory := os.Getenv("BUILD_WORKING_DIRECTORY")
|
||||
return path.Join(workingDirectory, pathString), nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
if *crosstoolLocation == "" {
|
||||
log.Fatalf("Missing mandatory argument 'crosstool'")
|
||||
}
|
||||
crosstoolPath, err := toAbsolutePath(*crosstoolLocation)
|
||||
if err != nil {
|
||||
log.Fatalf("Error while resolving CROSSTOOL location:", err)
|
||||
}
|
||||
|
||||
if *outputLocation == "" {
|
||||
log.Fatalf("Missing mandatory argument 'output_location'")
|
||||
}
|
||||
outputPath, err := toAbsolutePath(*outputLocation)
|
||||
if err != nil {
|
||||
log.Fatalf("Error resolving output location:", err)
|
||||
}
|
||||
|
||||
in, err := ioutil.ReadFile(*crosstoolLocation)
|
||||
in, err := ioutil.ReadFile(crosstoolPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error reading CROSSTOOL file:", err)
|
||||
}
|
||||
|
@ -51,7 +82,7 @@ func main() {
|
|||
log.Fatalf("Failed to parse CROSSTOOL:", err)
|
||||
}
|
||||
|
||||
file, err := os.Create(*outputLocation)
|
||||
file, err := os.Create(outputPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error creating output file:", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue