blob: 1796d497b9c9e6d6e3efb8c8fc5e0d50d16f1386 [file] [log] [blame]
// Copyright (C) 2016 The Android Open Source Project
//
// 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 pkgdata
import (
"fmt"
"android.googlesource.com/platform/tools/gpu/framework/device"
"android.googlesource.com/platform/tools/gpu/framework/file"
"android.googlesource.com/platform/tools/gpu/framework/log"
)
type fileLayout interface {
File(ctx log.Context, abi device.ABI, name string) (file.Path, error)
Strings(ctx log.Context) (file.Path, error)
}
var packageOSToDir = map[device.OSKind]string{
device.UnknownOS: "unknown",
device.Windows: "win32",
device.OSX: "darwin",
device.Linux: "linux",
device.Android: "android",
}
var pkgABIToDir = map[device.Architecture]string{
device.ARMv7a: "armeabi-v7a",
device.ARMv8a: "arm64-v8a",
device.X86: "x86",
device.X86_64: "x86_64",
}
// pkgLayout is the file layout used when running executables from a packaged
// build.
type pkgLayout struct {
root file.Path
}
func (l pkgLayout) File(ctx log.Context, abi device.ABI, name string) (file.Path, error) {
return l.root.Join(packageOSToDir[abi.OS], pkgABIToDir[abi.Architecture], name), nil
}
func (l pkgLayout) Strings(ctx log.Context) (file.Path, error) {
return l.root.Join("strings", "en-us.stb"), nil
}
var binABIToDir = map[string]string{
"armeabi": "android-armv7a",
"armeabi-v7a": "android-armv7a",
"arm64-v8a": "android-armv8a",
"x86": "android-x86",
}
// binLayout is the file layout used when running executables from the build's
// bin directory.
type binLayout struct {
root file.Path
}
func abiDirectory(ctx log.Context, abi device.ABI) (string, error) {
dir, ok := binABIToDir[abi.Name]
if !ok {
return "", ctx.AsErrorf("Unknown device ABI: %+v", abi)
}
return dir, nil
}
func (l binLayout) File(ctx log.Context, abi device.ABI, name string) (file.Path, error) {
if abi.OS == device.Host(ctx).Configuration.OS.Kind {
return l.root.Join(name), nil
}
dir, err := abiDirectory(ctx, abi)
if err != nil {
return file.Path{}, err
}
return l.root.Join(dir, name), nil
}
func (l binLayout) Strings(ctx log.Context) (file.Path, error) {
return l.root.Join("strings", "en-us.stb"), nil
}
// unknownLayout is the file layout used when no other layout can be discovered.
// All methods will return an error.
type unknownLayout struct{}
func (l unknownLayout) File(ctx log.Context, abi device.ABI, name string) (file.Path, error) {
return file.Path{}, fmt.Errorf("Cannot find package files")
}
func (l unknownLayout) Strings(ctx log.Context) (file.Path, error) {
return file.Path{}, fmt.Errorf("Cannot find package files")
}