Search in sources :

Example 71 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class BlazeResolveConfigurationEquivalenceTest method testIncludes.

@Test
public void testIncludes() {
    ProjectView projectView = projectView(directories("foo/bar"), targets("//foo/bar:one", "//foo/bar:two", "//foo/bar:three"));
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(createCcToolchain()).addTarget(createCcTarget("//foo/bar:one", Kind.CC_BINARY, sources("foo/bar/one.cc"), defines(), includes("foo/same"))).addTarget(createCcTarget("//foo/bar:two", Kind.CC_BINARY, sources("foo/bar/two.cc"), defines(), includes("foo/same"))).addTarget(createCcTarget("//foo/bar:three", Kind.CC_BINARY, sources("foo/bar/three.cc"), defines(), includes("foo/different"))).build();
    VirtualFile includeSame = createVirtualFile("/root/foo/same");
    VirtualFile includeDifferent = createVirtualFile("/root/foo/different");
    List<BlazeResolveConfiguration> configurations = resolve(projectView, targetMap);
    assertThat(configurations).hasSize(2);
    assertThat(getHeaders(get(configurations, "//foo/bar:one and 1 other target(s)"), OCLanguageKind.CPP)).containsExactly(header(includeSame));
    assertThat(getHeaders(get(configurations, "//foo/bar:three"), OCLanguageKind.CPP)).containsExactly(header(includeDifferent));
    for (BlazeResolveConfiguration configuration : configurations) {
        assertThat(configuration.getProjectHeadersRoots().getRoots()).isEmpty();
        assertThat(configuration.getCompilerMacros()).isEqualTo(macros());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StubVirtualFile(com.intellij.openapi.vfs.newvfs.impl.StubVirtualFile) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 72 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class BlazeGoGotoDeclarationHandlerTest method testResolveGoDirectories.

@Test
public void testResolveGoDirectories() {
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(src("foo/bar/BUILD")).setLabel("//foo/bar:binary").setKind("go_binary").addSource(src("foo/bar/binary.go")).addDependency("//one/two:library").setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("foo/bar/binary.go"))).setImportPath("prefix/foo/bar/binary"))).addTarget(TargetIdeInfo.builder().setBuildFile(src("one/two/BUILD")).setLabel("//one/two:library").setKind("go_library").addSource(src("one/two/library.go")).setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("one/two/library.go"))).setImportPath("prefix/one/two/library"))).build();
    BlazeProjectData projectData = new BlazeProjectData(0L, targetMap, null, null, new WorkspacePathResolverImpl(workspaceRoot), location -> workspaceRoot.fileForPath(new WorkspacePath(location.getRelativePath())), new WorkspaceLanguageSettings(WorkspaceType.GO, ImmutableSet.of(LanguageClass.GO)), null, null);
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(projectData));
    GoFile fooBarBinary = (GoFile) workspace.createPsiFile(new WorkspacePath("foo/bar/binary.go"), "package main", "import \"p<caret>refix/one<caret>/<caret>two/lib<caret>rary\"", "func foo(a library.One<caret>Two) {}", "func main() {}");
    GoFile oneTwoLibrary = (GoFile) workspace.createPsiFile(new WorkspacePath("one/two/library.go"), "package library", "type OneTwo struct {}");
    GoTypeSpec oneTwoStruct = PsiTreeUtil.findChildOfType(oneTwoLibrary, GoTypeSpec.class);
    PsiDirectory oneTwoDirectory = oneTwoLibrary.getParent();
    assertThat(oneTwoDirectory).isNotNull();
    PsiDirectory oneDirectory = oneTwoDirectory.getParent();
    assertThat(oneDirectory).isNotNull();
    BuildFile oneTwoBUILD = (BuildFile) workspace.createPsiFile(new WorkspacePath("one/two/BUILD"), "go_library(", "    name = 'library',", "    srcs = ['library.go'],", ")");
    FuncallExpression oneTwoLibraryRule = PsiUtils.findFirstChildOfClassRecursive(oneTwoBUILD, FuncallExpression.class);
    BlazeGoRootsProvider.createGoPathSourceRoot(getProject(), projectData);
    testFixture.configureFromExistingVirtualFile(fooBarBinary.getVirtualFile());
    List<Caret> carets = testFixture.getEditor().getCaretModel().getAllCarets();
    assertThat(carets).hasSize(5);
    PsiElement gotoPrefix = GotoDeclarationAction.findTargetElement(getProject(), testFixture.getEditor(), carets.get(0).getOffset());
    assertThat(gotoPrefix).isEqualTo(oneTwoLibraryRule);
    PsiElement gotoOne = GotoDeclarationAction.findTargetElement(getProject(), testFixture.getEditor(), carets.get(1).getOffset());
    assertThat(gotoOne).isEqualTo(oneDirectory);
    PsiElement gotoTwo = GotoDeclarationAction.findTargetElement(getProject(), testFixture.getEditor(), carets.get(2).getOffset());
    assertThat(gotoTwo).isEqualTo(oneTwoDirectory);
    PsiElement gotoLibrary = GotoDeclarationAction.findTargetElement(getProject(), testFixture.getEditor(), carets.get(3).getOffset());
    assertThat(gotoLibrary).isEqualTo(oneTwoLibraryRule);
    PsiElement gotoOneTwoType = GotoDeclarationAction.findTargetElement(getProject(), testFixture.getEditor(), carets.get(4).getOffset());
    assertThat(gotoOneTwoType).isEqualTo(oneTwoStruct);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) GoFile(com.goide.psi.GoFile) GoTypeSpec(com.goide.psi.GoTypeSpec) WorkspacePathResolverImpl(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl) PsiDirectory(com.intellij.psi.PsiDirectory) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Caret(com.intellij.openapi.editor.Caret) PsiElement(com.intellij.psi.PsiElement) Test(org.junit.Test)

