diff options
author | Danna Kelmer <dannark@google.com> | 2018-07-16 09:13:09 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-07-16 09:14:25 -0700 |
commit | 3149beb6543c50f381f91f9645f2a4da43d20c0c (patch) | |
tree | 941d788d6d52cb9dab7ab39ecabc544b3f89974d /src/main/java/com/google/devtools/build | |
parent | 7e703eca32b834edc677a926c2d440e49ffdadc2 (diff) |
Add implicit mapping from "@mainrepo" to "@". This fixes the issue where referencing the main repository using its name caused bazel to treat it as a separate external repository.
Closes #5586.
Fixes #3115.
RELNOTES: None
PiperOrigin-RevId: 204752150
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java index 0837b823f4..6cc7ddfffe 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java +++ b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java @@ -18,6 +18,7 @@ import static com.google.devtools.build.lib.syntax.Runtime.NONE; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; +import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.cmdline.Label; @@ -301,18 +302,17 @@ public class WorkspaceFactory { } @SkylarkSignature( - name = "workspace", - objectType = Object.class, - returnType = SkylarkList.class, - doc = - "Sets the name for this workspace. Workspace names should be a Java-package-style " - + "description of the project, using underscores as separators, e.g., " - + "github.com/bazelbuild/bazel should use com_github_bazelbuild_bazel. Names must " - + "start with a letter and can only contain letters, numbers, and underscores.", - parameters = {@Param(name = "name", type = String.class, doc = "the name of the workspace.")}, - useAst = true, - useEnvironment = true - ) + name = "workspace", + objectType = Object.class, + returnType = SkylarkList.class, + doc = + "Sets the name for this workspace. Workspace names should be a Java-package-style " + + "description of the project, using underscores as separators, e.g., " + + "github.com/bazelbuild/bazel should use com_github_bazelbuild_bazel. Names must " + + "start with a letter and can only contain letters, numbers, and underscores.", + parameters = {@Param(name = "name", type = String.class, doc = "the name of the workspace.")}, + useAst = true, + useEnvironment = true) private static final BuiltinFunction.Factory newWorkspaceFunction = new BuiltinFunction.Factory("workspace") { public BuiltinFunction create(boolean allowOverride, final RuleFactory ruleFactory) { @@ -344,6 +344,12 @@ public class WorkspaceFactory { } catch (InvalidRuleException | NameConflictException | LabelSyntaxException e) { throw new EvalException(ast.getLocation(), e.getMessage()); } + // Add entry in repository map from "@name" --> "@" to avoid issue where bazel + // treats references to @name as a separate external repo + builder.addRepositoryMappingEntry( + RepositoryName.MAIN, + RepositoryName.createFromValidStrippedName(name), + RepositoryName.MAIN); return NONE; } }; @@ -488,17 +494,27 @@ public class WorkspaceFactory { + kwargs.get("name") + "')"); } + String externalRepoName = (String) kwargs.get("name"); + // Add an entry in every repository from @<mainRepoName> to "@" to avoid treating + // @<mainRepoName> as a separate repository. This will be overridden if the main + // repository has a repo_mapping entry from <mainRepoName> to something. + if (!Strings.isNullOrEmpty(builder.pkg.getWorkspaceName())) { + builder.addRepositoryMappingEntry( + RepositoryName.createFromValidStrippedName(externalRepoName), + RepositoryName.createFromValidStrippedName(builder.pkg.getWorkspaceName()), + RepositoryName.MAIN); + } if (env.getSemantics().experimentalEnableRepoMapping()) { if (kwargs.containsKey("repo_mapping")) { if (!(kwargs.get("repo_mapping") instanceof Map)) { throw new EvalException( ast.getLocation(), - "Invalid value for 'repo_mapping': '" + kwargs.get("repo_mapping") + "Invalid value for 'repo_mapping': '" + + kwargs.get("repo_mapping") + "'. Value must be a map."); } @SuppressWarnings("unchecked") Map<String, String> map = (Map<String, String>) kwargs.get("repo_mapping"); - String externalRepoName = (String) kwargs.get("name"); for (Map.Entry<String, String> e : map.entrySet()) { builder.addRepositoryMappingEntry( RepositoryName.createFromValidStrippedName(externalRepoName), |