-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
================ * `TargetPattern#renameRepository` is merged into `TargetPattern.Parser#parse`. This is much less error-prone -- repo mapping should not be an afterthought, but something that should always be applied if possible (sometimes it's not, for example for `blaze query`). * This also fixes the bug where calling `native.register_toolchains("//:all")` in `@some_repo//:defs.bzl` registers `@//:all` instead of `@some_repo//:all` (see change in RegisteredExecutionPlatformsTest) * A new class `SignedTargetPattern` is introduced, which can store whether the pattern is positive or negative (with the `sign` method). * `TargetPatternValue#keys` is greatly simplified thanks to the changes above; the exception throwing is confined to the parsing step, and the construction of `TargetPatternKey` can happen as a separate step, obviating the whole "skykey or exception" dance. * Following from the above, the //external package now stores registered toolchains and execution platforms as parsed target patterns, instead of simple strings. Among other things, this would help implement toolchain registration in bzlmod. PiperOrigin-RevId: 400720457
- Loading branch information
1 parent
d250a23
commit 630be02
Showing
30 changed files
with
444 additions
and
434 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/com/google/devtools/build/lib/cmdline/SignedTargetPattern.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2021 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.build.lib.cmdline; | ||
|
||
import com.google.auto.value.AutoValue; | ||
|
||
/** A {@link TargetPattern} with a potential minus sign in front of it, signifying exclusion. */ | ||
@AutoValue | ||
public abstract class SignedTargetPattern { | ||
public abstract TargetPattern pattern(); | ||
|
||
public abstract Sign sign(); | ||
|
||
public static SignedTargetPattern create(TargetPattern pattern, Sign sign) { | ||
return new AutoValue_SignedTargetPattern(pattern, sign); | ||
} | ||
|
||
/** Whether this target pattern begins with a minus sign (NEGATIVE) or not (POSITIVE). */ | ||
public enum Sign { | ||
POSITIVE, | ||
NEGATIVE | ||
} | ||
|
||
public static SignedTargetPattern parse(String pattern, TargetPattern.Parser parser) | ||
throws TargetParsingException { | ||
if (pattern.startsWith("-")) { | ||
return create(parser.parse(pattern.substring(1)), SignedTargetPattern.Sign.NEGATIVE); | ||
} else { | ||
return create(parser.parse(pattern), SignedTargetPattern.Sign.POSITIVE); | ||
} | ||
} | ||
} |
Oops, something went wrong.