Example 73 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class BlazeGoRootsProviderTest method testBuildGoRoot.

@Test
public void testBuildGoRoot() {
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(src("foo/bar/BUILD")).setLabel("//foo/bar:binary").setKind("go_binary").addSource(src("foo/bar/binary.go")).addDependency("//one/two:library").setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("foo/bar/binary.go"))).setImportPath("prefix/foo/bar/binary"))).addTarget(TargetIdeInfo.builder().setBuildFile(src("one/two/BUILD")).setLabel("//one/two:library").setKind("go_library").addSource(src("one/two/library.go")).addSource(src("one/two/three/library.go")).setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("one/two/library.go"), src("one/two/three/library.go"))).setImportPath("prefix/one/two/library"))).build();
    BlazeProjectData projectData = new BlazeProjectData(0L, targetMap, null, null, null, location -> workspaceRoot.fileForPath(new WorkspacePath(location.getRelativePath())), new WorkspaceLanguageSettings(WorkspaceType.GO, ImmutableSet.of(LanguageClass.GO)), null, null);
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(projectData));
    BlazeGoRootsProvider.createGoPathSourceRoot(getProject(), projectData);
    BlazeGoRootsProvider goRootsProvider = GoRootsProvider.EP_NAME.findExtension(BlazeGoRootsProvider.class);
    assertThat(goRootsProvider).isNotNull();
    Collection<VirtualFile> goRoots = goRootsProvider.getGoPathSourcesRoots(getProject(), null);
    VirtualFile goRoot = projectDataDirectory.findFileByRelativePath(".gopath");
    assertThat(goRoot).isNotNull();
    assertThat(goRoot.isDirectory()).isTrue();
    assertThat(goRoots).containsExactly(goRoot);
    assertIsDirectory(goRoot.findFileByRelativePath("prefix"));
    assertIsDirectory(goRoot.findFileByRelativePath("prefix/foo"));
    assertIsDirectory(goRoot.findFileByRelativePath("prefix/foo/bar"));
    assertIsDirectory(goRoot.findFileByRelativePath("prefix/foo/bar/binary"));
    assertIsSymbolicLink(goRoot.findFileByRelativePath("prefix/foo/bar/binary/binary_a7f1ab96.go"), "foo/bar/binary.go");
    assertIsDirectory(goRoot.findFileByRelativePath("prefix/one"));
    assertIsDirectory(goRoot.findFileByRelativePath("prefix/one/two"));
    assertIsDirectory(goRoot.findFileByRelativePath("prefix/one/two/library"));
    assertIsSymbolicLink(goRoot.findFileByRelativePath("prefix/one/two/library/library_81c8436f.go"), "one/two/library.go");
    assertIsSymbolicLink(goRoot.findFileByRelativePath("prefix/one/two/library/library_93e51efe.go"), "one/two/three/library.go");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Example 74 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class BlazeGoTestEventsHandlerTest method testSuiteLocationResolvesToBuildRule.

