aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/analysis
diff options
context:
space:
mode:
authorGravatar John Field <jfield@google.com>2015-09-21 18:59:19 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2015-09-22 17:05:23 +0000
commit925dc5ce1c6916b43a94fa12017aa4a6390de891 (patch)
tree17da1c801a23290c563bcf4347dd90930f094c12 /src/main/java/com/google/devtools/build/lib/analysis
parentd256a821f4051273e3be1617c793c6dc5e77d964 (diff)
Use Labels, rather than PathFragments, to represent Skylark loads internally. This should be a semantics-preserving change for users. In a subsequent CL, I'll change the Skylark syntax to allow load statements to use labels as well as paths, with the goal of eventually deprecating the latter.
Also: - Removed the hack for handling relative loads in the prelude file. - Refactored some redundant functionality in PackageFunction and SkylarkImportLookupFunction for handling loads. - Removed the ability to put the BUILD file for the package containing a Skylark file under a different package root than the Skylark file itself. This functionality isn't currently used and is inconsistent with Blaze's handling of the package path elsewhere. - Added BUILD files to a number of tests that load Skylark files; this is consistent with the requirement that all Skylark files need to be part of some package. - Changed the constants used to set the location of the prelude file from paths to labels. -- MOS_MIGRATED_REVID=103567562
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/analysis')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java
index 3b7ddd47e3..b46fea748c 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java
@@ -18,7 +18,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType.ABSTRACT;
import static com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType.TEST;
-import com.google.common.base.Preconditions;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
@@ -81,7 +80,7 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider {
*/
public static class Builder implements RuleDefinitionEnvironment {
private final StringBuilder defaultWorkspaceFile = new StringBuilder();
- private PathFragment preludePath;
+ private Label preludeLabel;
private String runfilesPrefix;
private final List<ConfigurationFragmentFactory> configurationFragments = new ArrayList<>();
private final List<BuildInfoFactory> buildInfoFactories = new ArrayList<>();
@@ -105,11 +104,14 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider {
defaultWorkspaceFile.append(contents);
}
- public Builder setPrelude(String workspaceRelativePath) {
- PathFragment preludePathFragment = new PathFragment(workspaceRelativePath);
- Preconditions.checkArgument(!preludePathFragment.isAbsolute());
- Preconditions.checkArgument(preludePathFragment.isNormalized());
- this.preludePath = preludePathFragment;
+ public Builder setPrelude(String preludeLabelString) {
+ try {
+ this.preludeLabel = Label.parseAbsolute(preludeLabelString);
+ } catch (LabelSyntaxException e) {
+ String errorMsg =
+ String.format("Prelude label '%s' is not syntactically valid", preludeLabelString);
+ throw new IllegalArgumentException(errorMsg);
+ }
return this;
}
@@ -226,7 +228,7 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider {
}
return new ConfiguredRuleClassProvider(
- preludePath,
+ preludeLabel,
runfilesPrefix,
ImmutableMap.copyOf(ruleClassMap),
ImmutableMap.copyOf(ruleDefinitionMap),
@@ -269,9 +271,9 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider {
String defaultWorkspaceFile;
/**
- * Workspace-relative path to the prelude.
+ * Label for the prelude file.
*/
- private final PathFragment preludePath;
+ private final Label preludeLabel;
/**
* The default runfiles prefix.
@@ -315,7 +317,7 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider {
private final Environment.Frame globals;
public ConfiguredRuleClassProvider(
- PathFragment preludePath,
+ Label preludeLabel,
String runfilesPrefix,
ImmutableMap<String, RuleClass> ruleClassMap,
ImmutableMap<String, Class<? extends RuleDefinition>> ruleDefinitionMap,
@@ -327,7 +329,7 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider {
ConfigurationCollectionFactory configurationCollectionFactory,
PrerequisiteValidator prerequisiteValidator,
ImmutableMap<String, SkylarkType> skylarkAccessibleJavaClasses) {
- this.preludePath = preludePath;
+ this.preludeLabel = preludeLabel;
this.runfilesPrefix = runfilesPrefix;
this.ruleClassMap = ruleClassMap;
this.ruleDefinitionMap = ruleDefinitionMap;
@@ -346,8 +348,8 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider {
}
@Override
- public PathFragment getPreludePath() {
- return preludePath;
+ public Label getPreludeLabel() {
+ return preludeLabel;
}
@Override