Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full sync on build file changes #78

Open
wants to merge 17 commits into
base: wix-master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .bazelrc.remote
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
build --bes_results_url=https://app.buildbuddy.io/invocation/
build --bes_backend=grpcs://cloud.buildbuddy.io
# build --remote_cache=grpcs://cloud.buildbuddy.io

# build --remote_download_minimal
# build --remote_retries=0
# build --remote_timeout=10
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.0.0
28 changes: 28 additions & 0 deletions .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Run all tests
on: [push]
jobs:
build:
name: test with ${{ matrix.ij_product }}
runs-on: ubuntu-20.04
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
ij_product: ['intellij-2022.1', 'intellij-2022.2', 'intellij-2022.3']
experimental: [false]
steps:
- uses: actions/checkout@v2
- name: bazel cache
uses: actions/cache@v2
with:
path: ~/.bazel-repository-cache
key: ${{ github.ref }}
restore-keys: refs/heads/master
- name: run bazel
continue-on-error: ${{ matrix.experimental }}
run: >
bazel --bazelrc=.bazelrc.remote test //:ijwb_ce_tests
--repository_cache=~/.bazel-repository-cache
--define=ij_product=${{ matrix.ij_product }}
--keep_going
--test_output=errors
26 changes: 26 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -641,3 +641,29 @@ jvm_maven_import_external(
licenses = ["notice"], # Apache 2.0
server_urls = ["https://repo1.maven.org/maven2"],
)

bazel_version = "31082327bdb64b7bf52dd55ae18d29e920e61025"

bazel_repo_sha256 = "e8e1ac4bcab303f8f99c9b14ad3afbd059b84c516b7e76f6d9b89b8d5175594f"

http_archive(
name = "bazel",
sha256 = bazel_repo_sha256,
strip_prefix = "bazel-" + bazel_version,
url = "https://github.com/bazelbuild/bazel/archive/%s.zip" % bazel_version,
)

http_archive(
name = "io_buildbuddy_buildbuddy_toolchain",
sha256 = "9055a3e6f45773cd61931eba7b7cf35d6477ab6ad8fb2f18bf9815271fc682fe",
strip_prefix = "buildbuddy-toolchain-52aa5d2cc6c9ba7ee4063de35987be7d1b75f8e2",
urls = ["https://github.com/buildbuddy-io/buildbuddy-toolchain/archive/52aa5d2cc6c9ba7ee4063de35987be7d1b75f8e2.tar.gz"],
)

load("@io_buildbuddy_buildbuddy_toolchain//:deps.bzl", "buildbuddy_deps")

buildbuddy_deps()

load("@io_buildbuddy_buildbuddy_toolchain//:rules.bzl", "buildbuddy")

buildbuddy(name = "buildbuddy_toolchain")
17 changes: 17 additions & 0 deletions aspect/fast_build_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def _fast_build_info_impl(target, ctx):
"workspace_name": ctx.workspace_name,
"label": stringify_label(target.label),
"dependencies": [stringify_label(t.label) for t in dep_targets],
"build_file_path": ctx.build_file_path,
}

write_output = False
Expand All @@ -43,6 +44,9 @@ def _fast_build_info_impl(target, ctx):
elif java_common.JavaToolchainInfo != platform_common.ToolchainInfo and \
java_common.JavaToolchainInfo in target:
toolchain = target[java_common.JavaToolchainInfo]
elif hasattr(ctx.rule.attr, "java_compile_toolchain") and ctx.rule.attr.java_compile_toolchain and \
java_common.JavaToolchainInfo in ctx.rule.attr.java_compile_toolchain:
toolchain = ctx.rule.attr.java_compile_toolchain[java_common.JavaToolchainInfo]
else:
toolchain = None
if toolchain:
Expand All @@ -53,11 +57,17 @@ def _fast_build_info_impl(target, ctx):
bootclasspath_jars = []
if hasattr(toolchain, "bootclasspath"):
bootclasspath_jars = [artifact_location(f) for f in toolchain.bootclasspath.to_list()]
java_runtime = struct()
if hasattr(toolchain, "java_runtime"):
java_runtime = struct_omit_none(
java_executable_exec_path = toolchain.java_runtime.java_executable_exec_path,
)
info["java_toolchain_info"] = struct_omit_none(
javac_jars = javac_jars,
bootclasspath_jars = bootclasspath_jars,
source_version = toolchain.source_version,
target_version = toolchain.target_version,
java_runtime = java_runtime,
)
if JavaInfo in target:
write_output = True
Expand Down Expand Up @@ -92,6 +102,13 @@ def _fast_build_info_impl(target, ctx):
)
info["android_info"] = android_info

