-
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.
Provide transitive digest of bzl files for each Starlark Module.
Replace the optional label in Module with a context object, storing arbitrary additional data. The context will still carry a label which can be used to enhance the information provided by the repr, but also allows to store more information, useful outside of Starlark interpreter. An example of this is the transitive hash of the bzl files loaded by the module, which is not relevant to Starlark itself, but is important in Bazel. Move the concept of bzlTransitiveDigest from BazelStarlakContext (associated with the thread) to new BazelModuleContext, which is added to the Starlark module. The concept of the transitive digest makes most sense at the level of the module -- it means the `digest({bzl \in transitively_loaded(module)})`. After this change, we rely on picking appropriate module to get the digest from rather than the data associated with the StarlarkThread. One of the uses of the bzlTransitiveDigest is adding a digest for RuleClass instances. After this change, we explicitly use the hash of the module which defines the RuleClass itself. PiperOrigin-RevId: 311173293
- Loading branch information
1 parent
60b2eaf
commit 9f2cab5
Showing
20 changed files
with
147 additions
and
123 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
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
51 changes: 51 additions & 0 deletions
51
src/main/java/com/google/devtools/build/lib/packages/BazelModuleContext.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,51 @@ | ||
// Copyright 2020 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.packages; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import com.google.devtools.build.lib.cmdline.Label; | ||
|
||
/** | ||
* BazelModuleContext records Bazel-specific information associated with a .bzl {@link | ||
* com.google.devtools.build.lib.syntax.Module}. | ||
*/ | ||
@AutoValue | ||
public abstract class BazelModuleContext { | ||
/** Label associated with the Starlark {@link com.google.devtools.build.lib.syntax.Module}. */ | ||
public abstract Label label(); | ||
|
||
/** | ||
* Transitive digest of the .bzl file of the {@link com.google.devtools.build.lib.syntax.Module} | ||
* itself and all files it transitively loads. | ||
*/ | ||
@SuppressWarnings("AutoValueImmutableFields") | ||
public abstract byte[] bzlTransitiveDigest(); | ||
|
||
/** | ||
* Returns a label for a {@link com.google.devtools.build.lib.syntax.Module}. | ||
* | ||
* <p>This is a user-facing value and we rely on this string to be a valid label for the {@link | ||
* com.google.devtools.build.lib.syntax.Module} (and that only). Please see the documentation of | ||
* {@link com.google.devtools.build.lib.syntax.Module#withClientData(Object)} for more details. | ||
*/ | ||
@Override | ||
public final String toString() { | ||
return label().toString(); | ||
} | ||
|
||
public static BazelModuleContext create(Label label, byte[] bzlTransitiveDigest) { | ||
return new AutoValue_BazelModuleContext(label, bzlTransitiveDigest); | ||
} | ||
} |
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
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
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
Oops, something went wrong.