use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class MavenJarFunctionTest method testNoSha1WithCache.
@Test
public void testNoSha1WithCache() throws Exception {
Rule rule = scratchRule("external", "foo", "maven_jar(", " name = 'foo',", " artifact = 'x:y:z:1.1',", ")");
RepositoryCache cache = Mockito.mock(RepositoryCache.class);
Mockito.when(cache.isEnabled()).thenReturn(true);
MavenDownloader downloader = new MavenDownloader(cache);
try {
downloader.download("foo", WorkspaceAttributeMapper.of(rule), scratch.dir("/whatever"), TEST_SERVER);
fail("Expected failure to fetch artifact because of nonexistent server.");
} catch (IOException expected) {
assertThat(expected.getMessage()).contains("Failed to fetch Maven dependency:");
}
}
use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class BuildViewTestCase method scratchRule.
/**
* Create and return a scratch rule.
*
* @param packageName the package name of the rule.
* @param ruleName the name of the rule.
* @param lines the text of the rule.
* @return the rule instance for the created rule.
* @throws IOException
* @throws Exception
*/
protected Rule scratchRule(String packageName, String ruleName, String... lines) throws Exception {
String buildFilePathString = packageName + "/BUILD";
if (packageName.equals(Label.EXTERNAL_PACKAGE_NAME.getPathString())) {
buildFilePathString = "WORKSPACE";
scratch.overwriteFile(buildFilePathString, lines);
} else {
scratch.file(buildFilePathString, lines);
}
skyframeExecutor.invalidateFilesUnderPathForTesting(reporter, new ModifiedFileSet.Builder().modify(new PathFragment(buildFilePathString)).build(), rootDirectory);
return (Rule) getTarget("//" + packageName + ":" + ruleName);
}
use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class SdkMavenRepositoryTest method testGeneratedAarImport.
@Test
public void testGeneratedAarImport() throws Exception {
sdkMavenRepository.writeBuildFiles(workspaceDir);
Rule aarImport = getConfiguredTarget("//com.google.android:bar-1.0.0").getTarget().getAssociatedRule();
assertThat(aarImport.getRuleClass()).isEqualTo("aar_import");
AttributeMap attributes = RawAttributeMapper.of(aarImport);
assertThat(attributes.get("aar", BuildType.LABEL)).isEqualTo(Label.parseAbsoluteUnchecked("//:repo/com/google/android/bar/1.0.0/bar.aar"));
assertThat(attributes.get("exports", BuildType.LABEL_LIST)).containsExactly(Label.parseAbsoluteUnchecked("//com.google.android:foo-1.0.0"));
}
use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class SdkMavenRepositoryTest method testGeneratedJavaImport.
@Test
public void testGeneratedJavaImport() throws Exception {
sdkMavenRepository.writeBuildFiles(workspaceDir);
Rule javaImport = getConfiguredTarget("//com.google.android:foo-1.0.0").getTarget().getAssociatedRule();
assertThat(javaImport.getRuleClass()).isEqualTo("java_import");
AttributeMap attributes = RawAttributeMapper.of(javaImport);
assertThat(attributes.get("jars", BuildType.LABEL_LIST)).containsExactly(Label.parseAbsoluteUnchecked("//:repo/com/google/android/foo/1.0.0/foo.jar"));
assertThat(attributes.get("exports", BuildType.LABEL_LIST)).isEmpty();
}
use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class SkylarkFileContentHashTests method getHash.
/**
* Returns the hash code of the rule target defined by the pkg and the target name parameters.
* Asserts that the targets and it's Skylark dependencies were loaded properly.
*/
private String getHash(String pkg, String name) throws Exception {
PackageCacheOptions packageCacheOptions = Options.getDefaults(PackageCacheOptions.class);
packageCacheOptions.defaultVisibility = ConstantRuleVisibility.PUBLIC;
packageCacheOptions.showLoadingProgress = true;
packageCacheOptions.globbingThreads = 7;
getSkyframeExecutor().preparePackageLoading(new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory)), packageCacheOptions, "", UUID.randomUUID(), ImmutableMap.<String, String>of(), ImmutableMap.<String, String>of(), new TimestampGranularityMonitor(BlazeClock.instance()));
SkyKey pkgLookupKey = PackageValue.key(PackageIdentifier.parse("@//" + pkg));
EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate(getSkyframeExecutor(), pkgLookupKey, /*keepGoing=*/
false, reporter);
assertFalse(result.hasError());
Collection<Target> targets = result.get(pkgLookupKey).getPackage().getTargets();
for (Target target : targets) {
if (target.getName().equals(name)) {
return ((Rule) target).getRuleClassObject().getRuleDefinitionEnvironment().getTransitiveContentHashCode();
}
}
throw new IllegalStateException("target not found: " + name);
}
Aggregations