if ProtoInfo in target:
write_output = True
proto_info = {
"sources": sources_from_target(ctx),
}
info["proto_info"] = struct_omit_none(**proto_info)

if write_output:
output_file = ctx.actions.declare_file(target.label.name + ".ide-fast-build-info.txt")
ctx.actions.write(output_file, struct_omit_none(**info).to_proto())
Expand Down
26 changes: 20 additions & 6 deletions aspect/intellij_info_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,8 @@ def library_artifact(java_output, rule_kind = None):
return None
src_jars = get_source_jars(java_output)

if rule_kind != None and rule_kind.startswith("scala"):
interface_jar = None
else:
interface_jar = artifact_location(java_output.ijar)

return struct_omit_none(
interface_jar = interface_jar,
interface_jar = None,
jar = artifact_location(java_output.class_jar),
source_jar = artifact_location(src_jars[0]) if src_jars else None,
source_jars = [artifact_location(f) for f in src_jars],
Expand Down Expand Up @@ -328,6 +323,24 @@ def _do_starlark_string_expansion(ctx, name, strings, extra_targets = []):
return strings

##### Builders for individual parts of the aspect output
def collect_proto_info(target, ctx, semantics, ide_info, ide_info_file, output_groups):
if not ProtoInfo in target:
return False

proto_info = target[ProtoInfo]
proto_output = depset([proto_info.direct_descriptor_set])

ide_info["proto_ide_info"] = struct_omit_none(
sources = sources_from_target(ctx),
source_root = proto_info.proto_source_root,
strip_import_prefix = ctx.rule.attr.strip_import_prefix,
import_prefix = ctx.rule.attr.import_prefix,
)

update_sync_output_groups(output_groups, "intellij-info-proto", depset([ide_info_file]))
update_sync_output_groups(output_groups, "intellij-compile-proto", proto_output)
update_sync_output_groups(output_groups, "intellij-resolve-proto", proto_output)
return True

def collect_py_info(target, ctx, semantics, ide_info, ide_info_file, output_groups):
"""Updates Python-specific output groups, returns false if not a Python target."""
Expand Down Expand Up @@ -1123,6 +1136,7 @@ def intellij_info_aspect_impl(target, ctx, semantics):
ide_info["test_info"] = build_test_info(ctx)

handled = False
handled = collect_proto_info(target, ctx, semantics, ide_info, ide_info_file, output_groups) or handled
handled = collect_py_info(target, ctx, semantics, ide_info, ide_info_file, output_groups) or handled
handled = collect_cpp_info(target, ctx, semantics, ide_info, ide_info_file, output_groups) or handled
handled = collect_c_toolchain_info(target, ctx, semantics, ide_info, ide_info_file, output_groups) or handled
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
licenses(["notice"]) # Apache 2.0

load(
"//aspect/testing/rules:intellij_aspect_test_fixture.bzl",
"intellij_aspect_test_fixture",
)

proto_library(
name = "a_proto",
srcs = ["a.proto"],
import_prefix = "test",
strip_import_prefix = "/" + package_name(),
)

proto_library(
name = "b_proto",
srcs = ["b.proto"],
deps = [":a_proto"],
)

intellij_aspect_test_fixture(
name = "fixture",
deps = [":b_proto"],
)

java_test(
name = "ProtoLibraryTest",
srcs = ["ProtoLibraryTest.java"],
data = [
":fixture",
],
deps = [
"//aspect/testing:BazelIntellijAspectTest",
"//aspect/testing:guava",
"//aspect/testing/rules:IntellijAspectTest",
"//aspect/testing/rules:intellij_aspect_test_fixture_java_proto",
"//intellij_platform_sdk:test_libs",
"//proto:intellij_ide_info_java_proto",
"@junit//jar",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2017 The Bazel Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.idea.blaze.aspect.proto.pl;

import com.google.devtools.intellij.IntellijAspectTestFixtureOuterClass.IntellijAspectTestFixture;
import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo;
import com.google.idea.blaze.BazelIntellijAspectTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import static com.google.common.truth.Truth.assertThat;

/** Tests for proto_library. */
@RunWith(JUnit4.class)
public class ProtoLibraryTest extends BazelIntellijAspectTest {

@Test
public void testProtoLibrary() throws Exception {
IntellijAspectTestFixture fixture = loadTestFixture(":fixture");

TargetIdeInfo aProto = findTarget(fixture, ":a_proto");
assertThat(aProto).isNotNull();
assertThat(aProto.hasProtoIdeInfo()).isTrue();
assertThat(relativePathsForArtifacts(aProto.getProtoIdeInfo().getSourcesList()))
.containsExactly(testRelative("a.proto"));
assertThat(aProto.getProtoIdeInfo().getSourceRoot())
.isEqualTo(
"bazel-out/darwin-fastbuild/bin/aspect/testing/tests/src/com/google/idea/blaze/aspect/proto/pl/_virtual_imports/a_proto");
assertThat(aProto.getProtoIdeInfo().getImportPrefix()).isEqualTo("test");
assertThat(aProto.getProtoIdeInfo().getStripImportPrefix())
.isEqualTo("/aspect/testing/tests/src/com/google/idea/blaze/aspect/proto/pl");

TargetIdeInfo bProto = findTarget(fixture, ":b_proto");
assertThat(bProto).isNotNull();
assertThat(bProto.hasProtoIdeInfo()).isTrue();
assertThat(relativePathsForArtifacts(bProto.getProtoIdeInfo().getSourcesList()))
.containsExactly(testRelative("b.proto"));
assertThat(bProto.getProtoIdeInfo().getSourceRoot()).isEqualTo(".");
assertThat(bProto.getProtoIdeInfo().getImportPrefix()).isEmpty();
assertThat(bProto.getProtoIdeInfo().getStripImportPrefix()).isEmpty();
assertThat(dependenciesForTarget(bProto)).contains(dep(aProto));

assertThat(getOutputGroupFiles(fixture, "intellij-info-proto"))
.containsExactly(
testRelative(intellijInfoFileName(aProto.getKey())),
testRelative(intellijInfoFileName(bProto.getKey())));

assertThat(getOutputGroupFiles(fixture, "intellij-compile-proto"))
.containsExactly(
testRelative("a_proto-descriptor-set.proto.bin"),
testRelative("b_proto-descriptor-set.proto.bin"));

assertThat(getOutputGroupFiles(fixture, "intellij-resolve-proto"))
.containsExactly(
testRelative("a_proto-descriptor-set.proto.bin"),
testRelative("b_proto-descriptor-set.proto.bin"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
syntax = "proto2";
package a;
message A {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
syntax = "proto3";
import "test/a.proto";
package b;
message B {a.A a = 1;}
2 changes: 2 additions & 0 deletions base/src/META-INF/blaze-base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@
serviceImplementation="com.google.idea.blaze.base.projectview.ProjectViewStorageManagerImpl"/>
<projectService serviceInterface="com.google.idea.blaze.base.projectview.ProjectViewManager"
serviceImplementation="com.google.idea.blaze.base.projectview.ProjectViewManagerImpl"/>
<projectService serviceInterface="com.google.idea.blaze.base.prelude.PreludeManager"
serviceImplementation="com.google.idea.blaze.base.prelude.PreludeManagerImpl"/>
<applicationService serviceInterface="com.google.idea.blaze.base.sync.aspects.BlazeIdeInterface"
serviceImplementation="com.google.idea.blaze.base.sync.aspects.BlazeIdeInterfaceAspectsImpl"/>
<projectService serviceInterface="com.google.idea.blaze.base.toolwindow.TasksToolWindowService"
Expand Down
31 changes: 29 additions & 2 deletions base/src/com/google/idea/blaze/base/actions/BuildFileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,21 @@
import com.google.idea.blaze.base.lang.buildfile.search.BlazePackage;
import com.google.idea.blaze.base.model.BlazeProjectData;
import com.google.idea.blaze.base.model.primitives.Label;
import com.google.idea.blaze.base.model.primitives.LanguageClass;
import com.google.idea.blaze.base.model.primitives.WorkspacePath;
import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager;
import com.google.idea.blaze.base.targetmaps.SourceToTargetMap;
import com.google.idea.common.experiments.BoolExperiment;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFileSystemItem;
import com.intellij.psi.PsiManager;
import java.io.File;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Stream;
import javax.annotation.Nullable;

/** BUILD-file utility methods used by actions. */
Expand Down Expand Up @@ -74,9 +77,11 @@ static PsiElement findBuildTarget(Project project, BlazePackage parentPackage, F
if (packagePath == null) {
return null;
}
final Stream<Label> targetLabels = SourceToTargetMap.getInstance(project)
.getTargetsToBuildForSourceFile(file).stream();

Label label =
SourceToTargetMap.getInstance(project).getTargetsToBuildForSourceFile(file).stream()
.filter(l -> l.blazePackage().equals(packagePath))
filterCRelatedLabelsWhichBelongToOtherPackages(file,packagePath, targetLabels)
.findFirst()
.orElse(null);
if (label == null) {
Expand All @@ -98,6 +103,28 @@ static PsiElement findBuildTarget(Project project, BlazePackage parentPackage, F
return null;
}

private static Stream<Label> filterCRelatedLabelsWhichBelongToOtherPackages(File file,
WorkspacePath packagePath, Stream<Label> targetLabels) {
/*
More info:
https://bazelbuild.slack.com/archives/CM8JQCANN/p1566481600003600
Filter was deliberately added to fix an issue with C++ headers.
The original bug was that opening the BUILD file for foo/bar.h caused it to open baz/qux/BUILD
because there’s a cc_library target in baz/qux that includes foo/bar.h in its headers.
The source-to-target look up queries the index for the target during the last sync which compiled the source file.
In this case, it was the cc_library target in baz/qux.
So the fix was to ensure that the BUILD file is always for the parent package (foo/bar).

This is limited to C only since this logic messes up supporting aggregate targets
https://github.com/bazelbuild/intellij/issues/475
*/
LanguageClass fileLanguage = LanguageClass.fromExtension(
FileUtilRt.getExtension(file.getName()).toLowerCase());
return (fileLanguage == LanguageClass.C) ?
targetLabels.filter(l -> l.blazePackage().equals(packagePath)) :
targetLabels;
}

/**
* Returns the label of a macro with name prefixing the target name of a given label with a '_' or
* '-' delimiter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ default ImmutableList<FileNameMatcher> buildLanguageFileTypeMatchers() {
possibleBuildFileNames().forEach(s -> list.add(new ExactFileNameMatcher(s)));
possibleWorkspaceFileNames().forEach(s -> list.add(new ExactFileNameMatcher(s)));
possibleFileExtensions().forEach(s -> list.add(new ExtensionFileNameMatcher(s)));
list.add(new ExactFileNameMatcher("prelude_bazel"));
return list.build();
}

Expand Down
Loading