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 15package runfiles 16 17import "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. 22type Directory string 23 24func (d Directory) new(sourceRepo SourceRepo) (*Runfiles, error) { 25 r := &Runfiles{ 26 impl: d, 27 env: directoryVar + "=" + string(d), 28 sourceRepo: string(sourceRepo), 29 } 30 err := r.loadRepoMapping() 31 return r, err 32} 33 34func (d Directory) path(s string) (string, error) { 35 return filepath.Join(string(d), filepath.FromSlash(s)), nil 36} 37