use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class RawAttributeMapperTest method testGetMergedValues.
@Test
public void testGetMergedValues() throws Exception {
Rule rule = scratchRule("x", "myrule", "sh_binary(", " name = 'myrule',", " srcs = select({", " '//conditions:a': ['a.sh', 'b.sh'],", " '//conditions:b': ['b.sh', 'c.sh'],", " }))");
RawAttributeMapper rawMapper = RawAttributeMapper.of(rule);
assertThat(rawMapper.getMergedValues("srcs", BuildType.LABEL_LIST)).containsExactly(Label.parseAbsolute("//x:a.sh"), Label.parseAbsolute("//x:b.sh"), Label.parseAbsolute("//x:c.sh")).inOrder();
}
use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class RawAttributeMapperTest method testMergedValuesWithConcatenatedSelects.
@Test
public void testMergedValuesWithConcatenatedSelects() throws Exception {
Rule rule = scratchRule("x", "myrule", "sh_binary(", " name = 'myrule',", " srcs = select({", " '//conditions:a1': ['a1.sh'],", " '//conditions:b1': ['b1.sh', 'another_b1.sh']})", " + select({", " '//conditions:a2': ['a2.sh'],", " '//conditions:b2': ['b2.sh']})", " )");
RawAttributeMapper rawMapper = RawAttributeMapper.of(rule);
assertThat(rawMapper.getMergedValues("srcs", BuildType.LABEL_LIST)).containsExactly(Label.parseAbsolute("//x:a1.sh"), Label.parseAbsolute("//x:b1.sh"), Label.parseAbsolute("//x:another_b1.sh"), Label.parseAbsolute("//x:a2.sh"), Label.parseAbsolute("//x:b2.sh")).inOrder();
}
use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class SkylarkRepositoryContextTest method setUpContextForRule.
protected void setUpContextForRule(Map<String, Object> kwargs, Attribute... attributes) throws Exception {
Package.Builder packageBuilder = Package.newExternalPackageBuilder(Package.Builder.DefaultHelper.INSTANCE, workspaceFile, "runfiles");
FuncallExpression ast = new FuncallExpression(new Identifier("test"), ImmutableList.<Passed>of());
ast.setLocation(Location.BUILTIN);
Rule rule = packageBuilder.externalPackageData().createAndAddRepositoryRule(packageBuilder, buildRuleClass(attributes), null, kwargs, ast);
HttpDownloader downloader = Mockito.mock(HttpDownloader.class);
context = new SkylarkRepositoryContext(rule, outputDirectory, Mockito.mock(SkyFunction.Environment.class), ImmutableMap.of("FOO", "BAR"), downloader, new HashMap<String, String>());
}
use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class MavenJarFunctionTest method testValidSha1.
@Test
public void testValidSha1() throws Exception {
Rule rule = scratchRule("external", "foo", "maven_jar(", " name = 'foo',", " artifact = 'x:y:z:1.1',", " sha1 = 'da39a3ee5e6b4b0d3255bfef95601890afd80709',", ")");
MavenDownloader downloader = new MavenDownloader(Mockito.mock(RepositoryCache.class));
try {
downloader.download("foo", WorkspaceAttributeMapper.of(rule), scratch.dir("/whatever"), TEST_SERVER);
fail("Expected failure to fetch artifact because of nonexistent server and not due to " + "the existence of a valid SHA");
} 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 SdkMavenRepositoryTest method testGeneratedRuleForInvalidPackaging.
@Test
public void testGeneratedRuleForInvalidPackaging() throws Exception {
sdkMavenRepository.writeBuildFiles(workspaceDir);
Rule invalidPackagingGenrule = getConfiguredTarget("//com.google.android:baz-1.0.0").getTarget().getAssociatedRule();
assertThat(invalidPackagingGenrule.getRuleClass()).isEqualTo("genrule");
assertThat(RawAttributeMapper.of(invalidPackagingGenrule).get("cmd", Type.STRING)).isEqualTo("echo Bazel does not recognize the Maven packaging type for: " + "\"//:repo/com/google/android/baz/1.0.0/baz.par\"; exit 1");
}
Aggregations