Search in sources :

Example 26 with Rule

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();
}
Also used : RawAttributeMapper(com.google.devtools.build.lib.packages.RawAttributeMapper) Rule(com.google.devtools.build.lib.packages.Rule) Test(org.junit.Test)

Example 27 with Rule

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();
}
Also used : RawAttributeMapper(com.google.devtools.build.lib.packages.RawAttributeMapper) Rule(com.google.devtools.build.lib.packages.Rule) Test(org.junit.Test)

Example 28 with Rule

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>());
}
Also used : Identifier(com.google.devtools.build.lib.syntax.Identifier) SkyFunction(com.google.devtools.build.skyframe.SkyFunction) HttpDownloader(com.google.devtools.build.lib.bazel.repository.downloader.HttpDownloader) HashMap(java.util.HashMap) Package(com.google.devtools.build.lib.packages.Package) Rule(com.google.devtools.build.lib.packages.Rule) FuncallExpression(com.google.devtools.build.lib.syntax.FuncallExpression)

Example 29 with Rule

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:");
    }
}
Also used : RepositoryCache(com.google.devtools.build.lib.bazel.repository.cache.RepositoryCache) Rule(com.google.devtools.build.lib.packages.Rule) IOException(java.io.IOException) Test(org.junit.Test)

Example 30 with Rule

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");
}
Also used : Rule(com.google.devtools.build.lib.packages.Rule) Test(org.junit.Test)

Aggregations

Rule (com.google.devtools.build.lib.packages.Rule)79 Test (org.junit.Test)27 Label (com.google.devtools.build.lib.cmdline.Label)26 Attribute (com.google.devtools.build.lib.packages.Attribute)20 Target (com.google.devtools.build.lib.packages.Target)19 Nullable (javax.annotation.Nullable)10 RawAttributeMapper (com.google.devtools.build.lib.packages.RawAttributeMapper)9 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)9 OutputFile (com.google.devtools.build.lib.packages.OutputFile)8 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)7 NoSuchThingException (com.google.devtools.build.lib.packages.NoSuchThingException)7 SkyKey (com.google.devtools.build.skyframe.SkyKey)7 ImmutableList (com.google.common.collect.ImmutableList)6 InputFile (com.google.devtools.build.lib.packages.InputFile)6 IOException (java.io.IOException)6 LinkedHashSet (java.util.LinkedHashSet)6 AggregatingAttributeMapper (com.google.devtools.build.lib.packages.AggregatingAttributeMapper)5 Package (com.google.devtools.build.lib.packages.Package)5 Artifact (com.google.devtools.build.lib.actions.Artifact)4 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)4