|  | 
| 13 | 13 | // limitations under the License. | 
| 14 | 14 | package com.google.devtools.build.lib.runtime; | 
| 15 | 15 | 
 | 
|  | 16 | +import com.google.common.annotations.VisibleForTesting; | 
| 16 | 17 | import com.google.common.base.Preconditions; | 
| 17 | 18 | import com.google.common.base.Splitter; | 
| 18 | 19 | import com.google.common.base.Strings; | 
| 19 | 20 | import com.google.common.collect.ImmutableMap; | 
|  | 21 | +import com.google.devtools.build.lib.analysis.BlazeDirectories; | 
| 20 | 22 | import com.google.devtools.build.lib.vfs.FileSystem; | 
| 21 | 23 | import com.google.devtools.build.lib.vfs.Path; | 
| 22 | 24 | import com.google.devtools.build.lib.vfs.PathFragment; | 
| @@ -44,11 +46,27 @@ public final class CommandLinePathFactory { | 
| 44 | 46 |   private final FileSystem fileSystem; | 
| 45 | 47 |   private final ImmutableMap<String, Path> roots; | 
| 46 | 48 | 
 | 
|  | 49 | +  @VisibleForTesting | 
| 47 | 50 |   public CommandLinePathFactory(FileSystem fileSystem, ImmutableMap<String, Path> roots) { | 
| 48 | 51 |     this.fileSystem = Preconditions.checkNotNull(fileSystem); | 
| 49 | 52 |     this.roots = Preconditions.checkNotNull(roots); | 
| 50 | 53 |   } | 
| 51 | 54 | 
 | 
|  | 55 | +  static CommandLinePathFactory create(FileSystem fileSystem, BlazeDirectories directories) { | 
|  | 56 | +    Preconditions.checkNotNull(fileSystem); | 
|  | 57 | +    Preconditions.checkNotNull(directories); | 
|  | 58 | + | 
|  | 59 | +    ImmutableMap.Builder<String, Path> wellKnownRoots = ImmutableMap.builder(); | 
|  | 60 | + | 
|  | 61 | +    // This is necessary because some tests don't have a workspace set. | 
|  | 62 | +    Path workspace = directories.getWorkspace(); | 
|  | 63 | +    if (workspace != null) { | 
|  | 64 | +      wellKnownRoots.put("workspace", workspace); | 
|  | 65 | +    } | 
|  | 66 | + | 
|  | 67 | +    return new CommandLinePathFactory(fileSystem, wellKnownRoots.build()); | 
|  | 68 | +  } | 
|  | 69 | + | 
| 52 | 70 |   /** Creates a {@link Path}. */ | 
| 53 | 71 |   public Path create(Map<String, String> env, String value) throws IOException { | 
| 54 | 72 |     Preconditions.checkNotNull(env); | 
|  | 
0 commit comments