@Test
public void testSuiteLocationResolvesToBuildRule() {
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//foo/bar:foo_test").setKind("go_test").setBuildFile(src("foo/bar/BUILD")).addSource(src("foo/bar/foo_test.go")).addSource(src("foo/bar/bar_test.go")).setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("foo/bar/foo_test.go"))).addSources(ImmutableList.of(src("foo/bar/bar_test.go"))).setImportPath("google3/foo/bar/foo"))).build();
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(new BlazeProjectData(0L, targetMap, null, null, new WorkspacePathResolverImpl(workspaceRoot), location -> workspaceRoot.fileForPath(new WorkspacePath(location.getRelativePath())), new WorkspaceLanguageSettings(WorkspaceType.GO, ImmutableSet.of(LanguageClass.GO)), null, null)));
    workspace.createFile(new WorkspacePath("foo/bar/foo_test.go"), "package foo", "import \"testing\"", "func TestFoo(t *testing.T) {}");
    workspace.createFile(new WorkspacePath("foo/bar/bar_test.go"), "package foo", "import \"testing\"", "func TestBar(t *testing.T) {}");
    BuildFile buildFile = (BuildFile) workspace.createPsiFile(new WorkspacePath("foo/bar/BUILD"), "go_test(", "    name = 'foo_test',", "    srcs = [", "        'foo_test.go',", "        'bar_test.go',", "    ],", ")");
    FuncallExpression buildRule = PsiUtils.findFirstChildOfClassRecursive(buildFile, FuncallExpression.class);
    assertThat(buildRule).isNotNull();
    String url = handler.suiteLocationUrl(null, "foo/bar/foo_test");
    Location<?> location = getLocation(url);
    assertThat(location).isNotNull();
    assertThat(location.getPsiElement()).isEqualTo(buildRule);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePathResolverImpl(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Example 75 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class BlazeGoTestEventsHandlerTest method testTopLevelTestTargetResolves.

@Test
public void testTopLevelTestTargetResolves() {
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//:foo_test").setKind("go_test").setBuildFile(src("BUILD")).addSource(src("foo_test.go")).setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("foo_test.go"))).setImportPath("foo"))).build();
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(new BlazeProjectData(0L, targetMap, null, null, new WorkspacePathResolverImpl(workspaceRoot), location -> workspaceRoot.fileForPath(new WorkspacePath(location.getRelativePath())), new WorkspaceLanguageSettings(WorkspaceType.GO, ImmutableSet.of(LanguageClass.GO)), null, null)));
    GoFile goFile = (GoFile) workspace.createPsiFile(new WorkspacePath("foo_test.go"), "package foo", "import \"testing\"", "func TestFoo(t *testing.T) {}");
    workspace.createFile(new WorkspacePath("BUILD"), "go_test(", "    name = 'foo_test',", "    srcs = ['foo_test.go'],", ")");
    String url = handler.suiteLocationUrl(null, "foo_test");
    Location<?> location = getLocation(url);
    assertThat(location).isNotNull();
    assertThat(location.getPsiElement()).isEqualTo(goFile);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) GoFile(com.goide.psi.GoFile) WorkspacePathResolverImpl(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Aggregations

TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)77 Test (org.junit.Test)56 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)33 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)27 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)26 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)17 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)16 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)15 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)12 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)11 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)11 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)10 BlazeSyncParams (com.google.idea.blaze.base.sync.BlazeSyncParams)10 BlazeScalaImportResult (com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult)10 File (java.io.File)10 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)9 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)9 ImmutableList (com.google.common.collect.ImmutableList)8 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)8 ImmutableSet (com.google.common.collect.ImmutableSet)7