From 51215bd922d57f2ddd03deac6295f3e9267c7c3c Mon Sep 17 00:00:00 2001 From: juliexxia Date: Tue, 14 Aug 2018 10:28:35 -0700 Subject: Create new config module that is responsible for creating BuildSetting descriptor objects. Build settings are units of configuration i.e. a key/value pair of a setting (e.g. cpu) and a value (e.g. ppc). A build setting descriptor is used to describe what kind of build setting a skylark rule is (if any at all). The BuildSettingDescriptor implementation of the API describes two facets of the build setting rule: the type of the value and whether or not the setting is settable on the command line. The methods exposed here will eventually be hooked up to a new parameter in the rule() function. Validation for these restrictions will also happen in a later CL attached to the same bug. PiperOrigin-RevId: 208669663 --- .../build/lib/analysis/skylark/SkylarkConfig.java | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkConfig.java (limited to 'src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkConfig.java') diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkConfig.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkConfig.java new file mode 100644 index 0000000000..a75cd5c829 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkConfig.java @@ -0,0 +1,89 @@ +// Copyright 2018 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.analysis.skylark; + +import static com.google.devtools.build.lib.packages.BuildType.LABEL; +import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; +import static com.google.devtools.build.lib.syntax.Type.BOOLEAN; +import static com.google.devtools.build.lib.syntax.Type.INTEGER; +import static com.google.devtools.build.lib.syntax.Type.STRING; +import static com.google.devtools.build.lib.syntax.Type.STRING_LIST; + +import com.google.devtools.build.lib.skylarkbuildapi.SkylarkConfigApi; +import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter; +import com.google.devtools.build.lib.syntax.Type; + +/** + * Skylark namespace for creating build setting descriptors. + */ +public class SkylarkConfig implements SkylarkConfigApi { + + @Override + public BuildSettingDescriptor intSetting(Boolean flag) { + return new BuildSettingDescriptor(flag, INTEGER); + } + + @Override + public BuildSettingDescriptor boolSetting(Boolean flag) { + return new BuildSettingDescriptor(flag, BOOLEAN); + } + + @Override + public BuildSettingDescriptor stringSetting(Boolean flag) { + return new BuildSettingDescriptor(flag, STRING); + } + + @Override + public BuildSettingDescriptor stringListSetting(Boolean flag) { + return new BuildSettingDescriptor(flag, STRING_LIST); + } + + @Override + public BuildSettingDescriptor labelSetting(Boolean flag) { + return new BuildSettingDescriptor(flag, LABEL); + } + + @Override + public BuildSettingDescriptor labelListSetting(Boolean flag) { + return new BuildSettingDescriptor(flag, LABEL_LIST); + } + + @Override + public void repr(SkylarkPrinter printer) { + printer.append(""); + } + + /** + * An object that describes what time of build setting a skylark rule is (if any type). + */ + public static final class BuildSettingDescriptor implements SkylarkConfigApi.BuildSettingApi { + private boolean isFlag; + private Type type; + + BuildSettingDescriptor(boolean isFlag, Type type) { + this.isFlag = isFlag; + this.type = type; + } + + public Type getType() { + return type; + } + + @Override + public void repr(SkylarkPrinter printer) { + printer.append(""); + } + } +} -- cgit v1.2.3