1 // Copyright 2020, 2021, 2021 Google LLC 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 // https://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 15 package runfiles 16 17 import "path/filepath" 18 19 // Directory specifies the location of the runfiles directory. You can pass 20 // this as an option to New. If unset or empty, use the value of the 21 // environmental variable RUNFILES_DIR. 22 type Directory string 23 24 func (d Directory) new(sourceRepo SourceRepo) (*Runfiles, error) { 25 r := &Runfiles{ 26 impl: d, 27 env: []string{ 28 directoryVar + "=" + string(d), 29 legacyDirectoryVar + "=" + string(d), 30 }, 31 sourceRepo: string(sourceRepo), 32 } 33 err := r.loadRepoMapping() 34 return r, err 35 } 36 37 func (d Directory) path(s string) (string, error) { 38 return filepath.Join(string(d), filepath.FromSlash(s)), nil 39 } 40