| // 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 scans the running executable's directory structure to find |
| // the relative location of other files to load / shell. |
| package pkgdata |
| |
| import ( |
| "android.googlesource.com/platform/tools/gpu/framework/device" |
| "android.googlesource.com/platform/tools/gpu/framework/file" |
| "android.googlesource.com/platform/tools/gpu/framework/log" |
| ) |
| |
| // resolvedLayout is the data file layout discovered by layout() |
| // Call layout() instead of using this directly. |
| var resolvedLayout fileLayout |
| |
| func layout() (out fileLayout) { |
| if resolvedLayout != nil { |
| return resolvedLayout |
| } |
| defer func() { resolvedLayout = out }() |
| for _, base := range []file.Path{file.ExecutablePath(), file.Abs(".")} { |
| dir := base.Parent() |
| // Check the regular package layout first: |
| // pkg |
| // ├─── source.properties |
| // ├─── strings |
| // │ └─── en-us.stb |
| // ├─── android |
| // │ ├─── arm64-v8a |
| // │ │ ├─── libgapii.so |
| // │ │ ├─── gapir.apk |
| // │ │ ↓ |
| // │ ├─── armeabi-v7a |
| // │ │ ↓ |
| // │ ├─── pkginfo.apk |
| // │ ↓ |
| // ├─── osx |
| // │ └─── x86_64 |
| // │ ├─── gapir |
| // │ ├─── gapis |
| // │ ↓ |
| // ↓ |
| if root := dir.Parent().Parent(); root.Join("source.properties").Exists() { |
| return pkgLayout{root} |
| } |
| // Check bin layout from executable's directory. |
| // bin |
| // ├─── source.properties |
| // ├─── gapir |
| // ├─── gapis |
| // ├─── strings |
| // │ └─── en-us.stb |
| // ├─── android-armv7a |
| // │ ├─── libgapii.so |
| // │ ├─── gapir.apk |
| // │ ↓ |
| // ├─── android-armv8a |
| // │ ↓ |
| // ↓ |
| if dir.Join("android-armv7a").Exists() { |
| return binLayout{dir} |
| } |
| } |
| return unknownLayout{} |
| } |
| |
| // File returns the path to the specified file for the given ABI. |
| func File(ctx log.Context, abi device.ABI, name string) (file.Path, error) { |
| return layout().File(ctx, abi, name) |
| } |
| |
| // Strings returns the path to the binary string table. |
| func Strings(ctx log.Context) (file.Path, error) { |
| return layout().Strings(ctx) |
| } |