github.com/bazelbuild/rules_webtesting@v0.2.0/web/internal/files.bzl (about) 1 # Copyright 2016 Google Inc. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 """A library of functions for working with runfiles.""" 15 16 def _long_path(ctx, file): 17 """Constructs a path relative to TEST_SRCDIR for accessing the file. 18 19 Args: 20 ctx: a Skylark rule context. 21 file: a File object. The file should appear in the runfiles for the 22 test. 23 24 Returns: 25 A string path relative to TEST_SRCDIR suitable for use in tests and 26 testing infrastructure. 27 """ 28 if file.short_path[:3] == "../": 29 # sometimes a file"s short_path is ../<workspace_root>/<file_path> 30 # then we just need to trim the ../ 31 return file.short_path[3:] 32 if file.owner and file.owner.workspace_root: 33 # if the file has an owner and that owner has a workspace_root, 34 # prepend it. 35 return (file.owner.workspace_root + "/" + file.short_path) 36 37 # otherwise assume the file is in the same workspace as the current rule. 38 39 return (ctx.workspace_name + "/" + file.short_path) 40 41 files = struct(long_path = _long_path)