Rename some PackageId and RepositoryName fields/methods in prep for deep execroot change
This is in prep for making the execution root path for external repositories
../repo_name (instead of external/repo_name). Right now, the getRunfilesPath() returns that path, so that is renamed getExecRoot() (since the runfiles are really just a reflection of the execRoot structure). getSourceRoot() replaces getPathFragment, which has always been a confusing name (it's not clear from the name
what the difference is between it and getPackageFragment()). It returns the relative path to source files for external repositories (external/repo_name).
Also renamed/moved to more sensible class a few static RepositoryName fields.
--
MOS_MIGRATED_REVID=128594419
diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java b/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
index 6445f48..a20ea18 100644
--- a/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
+++ b/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
@@ -47,27 +47,15 @@
return INTERNER.intern(new PackageIdentifier(repository, pkgName));
}
- public static final String DEFAULT_REPOSITORY = "";
- public static final RepositoryName DEFAULT_REPOSITORY_NAME;
- public static final RepositoryName MAIN_REPOSITORY_NAME;
- public static final PackageIdentifier EMPTY_PACKAGE_ID;
-
- static {
- try {
- DEFAULT_REPOSITORY_NAME = RepositoryName.create(DEFAULT_REPOSITORY);
- MAIN_REPOSITORY_NAME = RepositoryName.create("@");
- EMPTY_PACKAGE_ID = createInMainRepo(PathFragment.EMPTY_FRAGMENT);
- } catch (LabelSyntaxException e) {
- throw new IllegalStateException(e);
- }
- }
+ public static final PackageIdentifier EMPTY_PACKAGE_ID = createInMainRepo(
+ PathFragment.EMPTY_FRAGMENT);
public static PackageIdentifier createInMainRepo(String name) {
return createInMainRepo(new PathFragment(name));
}
public static PackageIdentifier createInMainRepo(PathFragment name) {
- return create(MAIN_REPOSITORY_NAME, name);
+ return create(RepositoryName.MAIN, name);
}
/**
@@ -99,10 +87,10 @@
} else if (input.startsWith("@")) {
throw new LabelSyntaxException("starts with a '@' but does not contain '//'");
} else if (packageStartPos == 0) {
- repo = PackageIdentifier.DEFAULT_REPOSITORY;
+ repo = RepositoryName.DEFAULT_REPOSITORY;
packageName = input.substring(2);
} else {
- repo = PackageIdentifier.DEFAULT_REPOSITORY;
+ repo = RepositoryName.DEFAULT_REPOSITORY;
packageName = input;
}
@@ -128,19 +116,19 @@
}
/**
- * Returns a relative path that should be unique across all remote and packages, based on the
- * repository and package names.
+ * Returns a relative path to the source code for this package. Returns pkgName if this is in the
+ * main repository or external/[repository name]/[pkgName] if not.
*/
- public PathFragment getPathFragment() {
- return repository.getPathFragment().getRelative(pkgName);
+ public PathFragment getSourceRoot() {
+ return repository.getSourceRoot().getRelative(pkgName);
}
/**
- * Returns the runfiles path for this repository (relative to the x.runfiles/main-repo/
+ * Returns the runfiles/execRoot path for this repository (relative to the x.runfiles/main-repo/
* directory).
*/
- public PathFragment getRunfilesPath() {
- return getRepository().getRunfilesPath().getRelative(getPackageFragment());
+ public PathFragment getPathUnderExecRoot() {
+ return getRepository().getPathUnderExecRoot().getRelative(getPackageFragment());
}
public PackageIdentifier makeAbsolute() {
@@ -148,7 +136,7 @@
return this;
}
- return create(MAIN_REPOSITORY_NAME, pkgName);
+ return create(RepositoryName.MAIN, pkgName);
}
/**