-
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.
Expose platform-related providers to Skylark.
Change-Id: I7615d3e6e33e0c48f18b2506a135f45ce3705a38 PiperOrigin-RevId: 152256914
- Loading branch information
Showing
16 changed files
with
492 additions
and
186 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
92 changes: 92 additions & 0 deletions
92
src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSettingInfo.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,92 @@ | ||
// Copyright 2017 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.rules.platform; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import com.google.common.base.Function; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.Iterables; | ||
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; | ||
import com.google.devtools.build.lib.cmdline.Label; | ||
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; | ||
import com.google.devtools.build.lib.packages.ClassObjectConstructor; | ||
import com.google.devtools.build.lib.packages.NativeClassObjectConstructor; | ||
import com.google.devtools.build.lib.packages.SkylarkClassObject; | ||
import com.google.devtools.build.lib.packages.SkylarkProviderIdentifier; | ||
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; | ||
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; | ||
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; | ||
import com.google.devtools.build.lib.util.Preconditions; | ||
|
||
/** Provider for a platform constraint setting that is available to be fulfilled. */ | ||
@SkylarkModule( | ||
name = "ConstraintSettingInfo", | ||
doc = "A specific constraint setting that may be used to define a platform.", | ||
category = SkylarkModuleCategory.PROVIDER | ||
) | ||
@AutoValue | ||
@Immutable | ||
public abstract class ConstraintSettingInfo extends SkylarkClassObject { | ||
|
||
/** Name used in Skylark for accessing this provider. */ | ||
static final String SKYLARK_NAME = "ConstraintSettingInfo"; | ||
|
||
/** Skylark constructor and identifier for this provider. */ | ||
static final ClassObjectConstructor SKYLARK_CONSTRUCTOR = | ||
new NativeClassObjectConstructor(SKYLARK_NAME) {}; | ||
|
||
/** Identifier used to retrieve this provider from rules which export it. */ | ||
public static final SkylarkProviderIdentifier SKYLARK_IDENTIFIER = | ||
SkylarkProviderIdentifier.forKey(SKYLARK_CONSTRUCTOR.getKey()); | ||
|
||
ConstraintSettingInfo() { | ||
super(SKYLARK_CONSTRUCTOR, ImmutableMap.<String, Object>of()); | ||
} | ||
|
||
@SkylarkCallable( | ||
name = "label", | ||
doc = "The label used to identify this constraint setting.", | ||
structField = true | ||
) | ||
public abstract Label label(); | ||
|
||
/** Retrieves and casts the provider from the given target. */ | ||
public static ConstraintSettingInfo fromTarget(TransitiveInfoCollection target) { | ||
Object provider = target.get(SKYLARK_IDENTIFIER); | ||
if (provider == null) { | ||
return null; | ||
} | ||
Preconditions.checkState(provider instanceof ConstraintSettingInfo); | ||
return (ConstraintSettingInfo) provider; | ||
} | ||
|
||
/** Retrieves and casts the providers from the given targets. */ | ||
public static Iterable<ConstraintSettingInfo> fromTargets( | ||
Iterable<? extends TransitiveInfoCollection> targets) { | ||
return Iterables.transform( | ||
targets, | ||
new Function<TransitiveInfoCollection, ConstraintSettingInfo>() { | ||
@Override | ||
public ConstraintSettingInfo apply(TransitiveInfoCollection target) { | ||
return fromTarget(target); | ||
} | ||
}); | ||
} | ||
|
||
/** Returns a new {@link ConstraintSettingInfo} with the given data. */ | ||
public static ConstraintSettingInfo create(Label constraintSetting) { | ||
return new AutoValue_ConstraintSettingInfo(constraintSetting); | ||
} | ||
} |
31 changes: 0 additions & 31 deletions
31
src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSettingProvider.java
This file was deleted.
Oops, something went wrong.
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
99 changes: 99 additions & 0 deletions
99
src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueInfo.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,99 @@ | ||
// Copyright 2017 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.rules.platform; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import com.google.common.base.Function; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.Iterables; | ||
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; | ||
import com.google.devtools.build.lib.cmdline.Label; | ||
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; | ||
import com.google.devtools.build.lib.packages.ClassObjectConstructor; | ||
import com.google.devtools.build.lib.packages.NativeClassObjectConstructor; | ||
import com.google.devtools.build.lib.packages.SkylarkClassObject; | ||
import com.google.devtools.build.lib.packages.SkylarkProviderIdentifier; | ||
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; | ||
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; | ||
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; | ||
import com.google.devtools.build.lib.util.Preconditions; | ||
|
||
/** Provider for a platform constraint value that fulfills a {@link ConstraintSettingInfo}. */ | ||
@SkylarkModule( | ||
name = "ConstraintValueProvider", | ||
doc = "A value for a constraint setting that can be used to define a platform.", | ||
category = SkylarkModuleCategory.PROVIDER | ||
) | ||
@AutoValue | ||
@Immutable | ||
public abstract class ConstraintValueInfo extends SkylarkClassObject { | ||
|
||
/** Name used in Skylark for accessing this provider. */ | ||
static final String SKYLARK_NAME = "ConstraintValueInfo"; | ||
|
||
/** Skylark constructor and identifier for this provider. */ | ||
static final ClassObjectConstructor SKYLARK_CONSTRUCTOR = | ||
new NativeClassObjectConstructor(SKYLARK_NAME) {}; | ||
|
||
/** Identifier used to retrieve this provider from rules which export it. */ | ||
public static final SkylarkProviderIdentifier SKYLARK_IDENTIFIER = | ||
SkylarkProviderIdentifier.forKey(SKYLARK_CONSTRUCTOR.getKey()); | ||
|
||
ConstraintValueInfo() { | ||
super(SKYLARK_CONSTRUCTOR, ImmutableMap.<String, Object>of()); | ||
} | ||
|
||
@SkylarkCallable( | ||
name = "constraint", | ||
doc = "The constraint setting that this value fulfills.", | ||
structField = true | ||
) | ||
public abstract ConstraintSettingInfo constraint(); | ||
|
||
@SkylarkCallable( | ||
name = "label", | ||
doc = "The label used to identify this constraint value.", | ||
structField = true | ||
) | ||
public abstract Label label(); | ||
|
||
/** Retrieves and casts the provider from the given target. */ | ||
public static ConstraintValueInfo fromTarget(TransitiveInfoCollection target) { | ||
Object provider = target.get(SKYLARK_IDENTIFIER); | ||
if (provider == null) { | ||
return null; | ||
} | ||
Preconditions.checkState(provider instanceof ConstraintValueInfo); | ||
return (ConstraintValueInfo) provider; | ||
} | ||
|
||
/** Retrieves and casts the providers from the given targets. */ | ||
public static Iterable<ConstraintValueInfo> fromTargets( | ||
Iterable<? extends TransitiveInfoCollection> targets) { | ||
return Iterables.transform( | ||
targets, | ||
new Function<TransitiveInfoCollection, ConstraintValueInfo>() { | ||
@Override | ||
public ConstraintValueInfo apply(TransitiveInfoCollection target) { | ||
return fromTarget(target); | ||
} | ||
}); | ||
} | ||
|
||
/** Returns a new {@link ConstraintValueInfo} with the given data. */ | ||
public static ConstraintValueInfo create(ConstraintSettingInfo constraint, Label value) { | ||
return new AutoValue_ConstraintValueInfo(constraint, value); | ||
} | ||
} |
33 changes: 0 additions & 33 deletions
33
src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueProvider.java
This file was deleted.
Oops, something went wrong.
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.