Skip to content

Commit

Permalink
bazel packages: rename StarlarkSemanticsOptions -> packages.semantics…
Browse files Browse the repository at this point in the history
….BuildLanguageOptions

It is not a part of lib.packages, but a dependency of it;
some clients (e.g. skydoc) depend on it alone.

FYI: syntax.StarlarkSemantics does not have a code dependency on Bazel, but
it has many logical dependencies on Bazel concepts. Follow-up changes will
make StarlarkSemantics a base class, and define
packages.semantics.BuildLanguageSemantics as a Bazel-specific subclass
containing all Bazelisms.
PiperOrigin-RevId: 330004717
  • Loading branch information
adonovan authored and copybara-github committed Sep 3, 2020
1 parent ece3ec7 commit 240bdea
Show file tree
Hide file tree
Showing 82 changed files with 350 additions and 304 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ filegroup(
"//src/main/java/com/google/devtools/build/lib/network:srcs",
"//src/main/java/com/google/devtools/build/lib/packages:srcs",
"//src/main/java/com/google/devtools/build/lib/packages/metrics:srcs",
"//src/main/java/com/google/devtools/build/lib/packages/semantics:srcs",
"//src/main/java/com/google/devtools/build/lib/pkgcache:srcs",
"//src/main/java/com/google/devtools/build/lib/platform:srcs",
"//src/main/java/com/google/devtools/build/lib/profiler/callcounts:srcs",
Expand Down Expand Up @@ -332,8 +333,8 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/metrics:event",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/packages:build_type",
"//src/main/java/com/google/devtools/build/lib/packages:starlark_semantics_options",
"//src/main/java/com/google/devtools/build/lib/packages:type",
"//src/main/java/com/google/devtools/build/lib/packages/semantics",
"//src/main/java/com/google/devtools/build/lib/pkgcache",
"//src/main/java/com/google/devtools/build/lib/platform:suspend_counter",
"//src/main/java/com/google/devtools/build/lib/profiler",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/concurrent",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/packages:build_type",
"//src/main/java/com/google/devtools/build/lib/packages:starlark_semantics_options",
"//src/main/java/com/google/devtools/build/lib/packages:type",
"//src/main/java/com/google/devtools/build/lib/packages/semantics",
"//src/main/java/com/google/devtools/build/lib/rules/cpp",
"//src/main/java/com/google/devtools/build/lib/skyframe:skyframe_cluster",
"//src/main/java/com/google/devtools/build/lib/skyframe:track_source_directories_flag",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.packages.StarlarkSemanticsOptions;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.rules.cpp.CppIncludeExtractionContext;
import com.google.devtools.build.lib.server.FailureDetails;
import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
Expand Down Expand Up @@ -148,7 +148,7 @@ private void updateInputsFromDepfile(ActionExecutionContext actionExecutionConte
boolean siblingRepositoryLayout =
actionExecutionContext
.getOptions()
.getOptions(StarlarkSemanticsOptions.class)
.getOptions(BuildLanguageOptions.class)
.experimentalSiblingRepositoryLayout;

CppIncludeExtractionContext scanningContext =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
import com.google.devtools.build.lib.buildeventstream.BuildEventProtocolOptions;
import com.google.devtools.build.lib.exec.ExecutionOptions;
import com.google.devtools.build.lib.packages.StarlarkSemanticsOptions;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.pkgcache.LoadingOptions;
import com.google.devtools.build.lib.pkgcache.PackageOptions;
import com.google.devtools.build.lib.runtime.KeepGoingOption;
Expand Down Expand Up @@ -76,7 +76,7 @@ public class BuildRequest implements OptionsProvider {
ImmutableList.of(
BuildRequestOptions.class,
PackageOptions.class,
StarlarkSemanticsOptions.class,
BuildLanguageOptions.class,
LoadingOptions.class,
AnalysisOptions.class,
ExecutionOptions.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
import com.google.devtools.build.lib.exec.SpawnStrategyRegistry;
import com.google.devtools.build.lib.exec.SpawnStrategyResolver;
import com.google.devtools.build.lib.exec.SymlinkTreeStrategy;
import com.google.devtools.build.lib.packages.StarlarkSemanticsOptions;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.profiler.AutoProfiler;
import com.google.devtools.build.lib.profiler.GoogleAutoProfilerUtils;
import com.google.devtools.build.lib.profiler.ProfilePhase;
Expand Down Expand Up @@ -475,8 +475,7 @@ private void prepare(
getExecRoot(),
runtime.getProductName(),
nonSymlinkedDirectoriesUnderExecRoot,
request.getOptions(StarlarkSemanticsOptions.class)
.experimentalSiblingRepositoryLayout);
request.getOptions(BuildLanguageOptions.class).experimentalSiblingRepositoryLayout);
symlinkForest.plantSymlinkForest();
} catch (IOException e) {
throw new AbruptExitException(
Expand Down
15 changes: 1 addition & 14 deletions src/main/java/com/google/devtools/build/lib/packages/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ java_library(
["*.java"],
exclude = TYPE_SRCS + BUILD_TYPE_SRCS + [
"BuilderFactoryForTesting.java",
"StarlarkSemanticsOptions.java",
"BuildLanguageOptions.java",
],
),
deps = [
Expand Down Expand Up @@ -89,19 +89,6 @@ java_library(
],
)

# This class is broken out of lib.packages because skydoc is not supposed to depend on lib.packages.
# TODO(adonovan): rethink skydoc's dependency mess.
java_library(
name = "starlark_semantics_options",
srcs = ["StarlarkSemanticsOptions.java"],
deps = [
"//src/main/java/com/google/devtools/build/lib/concurrent",
"//src/main/java/com/google/devtools/build/lib/syntax:evaluator",
"//src/main/java/com/google/devtools/common/options",
"//third_party:guava",
],
)

java_library(
name = "type",
srcs = TYPE_SRCS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -699,19 +699,18 @@ public String toString() {
public enum ThirdPartyLicenseExistencePolicy {
/**
* Always do this check, overriding whatever {@link
* StarlarkSemanticsOptions#incompatibleDisableThirdPartyLicenseChecking} says.
* BuildLanguageOptions#incompatibleDisableThirdPartyLicenseChecking} says.
*/
ALWAYS_CHECK,

/**
* Never do this check, overriding whatever {@link
* StarlarkSemanticsOptions#incompatibleDisableThirdPartyLicenseChecking} says.
* BuildLanguageOptions#incompatibleDisableThirdPartyLicenseChecking} says.
*/
NEVER_CHECK,

/**
* Do whatever {@link StarlarkSemanticsOptions#incompatibleDisableThirdPartyLicenseChecking}
* says.
* Do whatever {@link BuildLanguageOptions#incompatibleDisableThirdPartyLicenseChecking} says.
*/
USER_CONTROLLABLE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public static Map<String, String> getExecutionInfo(Rule rule) {
* @param rule a rule instance to get tags from
* @param allowTagsPropagation if set to true, tags will be propagated from a target to the
* actions' execution requirements, for more details {@see
* StarlarkSemanticsOptions#experimentalAllowTagsPropagation}
* BuildLanguageOptions#experimentalAllowTagsPropagation}
*/
public static ImmutableMap<String, String> getExecutionInfo(
Rule rule, boolean allowTagsPropagation) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load("@rules_java//java:defs.bzl", "java_library")

package(
default_visibility = ["//src:__subpackages__"],
)

licenses(["notice"])

filegroup(
name = "srcs",
srcs = glob(["*"]),
visibility = ["//src:__subpackages__"],
)

# This package defines the StarlarkSemantics used by Bazel, and its command-line flag parser.
java_library(
name = "semantics",
srcs = ["BuildLanguageOptions.java"],
deps = [
"//src/main/java/com/google/devtools/build/lib/concurrent",
"//src/main/java/com/google/devtools/build/lib/syntax:evaluator",
"//src/main/java/com/google/devtools/common/options",
"//third_party:guava",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
//

package com.google.devtools.build.lib.packages;
package com.google.devtools.build.lib.packages.semantics;

import com.google.common.collect.Interner;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
Expand All @@ -28,7 +28,7 @@
import java.util.List;

/**
* Contains options that affect Starlark's semantics.
* Options that affect the semantics of Bazel's build language.
*
* <p>These are injected into Skyframe (as an instance of {@link StarlarkSemantics}) when a new
* build invocation occurs. Changing these options between builds will therefore trigger a
Expand Down Expand Up @@ -59,7 +59,9 @@
* must be kept consistent; to make it easy we use alphabetic order. The parts that need updating
* are marked with the comment "<== Add new options here in alphabetic order ==>".
*/
public class StarlarkSemanticsOptions extends OptionsBase implements Serializable {
// TODO(adonovan): define "class BuildLanguageSemantics extends StarlarkSemantics"
// and move all Bazelisms into it. See StarlarkSemantics for details.
public class BuildLanguageOptions extends OptionsBase implements Serializable {

// <== Add new options here in alphabetic order ==>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/exec:spawn_strategy_resolver",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/packages:build_type",
"//src/main/java/com/google/devtools/build/lib/packages:starlark_semantics_options",
"//src/main/java/com/google/devtools/build/lib/packages:type",
"//src/main/java/com/google/devtools/build/lib/packages/semantics",
"//src/main/java/com/google/devtools/build/lib/profiler",
"//src/main/java/com/google/devtools/build/lib/rules:alias",
"//src/main/java/com/google/devtools/build/lib/rules/apple",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadCompatible;
import com.google.devtools.build.lib.exec.SpawnStrategyResolver;
import com.google.devtools.build.lib.packages.StarlarkSemanticsOptions;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.profiler.Profiler;
import com.google.devtools.build.lib.profiler.ProfilerTask;
import com.google.devtools.build.lib.profiler.SilentCloseable;
Expand Down Expand Up @@ -564,7 +564,7 @@ public NestedSet<Artifact> discoverInputs(ActionExecutionContext actionExecution
systemIncludeDirs,
actionExecutionContext
.getOptions()
.getOptions(StarlarkSemanticsOptions.class)
.getOptions(BuildLanguageOptions.class)
.experimentalSiblingRepositoryLayout);
}

Expand Down Expand Up @@ -1856,7 +1856,7 @@ public ActionContinuationOrResult execute()
boolean siblingRepositoryLayout =
actionExecutionContext
.getOptions()
.getOptions(StarlarkSemanticsOptions.class)
.getOptions(BuildLanguageOptions.class)
.experimentalSiblingRepositoryLayout;

NestedSet<Artifact> discoveredInputs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
import com.google.devtools.build.lib.packages.StarlarkSemanticsOptions;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.util.ResourceFileLoader;
import com.google.devtools.common.options.OptionsBase;
import com.google.devtools.common.options.OptionsParser;
Expand Down Expand Up @@ -47,7 +47,7 @@ public class BlazeCommandUtils {
ClientOptions.class,
// Starlark options aren't applicable to all commands, but making them a common option
// allows users to put them in the common section of the bazelrc. See issue #3538.
StarlarkSemanticsOptions.class);
BuildLanguageOptions.class);

private BlazeCommandUtils() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.events.Reporter;
import com.google.devtools.build.lib.exec.SingleBuildFileCache;
import com.google.devtools.build.lib.packages.StarlarkSemanticsOptions;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.pkgcache.PackageManager;
import com.google.devtools.build.lib.pkgcache.PackageOptions;
import com.google.devtools.build.lib.pkgcache.PathPackageLocator;
Expand Down Expand Up @@ -669,7 +669,7 @@ public void syncPackageLoading(OptionsProvider options)
reporter,
options.getOptions(PackageOptions.class),
packageLocator,
options.getOptions(StarlarkSemanticsOptions.class),
options.getOptions(BuildLanguageOptions.class),
getCommandId(),
clientEnv,
timestampGranularityMonitor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/cmdline:cmdline-primitives",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/packages:build_type",
"//src/main/java/com/google/devtools/build/lib/packages:starlark_semantics_options",
"//src/main/java/com/google/devtools/build/lib/packages:type",
"//src/main/java/com/google/devtools/build/lib/packages/semantics",
"//src/main/java/com/google/devtools/build/lib/pkgcache",
"//src/main/java/com/google/devtools/build/lib/skyframe:skyframe_cluster",
"//src/main/java/com/google/devtools/build/lib/syntax:evaluator",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import com.google.common.base.Supplier;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.packages.StarlarkSemanticsOptions;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.runtime.CommandEnvironment;
import com.google.devtools.build.lib.runtime.InfoItem;
import com.google.devtools.build.lib.skyframe.SkyframeExecutor;
Expand All @@ -41,8 +41,8 @@ public StarlarkSemanticsInfoItem(OptionsParsingResult commandOptions) {

@Override
public byte[] get(Supplier<BuildConfiguration> configurationSupplier, CommandEnvironment env) {
StarlarkSemanticsOptions starlarkSemanticsOptions =
commandOptions.getOptions(StarlarkSemanticsOptions.class);
BuildLanguageOptions starlarkSemanticsOptions =
commandOptions.getOptions(BuildLanguageOptions.class);
SkyframeExecutor skyframeExecutor = env.getBlazeWorkspace().getSkyframeExecutor();
StarlarkSemantics effectiveStarlarkSemantics =
skyframeExecutor.getEffectiveStarlarkSemantics(starlarkSemanticsOptions);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/google/devtools/build/lib/skyframe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/packages:build_type",
"//src/main/java/com/google/devtools/build/lib/packages:starlark_semantics_options",
"//src/main/java/com/google/devtools/build/lib/packages:type",
"//src/main/java/com/google/devtools/build/lib/packages/semantics",
"//src/main/java/com/google/devtools/build/lib/pkgcache",
"//src/main/java/com/google/devtools/build/lib/profiler",
"//src/main/java/com/google/devtools/build/lib/profiler:google-auto-profiler-utils",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.StarlarkSemanticsOptions;
import com.google.devtools.build.lib.packages.WorkspaceFileValue;
import com.google.devtools.build.lib.packages.WorkspaceFileValue.WorkspaceFileKey;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.pkgcache.PackageOptions;
import com.google.devtools.build.lib.pkgcache.PathPackageLocator;
import com.google.devtools.build.lib.profiler.Profiler;
Expand Down Expand Up @@ -233,7 +233,7 @@ public void sync(
ExtendedEventHandler eventHandler,
PackageOptions packageOptions,
PathPackageLocator packageLocator,
StarlarkSemanticsOptions starlarkSemanticsOptions,
BuildLanguageOptions starlarkSemanticsOptions,
UUID commandId,
Map<String, String> clientEnv,
TimestampGranularityMonitor tsgm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.packages.RuleClassProvider;
import com.google.devtools.build.lib.packages.RuleVisibility;
import com.google.devtools.build.lib.packages.StarlarkSemanticsOptions;
import com.google.devtools.build.lib.packages.WorkspaceFileValue;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.pkgcache.LoadingOptions;
import com.google.devtools.build.lib.pkgcache.PackageManager;
import com.google.devtools.build.lib.pkgcache.PackageOptions;
Expand Down Expand Up @@ -1352,7 +1352,7 @@ public void clearLoadedPackages() {
public void preparePackageLoading(
PathPackageLocator pkgLocator,
PackageOptions packageOptions,
StarlarkSemanticsOptions starlarkSemanticsOptions,
BuildLanguageOptions starlarkSemanticsOptions,
UUID commandId,
Map<String, String> clientEnv,
TimestampGranularityMonitor tsgm) {
Expand Down Expand Up @@ -1400,7 +1400,7 @@ private void setSiblingDirectoryLayout(boolean experimentalSiblingRepositoryLayo
}

public StarlarkSemantics getEffectiveStarlarkSemantics(
StarlarkSemanticsOptions starlarkSemanticsOptions) {
BuildLanguageOptions starlarkSemanticsOptions) {
return starlarkSemanticsOptions.toStarlarkSemantics();
}

Expand Down Expand Up @@ -2638,7 +2638,7 @@ public void sync(
ExtendedEventHandler eventHandler,
PackageOptions packageOptions,
PathPackageLocator pathPackageLocator,
StarlarkSemanticsOptions starlarkSemanticsOptions,
BuildLanguageOptions starlarkSemanticsOptions,
UUID commandId,
Map<String, String> clientEnv,
TimestampGranularityMonitor tsgm,
Expand Down Expand Up @@ -2690,7 +2690,7 @@ public void sync(
protected void syncPackageLoading(
PackageOptions packageOptions,
PathPackageLocator pathPackageLocator,
StarlarkSemanticsOptions starlarkSemanticsOptions,
BuildLanguageOptions starlarkSemanticsOptions,
UUID commandId,
Map<String, String> clientEnv,
TimestampGranularityMonitor tsgm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
/**
* Options that affect the dynamic behavior of Starlark execution and operators.
*
* <p>For descriptions of what these options do, see {@link packages.StarlarkSemanticsOptions}.
* <p>For descriptions of what these options do, see {@link
* packages.semantics.BuildLanguageOptions}.
*
* <p>For options that affect the static behavior of the Starlark frontend (lexer, parser,
* validator, compiler), see FileOptions.
*/
// TODO(brandjon): User error messages that reference options should maybe be substituted with the
// option name outside of the core Starlark interpreter?
// TODO(brandjon): Eventually these should be documented in full here, and StarlarkSemanticsOptions
// TODO(brandjon): Eventually these should be documented in full here, and BuildLanguageOptions
// should refer to this class for documentation. But this doesn't play nice with the options
// parser's annotation mechanism.
//
Expand Down
Loading

0 comments on commit 240bdea

Please sign in to comment.