forked from facebook/buck
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interfaces for classes in core.rules.graphbuilder
Summary: Extracted interfaces for BuildRuleKey and BuildRuleContextWithEnvironment. Moved the abstract class implementation into an impl sub package. Reviewed By: bobyangyf fbshipit-source-id: 63e8a50
- Loading branch information
1 parent
1d51479
commit 792e3b7
Showing
10 changed files
with
214 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
load("//tools/build_rules:java_rules.bzl", "java_immutables_library") | ||
|
||
java_immutables_library( | ||
name = "impl", | ||
srcs = glob( | ||
["*.java"], | ||
), | ||
exported_deps = [ | ||
"//src/com/facebook/buck/core/rules/graphbuilder:graphbuilder", | ||
], | ||
tests = [ | ||
"//test/com/facebook/buck/core/rules/graphbuilder/impl:impl", | ||
], | ||
visibility = [ | ||
"PUBLIC", | ||
], | ||
deps = [ | ||
"//src/com/facebook/buck/core/graph/transformation:transformation", | ||
"//src/com/facebook/buck/core/rules:rules", | ||
"//third-party/java/guava:guava", | ||
], | ||
) |
114 changes: 114 additions & 0 deletions
114
...om/facebook/buck/core/rules/graphbuilder/impl/DefaultBuildRuleContextWithEnvironment.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,114 @@ | ||
/* | ||
* Copyright 2018-present Facebook, Inc. | ||
* | ||
* 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.facebook.buck.core.rules.graphbuilder.impl; | ||
|
||
import com.facebook.buck.core.cell.resolver.CellPathResolver; | ||
import com.facebook.buck.core.graph.transformation.TransformationEnvironment; | ||
import com.facebook.buck.core.model.BuildTarget; | ||
import com.facebook.buck.core.model.targetgraph.TargetNode; | ||
import com.facebook.buck.core.rules.BuildRule; | ||
import com.facebook.buck.core.rules.BuildRuleCreationContext; | ||
import com.facebook.buck.core.rules.graphbuilder.BuildRuleContextWithEnvironment; | ||
import com.facebook.buck.core.rules.graphbuilder.BuildRuleKey; | ||
import com.facebook.buck.core.rules.provider.BuildRuleInfoProviderCollection; | ||
import com.facebook.buck.io.filesystem.ProjectFilesystem; | ||
import com.facebook.buck.toolchain.ToolchainProvider; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.collect.ImmutableSortedSet; | ||
import com.google.common.collect.Maps; | ||
import java.util.concurrent.CompletionStage; | ||
import java.util.function.Function; | ||
import org.immutables.value.Value; | ||
import org.immutables.value.Value.Style.ImplementationVisibility; | ||
|
||
/** Default abstract implementation of a {@link BuildRuleContextWithEnvironment}. */ | ||
@Value.Immutable(builder = false, copy = false) | ||
@Value.Style(visibility = ImplementationVisibility.PACKAGE) | ||
public abstract class DefaultBuildRuleContextWithEnvironment | ||
implements BuildRuleContextWithEnvironment { | ||
|
||
@Value.Parameter | ||
protected abstract BuildRuleKey getKey(); | ||
|
||
protected BuildRuleCreationContext getCreationContext() { | ||
return getKey().getBuildRuleCreationContext(); | ||
} | ||
|
||
/** @return the {@link TargetNode} of the current desired {@link BuildRule} */ | ||
protected TargetNode<?, ?> getCurrentNode() { | ||
return getKey().getTargetNode(); | ||
} | ||
|
||
@Value.Parameter | ||
protected abstract TransformationEnvironment<BuildRuleKey, BuildRule> getEnv(); | ||
|
||
@Override | ||
public ProjectFilesystem getProjectFilesystem() { | ||
return getCreationContext().getProjectFilesystem(); | ||
} | ||
|
||
@Override | ||
public CellPathResolver getCellPathResolver() { | ||
return getCreationContext().getCellPathResolver(); | ||
} | ||
|
||
@Override | ||
public ToolchainProvider getToolchainProvider() { | ||
return getCreationContext().getToolchainProvider(); | ||
} | ||
|
||
@Override | ||
public ImmutableSet<BuildTarget> getDeclaredDeps() { | ||
return getCurrentNode().getDeclaredDeps(); | ||
} | ||
|
||
@Override | ||
public ImmutableSortedSet<BuildTarget> getExtraDeps() { | ||
return getCurrentNode().getExtraDeps(); | ||
} | ||
|
||
@Override | ||
public ImmutableSortedSet<BuildTarget> getTargetGraphOnlyDeps() { | ||
return getCurrentNode().getTargetGraphOnlyDeps(); | ||
} | ||
|
||
@Override | ||
public CompletionStage<BuildRule> getProviderCollectionForDep( | ||
BuildRuleKey depKey, | ||
Function<BuildRuleInfoProviderCollection, BuildRule> createBuildRuleWithDep) { | ||
return getEnv() | ||
.evaluate( | ||
depKey, | ||
depBuildRule -> createBuildRuleWithDep.apply(depBuildRule.getProviderCollection())); | ||
} | ||
|
||
@Override | ||
public CompletionStage<BuildRule> getProviderCollectionForDeps( | ||
Iterable<BuildRuleKey> depKeys, | ||
Function<ImmutableMap<BuildRuleKey, BuildRuleInfoProviderCollection>, BuildRule> | ||
createBuildRuleWithDeps) { | ||
return getEnv() | ||
.evaluateAll( | ||
depKeys, | ||
depBuildRules -> | ||
createBuildRuleWithDeps.apply( | ||
ImmutableMap.copyOf( | ||
Maps.transformValues( | ||
depBuildRules, rule -> rule.getProviderCollection())))); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/com/facebook/buck/core/rules/graphbuilder/impl/DefaultBuildRuleKey.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,49 @@ | ||
/* | ||
* Copyright 2018-present Facebook, Inc. | ||
* | ||
* 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.facebook.buck.core.rules.graphbuilder.impl; | ||
|
||
import com.facebook.buck.core.model.BuildTarget; | ||
import com.facebook.buck.core.model.targetgraph.BuildRuleCreationContextWithTargetGraph; | ||
import com.facebook.buck.core.model.targetgraph.TargetNode; | ||
import com.facebook.buck.core.rules.graphbuilder.BuildRuleKey; | ||
import org.immutables.value.Value; | ||
|
||
/** Default abstract implementation of a {@link BuildRuleKey}. */ | ||
@Value.Immutable(builder = false, copy = false, prehash = true) | ||
public abstract class DefaultBuildRuleKey implements BuildRuleKey { | ||
|
||
@Value.Parameter | ||
@Value.Auxiliary | ||
@Override | ||
public abstract BuildTarget getBuildTarget(); | ||
|
||
@Value.Derived | ||
protected TargetNodeWrapper getTargetNodeWrapper() { | ||
return TargetNodeWrapper.of( | ||
getBuildRuleCreationContext().getTargetGraph().get(getBuildTarget())); | ||
} | ||
|
||
@Override | ||
public TargetNode<?, ?> getTargetNode() { | ||
return getTargetNodeWrapper().getTargetNode(); | ||
} | ||
|
||
@Value.Parameter | ||
@Value.Auxiliary | ||
@Override | ||
public abstract BuildRuleCreationContextWithTargetGraph getBuildRuleCreationContext(); | ||
} |
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
3 changes: 2 additions & 1 deletion
3
...acebook/buck/core/rules/graphbuilder/BUCK → ...ok/buck/core/rules/graphbuilder/impl/BUCK
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.