diff --git a/.bazelrc b/.bazelrc index 4acbd8f785f..313bdaa1e61 100644 --- a/.bazelrc +++ b/.bazelrc @@ -3,8 +3,8 @@ build --tool_java_language_version=21 --tool_java_runtime_version=21 # Delete test data packages, needed for bazel integration tests. Update by running the following command: # bazel run @rules_bazel_integration_test//tools:update_deleted_packages -build --deleted_packages=.bazelbsp,.bazelbsp/aspects,aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/testdata,clwb/tests/projects/clang_cl,clwb/tests/projects/clang_cl/main,clwb/tests/projects/execution/main,clwb/tests/projects/external_includes/main,clwb/tests/projects/llvm_toolchain/main,clwb/tests/projects/llvm_toolchain/wasm,clwb/tests/projects/query_sync/main,clwb/tests/projects/simple/main,clwb/tests/projects/target_compatible/main,clwb/tests/projects/virtual_includes/.clwb/aspects,clwb/tests/projects/virtual_includes/lib/impl_deps,clwb/tests/projects/virtual_includes/lib/raw_files,clwb/tests/projects/virtual_includes/lib/strip_absolut,clwb/tests/projects/virtual_includes/lib/strip_relative,clwb/tests/projects/virtual_includes/main,examples/cpp/simple_project/.clwb/aspects,examples/cpp/simple_project/src,examples/cpp/simple_project/src/lib,examples/go/with_go_source,examples/go/with_go_source/otherlib,examples/go/with_go_source/testa,examples/go/with_go_source/testb,examples/go/with_proto,examples/go/with_proto/go,examples/go/with_proto/go/external,examples/go/with_proto/go/lib,examples/go/with_proto/proto,examples/java/greetings_project,examples/java/greetings_project/.ijwb/aspects,examples/java/greetings_project/greeting_lib,examples/java/greetings_project/hello,examples/java/greetings_project/hi,examples/kotlin/simple_project,examples/python/simple_code_generator/example,examples/python/simple_code_generator/generated,examples/python/simple_code_generator/lib,examples/python/simple_code_generator/rules,examples/python/with_numpy,examples/python/with_numpy/app,examples/python/with_numpy/lib,examples/scala/with_bzlmod/hello,ijwb/tests/projects/simple,testing/test_deps/projects,testing/test_deps/projects/java_and_deps,testing/test_deps/projects/java_and_deps/deps/no_ide,testing/test_deps/projects/java_and_deps/deps/top_level_lib_1,testing/test_deps/projects/java_and_deps/deps/top_level_lib_2,testing/test_deps/projects/java_and_deps/deps/transitive_dep_lib,testing/test_deps/projects/java_and_deps/project,testing/test_deps/projects/java_and_deps/project/java/com/example/sample/nested,testing/test_deps/projects/simple_java,testing/test_deps/projects/simple_java/java/com/example/sample/nested,testing/test_deps/projects/simple_proto/external,testing/test_deps/projects/simple_proto/project -query --deleted_packages=.bazelbsp,.bazelbsp/aspects,aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/testdata,clwb/tests/projects/clang_cl,clwb/tests/projects/clang_cl/main,clwb/tests/projects/execution/main,clwb/tests/projects/external_includes/main,clwb/tests/projects/llvm_toolchain/main,clwb/tests/projects/llvm_toolchain/wasm,clwb/tests/projects/query_sync/main,clwb/tests/projects/simple/main,clwb/tests/projects/target_compatible/main,clwb/tests/projects/virtual_includes/.clwb/aspects,clwb/tests/projects/virtual_includes/lib/impl_deps,clwb/tests/projects/virtual_includes/lib/raw_files,clwb/tests/projects/virtual_includes/lib/strip_absolut,clwb/tests/projects/virtual_includes/lib/strip_relative,clwb/tests/projects/virtual_includes/main,examples/cpp/simple_project/.clwb/aspects,examples/cpp/simple_project/src,examples/cpp/simple_project/src/lib,examples/go/with_go_source,examples/go/with_go_source/otherlib,examples/go/with_go_source/testa,examples/go/with_go_source/testb,examples/go/with_proto,examples/go/with_proto/go,examples/go/with_proto/go/external,examples/go/with_proto/go/lib,examples/go/with_proto/proto,examples/java/greetings_project,examples/java/greetings_project/.ijwb/aspects,examples/java/greetings_project/greeting_lib,examples/java/greetings_project/hello,examples/java/greetings_project/hi,examples/kotlin/simple_project,examples/python/simple_code_generator/example,examples/python/simple_code_generator/generated,examples/python/simple_code_generator/lib,examples/python/simple_code_generator/rules,examples/python/with_numpy,examples/python/with_numpy/app,examples/python/with_numpy/lib,examples/scala/with_bzlmod/hello,ijwb/tests/projects/simple,testing/test_deps/projects,testing/test_deps/projects/java_and_deps,testing/test_deps/projects/java_and_deps/deps/no_ide,testing/test_deps/projects/java_and_deps/deps/top_level_lib_1,testing/test_deps/projects/java_and_deps/deps/top_level_lib_2,testing/test_deps/projects/java_and_deps/deps/transitive_dep_lib,testing/test_deps/projects/java_and_deps/project,testing/test_deps/projects/java_and_deps/project/java/com/example/sample/nested,testing/test_deps/projects/simple_java,testing/test_deps/projects/simple_java/java/com/example/sample/nested,testing/test_deps/projects/simple_proto/external,testing/test_deps/projects/simple_proto/project +build --deleted_packages=clwb/tests/projects/clang_cl,clwb/tests/projects/clang_cl/main,clwb/tests/projects/execution/main,clwb/tests/projects/external_includes/main,clwb/tests/projects/llvm_toolchain/main,clwb/tests/projects/llvm_toolchain/wasm,clwb/tests/projects/protobuf,clwb/tests/projects/protobuf/main,clwb/tests/projects/protobuf/proto,clwb/tests/projects/simple/.clwb/aspects,clwb/tests/projects/simple/main,clwb/tests/projects/target_compatible/main,clwb/tests/projects/virtual_includes/.clwb/aspects,clwb/tests/projects/virtual_includes/lib/impl_deps,clwb/tests/projects/virtual_includes/lib/raw_files,clwb/tests/projects/virtual_includes/lib/strip_absolut,clwb/tests/projects/virtual_includes/lib/strip_relative,clwb/tests/projects/virtual_includes/lib/transitive,clwb/tests/projects/virtual_includes/main,clwb/tests/projects/virtual_includes/third_party/sqlite,examples/cpp/simple_project/.clwb/aspects,examples/cpp/simple_project/src,examples/cpp/simple_project/src/lib,examples/python/simple_code_generator/example,examples/python/simple_code_generator/generated,examples/python/simple_code_generator/lib,examples/python/simple_code_generator/rules,examples/python/with_numpy,examples/python/with_numpy/app,examples/python/with_numpy/lib +query --deleted_packages=clwb/tests/projects/clang_cl,clwb/tests/projects/clang_cl/main,clwb/tests/projects/execution/main,clwb/tests/projects/external_includes/main,clwb/tests/projects/llvm_toolchain/main,clwb/tests/projects/llvm_toolchain/wasm,clwb/tests/projects/protobuf,clwb/tests/projects/protobuf/main,clwb/tests/projects/protobuf/proto,clwb/tests/projects/simple/.clwb/aspects,clwb/tests/projects/simple/main,clwb/tests/projects/target_compatible/main,clwb/tests/projects/virtual_includes/.clwb/aspects,clwb/tests/projects/virtual_includes/lib/impl_deps,clwb/tests/projects/virtual_includes/lib/raw_files,clwb/tests/projects/virtual_includes/lib/strip_absolut,clwb/tests/projects/virtual_includes/lib/strip_relative,clwb/tests/projects/virtual_includes/lib/transitive,clwb/tests/projects/virtual_includes/main,clwb/tests/projects/virtual_includes/third_party/sqlite,examples/cpp/simple_project/.clwb/aspects,examples/cpp/simple_project/src,examples/cpp/simple_project/src/lib,examples/python/simple_code_generator/example,examples/python/simple_code_generator/generated,examples/python/simple_code_generator/lib,examples/python/simple_code_generator/rules,examples/python/with_numpy,examples/python/with_numpy/app,examples/python/with_numpy/lib common --enable_bzlmod common --noincompatible_disallow_empty_glob diff --git a/MODULE.bazel b/MODULE.bazel index d02cacfca37..ca2db39982f 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -55,14 +55,25 @@ single_version_override( register_toolchains("//third_party/kotlin:toolchain") +# required for aspect integration tests bazel_dep( - name = "rules_shell", - version = "0.6.1", + name = "rules_cc", + version = "0.2.8", dev_dependency = True, ) bazel_dep( - name = "rules_cc", - version = "0.2.8", + name = "rules_foreign_cc", + version = "0.15.0", + dev_dependency = True, +) +bazel_dep( + name = "abseil-cpp", + version = "20250814.0", + dev_dependency = True, +) +bazel_dep( + name = "rules_shell", + version = "0.6.1", dev_dependency = True, ) bazel_dep( @@ -240,13 +251,3 @@ http_archive( sha256 = PYTHON_PLUGIN_253_SHA, url = PYTHON_PLUGIN_253_URL, ) - -# needed for cpp tests -http_archive( - name = "com_google_absl", - sha256 = "f50e5ac311a81382da7fa75b97310e4b9006474f9560ac46f54a9967f07d4ae3", - strip_prefix = "abseil-cpp-20240722.0", - urls = [ - "https://github.com/abseil/abseil-cpp/archive/refs/tags/20240722.0.tar.gz", - ], -) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 98a1898d1b8..d015e18e430 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -51,7 +51,8 @@ "https://bcr.bazel.build/modules/bazel_skylib/1.7.0/MODULE.bazel": "0db596f4563de7938de764cc8deeabec291f55e8ec15299718b93c4423e9796d", "https://bcr.bazel.build/modules/bazel_skylib/1.7.1/MODULE.bazel": "3120d80c5861aa616222ec015332e5f8d3171e062e3e804a2a0253e1be26e59b", "https://bcr.bazel.build/modules/bazel_skylib/1.8.1/MODULE.bazel": "88ade7293becda963e0e3ea33e7d54d3425127e0a326e0d17da085a5f1f03ff6", - "https://bcr.bazel.build/modules/bazel_skylib/1.8.1/source.json": "7ebaefba0b03efe59cac88ed5bbc67bcf59a3eff33af937345ede2a38b2d368a", + "https://bcr.bazel.build/modules/bazel_skylib/1.8.2/MODULE.bazel": "69ad6927098316848b34a9142bcc975e018ba27f08c4ff403f50c1b6e646ca67", + "https://bcr.bazel.build/modules/bazel_skylib/1.8.2/source.json": "34a3c8bcf233b835eb74be9d628899bb32999d3e0eadef1947a0a562a2b16ffb", "https://bcr.bazel.build/modules/bazel_worker_api/0.0.1/MODULE.bazel": "02a13b77321773b2042e70ee5e4c5e099c8ddee4cf2da9cd420442c36938d4bd", "https://bcr.bazel.build/modules/bazel_worker_api/0.0.4/MODULE.bazel": "460aa12d01231a80cce03c548287b433b321d205b0028ae596728c35e5ee442e", "https://bcr.bazel.build/modules/bazel_worker_api/0.0.4/source.json": "d353c410d47a8b65d09fa98e83d57ebec257a2c2b9c6e42d6fda1cb25e5464a5", @@ -138,6 +139,8 @@ "https://bcr.bazel.build/modules/rules_cc/0.2.0/MODULE.bazel": "b5c17f90458caae90d2ccd114c81970062946f49f355610ed89bebf954f5783c", "https://bcr.bazel.build/modules/rules_cc/0.2.8/MODULE.bazel": "f1df20f0bf22c28192a794f29b501ee2018fa37a3862a1a2132ae2940a23a642", "https://bcr.bazel.build/modules/rules_cc/0.2.8/source.json": "85087982aca15f31307bd52698316b28faa31bd2c3095a41f456afec0131344c", + "https://bcr.bazel.build/modules/rules_foreign_cc/0.15.0/MODULE.bazel": "fddf47051761cdbbe950bdcf3047e68540f48a63c8329e6ed0605d6007fd9334", + "https://bcr.bazel.build/modules/rules_foreign_cc/0.15.0/source.json": "563eee5c2d0195d71caf2f5869e3ce20dd690aa96ffb9d9da255a4f9eb0339bd", "https://bcr.bazel.build/modules/rules_foreign_cc/0.9.0/MODULE.bazel": "c9e8c682bf75b0e7c704166d79b599f93b72cfca5ad7477df596947891feeef6", "https://bcr.bazel.build/modules/rules_fuzzing/0.5.2/MODULE.bazel": "40c97d1144356f52905566c55811f13b299453a14ac7769dfba2ac38192337a8", "https://bcr.bazel.build/modules/rules_go/0.41.0/MODULE.bazel": "55861d8e8bb0e62cbd2896f60ff303f62ffcb0eddb74ecb0e5c0cbe36fc292c8", @@ -213,6 +216,7 @@ "https://bcr.bazel.build/modules/rules_python/0.4.0/MODULE.bazel": "9208ee05fd48bf09ac60ed269791cf17fb343db56c8226a720fbb1cdf467166c", "https://bcr.bazel.build/modules/rules_python/0.40.0/MODULE.bazel": "9d1a3cd88ed7d8e39583d9ffe56ae8a244f67783ae89b60caafc9f5cf318ada7", "https://bcr.bazel.build/modules/rules_python/1.0.0/MODULE.bazel": "898a3d999c22caa585eb062b600f88654bf92efb204fa346fb55f6f8edffca43", + "https://bcr.bazel.build/modules/rules_python/1.2.0/MODULE.bazel": "5aeeb48b2a6c19d668b48adf2b8a2b209a6310c230db0ce77450f148a89846e4", "https://bcr.bazel.build/modules/rules_python/1.4.1/MODULE.bazel": "8991ad45bdc25018301d6b7e1d3626afc3c8af8aaf4bc04f23d0b99c938b73a6", "https://bcr.bazel.build/modules/rules_python/1.6.3/MODULE.bazel": "a7b80c42cb3de5ee2a5fa1abc119684593704fcd2fec83165ebe615dec76574f", "https://bcr.bazel.build/modules/rules_python/1.6.3/source.json": "f0be74977e5604a6526c8a416cda22985093ff7d5d380d41722d7e44015cc419", @@ -505,7 +509,7 @@ }, "@@rules_apple+//apple:apple.bzl%provisioning_profile_repository_extension": { "general": { - "bzlTransitiveDigest": "Rb15CUkaGgiSP6NNN0OHHFc8jtP7Qq9ioXem8lmY4Ec=", + "bzlTransitiveDigest": "eVzyeT0wtszNEyCDTNCqNnCFIIhGkAIayc8bRxl37Hs=", "usagesDigest": "vsJl8Rw5NL+5Ag2wdUDoTeRF/5klkXO8545Iy7U1Q08=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -695,6 +699,346 @@ ] } }, + "@@rules_foreign_cc+//foreign_cc:extensions.bzl%tools": { + "general": { + "bzlTransitiveDigest": "g6eqFMwHN2rVvQLs8u4iibhBwHiaS/K+PAC7pNBtkYI=", + "usagesDigest": "PKJ/4yUmwmF/SjJ2HH9Xrp2gl5+NxehlhcdWxBLeWLI=", + "recordedFileInputs": {}, + "recordedDirentsInputs": {}, + "envVariables": {}, + "generatedRepoSpecs": { + "rules_foreign_cc_framework_toolchain_linux": { + "repoRuleId": "@@rules_foreign_cc+//foreign_cc/private/framework:toolchain.bzl%framework_toolchain_repository", + "attributes": { + "commands_src": "@rules_foreign_cc//foreign_cc/private/framework/toolchains:linux_commands.bzl", + "exec_compatible_with": [ + "@platforms//os:linux" + ] + } + }, + "rules_foreign_cc_framework_toolchain_freebsd": { + "repoRuleId": "@@rules_foreign_cc+//foreign_cc/private/framework:toolchain.bzl%framework_toolchain_repository", + "attributes": { + "commands_src": "@rules_foreign_cc//foreign_cc/private/framework/toolchains:freebsd_commands.bzl", + "exec_compatible_with": [ + "@platforms//os:freebsd" + ] + } + }, + "rules_foreign_cc_framework_toolchain_windows": { + "repoRuleId": "@@rules_foreign_cc+//foreign_cc/private/framework:toolchain.bzl%framework_toolchain_repository", + "attributes": { + "commands_src": "@rules_foreign_cc//foreign_cc/private/framework/toolchains:windows_commands.bzl", + "exec_compatible_with": [ + "@platforms//os:windows" + ] + } + }, + "rules_foreign_cc_framework_toolchain_macos": { + "repoRuleId": "@@rules_foreign_cc+//foreign_cc/private/framework:toolchain.bzl%framework_toolchain_repository", + "attributes": { + "commands_src": "@rules_foreign_cc//foreign_cc/private/framework/toolchains:macos_commands.bzl", + "exec_compatible_with": [ + "@platforms//os:macos" + ] + } + }, + "rules_foreign_cc_framework_toolchains": { + "repoRuleId": "@@rules_foreign_cc+//foreign_cc/private/framework:toolchain.bzl%framework_toolchain_repository_hub", + "attributes": {} + }, + "cmake_src": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "filegroup(\n name = \"all_srcs\",\n srcs = glob([\"**\"]),\n visibility = [\"//visibility:public\"],\n)\n", + "sha256": "a6d2eb1ebeb99130dfe63ef5a340c3fdb11431cce3d7ca148524c125924cea68", + "strip_prefix": "cmake-3.31.7", + "urls": [ + "https://github.com/Kitware/CMake/releases/download/v3.31.7/cmake-3.31.7.tar.gz" + ], + "patches": [ + "@@rules_foreign_cc+//toolchains/patches:cmake-c++11.patch" + ] + } + }, + "gnumake_src": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "filegroup(\n name = \"all_srcs\",\n srcs = glob([\"**\"]),\n visibility = [\"//visibility:public\"],\n)\n", + "sha256": "dd16fb1d67bfab79a72f5e8390735c49e3e8e70b4945a15ab1f81ddb78658fb3", + "strip_prefix": "make-4.4.1", + "urls": [ + "https://mirror.bazel.build/ftpmirror.gnu.org/gnu/make/make-4.4.1.tar.gz", + "http://ftpmirror.gnu.org/gnu/make/make-4.4.1.tar.gz" + ] + } + }, + "ninja_build_src": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "filegroup(\n name = \"all_srcs\",\n srcs = glob([\"**\"]),\n visibility = [\"//visibility:public\"],\n)\n", + "integrity": "sha256-ghvf9Io/aDvEuztvC1/nstZHz2XVKutjMoyRpsbfKFo=", + "strip_prefix": "ninja-1.12.1", + "urls": [ + "https://mirror.bazel.build/github.com/ninja-build/ninja/archive/v1.12.1.tar.gz", + "https://github.com/ninja-build/ninja/archive/v1.12.1.tar.gz" + ] + } + }, + "meson_src": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "exports_files([\"meson.py\"])\n\nfilegroup(\n name = \"runtime\",\n # NOTE: excluding __pycache__ is important to avoid rebuilding due to pyc\n # files, see https://github.com/bazel-contrib/rules_foreign_cc/issues/1342\n srcs = glob([\"mesonbuild/**\"], exclude = [\"**/__pycache__/*\"]),\n visibility = [\"//visibility:public\"],\n)\n", + "sha256": "567e533adf255de73a2de35049b99923caf872a455af9ce03e01077e0d384bed", + "strip_prefix": "meson-1.5.1", + "urls": [ + "https://mirror.bazel.build/github.com/mesonbuild/meson/releases/download/1.5.1/meson-1.5.1.tar.gz", + "https://github.com/mesonbuild/meson/releases/download/1.5.1/meson-1.5.1.tar.gz" + ] + } + }, + "glib_dev": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "\ncc_import(\n name = \"glib_dev\",\n hdrs = glob([\"include/**\"]),\n shared_library = \"@glib_runtime//:bin/libglib-2.0-0.dll\",\n visibility = [\"//visibility:public\"],\n)\n ", + "sha256": "bdf18506df304d38be98a4b3f18055b8b8cca81beabecad0eece6ce95319c369", + "urls": [ + "https://mirror.bazel.build/download.gnome.org/binaries/win64/glib/2.26/glib-dev_2.26.1-1_win64.zip", + "https://download.gnome.org/binaries/win64/glib/2.26/glib-dev_2.26.1-1_win64.zip" + ] + } + }, + "glib_src": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "\ncc_import(\n name = \"msvc_hdr\",\n hdrs = [\"msvc_recommended_pragmas.h\"],\n visibility = [\"//visibility:public\"],\n)\n ", + "sha256": "bc96f63112823b7d6c9f06572d2ad626ddac7eb452c04d762592197f6e07898e", + "strip_prefix": "glib-2.26.1", + "urls": [ + "https://mirror.bazel.build/download.gnome.org/sources/glib/2.26/glib-2.26.1.tar.gz", + "https://download.gnome.org/sources/glib/2.26/glib-2.26.1.tar.gz" + ] + } + }, + "glib_runtime": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "\nexports_files(\n [\n \"bin/libgio-2.0-0.dll\",\n \"bin/libglib-2.0-0.dll\",\n \"bin/libgmodule-2.0-0.dll\",\n \"bin/libgobject-2.0-0.dll\",\n \"bin/libgthread-2.0-0.dll\",\n ],\n visibility = [\"//visibility:public\"],\n)\n ", + "sha256": "88d857087e86f16a9be651ee7021880b3f7ba050d34a1ed9f06113b8799cb973", + "urls": [ + "https://mirror.bazel.build/download.gnome.org/binaries/win64/glib/2.26/glib_2.26.1-1_win64.zip", + "https://download.gnome.org/binaries/win64/glib/2.26/glib_2.26.1-1_win64.zip" + ] + } + }, + "gettext_runtime": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "\ncc_import(\n name = \"gettext_runtime\",\n shared_library = \"bin/libintl-8.dll\",\n visibility = [\"//visibility:public\"],\n)\n ", + "sha256": "1f4269c0e021076d60a54e98da6f978a3195013f6de21674ba0edbc339c5b079", + "urls": [ + "https://mirror.bazel.build/download.gnome.org/binaries/win64/dependencies/gettext-runtime_0.18.1.1-2_win64.zip", + "https://download.gnome.org/binaries/win64/dependencies/gettext-runtime_0.18.1.1-2_win64.zip" + ] + } + }, + "pkgconfig_src": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "filegroup(\n name = \"all_srcs\",\n srcs = glob([\"**\"]),\n visibility = [\"//visibility:public\"],\n)\n", + "sha256": "6fc69c01688c9458a57eb9a1664c9aba372ccda420a02bf4429fe610e7e7d591", + "strip_prefix": "pkg-config-0.29.2", + "patches": [ + "@@rules_foreign_cc+//toolchains/patches:pkgconfig-detectenv.patch", + "@@rules_foreign_cc+//toolchains/patches:pkgconfig-makefile-vc.patch", + "@@rules_foreign_cc+//toolchains/patches:pkgconfig-builtin-glib-int-conversion.patch" + ], + "urls": [ + "https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz", + "https://mirror.bazel.build/pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz" + ] + } + }, + "cmake-3.31.7-linux-aarch64": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "urls": [ + "https://github.com/Kitware/CMake/releases/download/v3.31.7/cmake-3.31.7-linux-aarch64.tar.gz" + ], + "sha256": "e5b2dc2aefdca10afe09c8fa4ee2bbb4e732665943a94322f99c118781910c3c", + "strip_prefix": "cmake-3.31.7-linux-aarch64", + "build_file_content": "load(\"@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl\", \"native_tool_toolchain\")\n\npackage(default_visibility = [\"//visibility:public\"])\n\nfilegroup(\n name = \"cmake_bin\",\n srcs = [\"bin/cmake\"],\n)\n\nfilegroup(\n name = \"cmake_data\",\n srcs = glob(\n [\n \"**\",\n ],\n exclude = [\n \"WORKSPACE\",\n \"WORKSPACE.bazel\",\n \"BUILD\",\n \"BUILD.bazel\",\n \"**/* *\",\n ],\n ),\n)\n\nnative_tool_toolchain(\n name = \"cmake_tool\",\n path = \"bin/cmake\",\n target = \":cmake_data\",\n env = {\"CMAKE\": \"$(execpath :cmake_bin)\"},\n tools = [\":cmake_bin\"],\n)\n" + } + }, + "cmake-3.31.7-linux-x86_64": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "urls": [ + "https://github.com/Kitware/CMake/releases/download/v3.31.7/cmake-3.31.7-linux-x86_64.tar.gz" + ], + "sha256": "14e15d0b445dbeac686acc13fe13b3135e8307f69ccf4c5c91403996ce5aa2d4", + "strip_prefix": "cmake-3.31.7-linux-x86_64", + "build_file_content": "load(\"@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl\", \"native_tool_toolchain\")\n\npackage(default_visibility = [\"//visibility:public\"])\n\nfilegroup(\n name = \"cmake_bin\",\n srcs = [\"bin/cmake\"],\n)\n\nfilegroup(\n name = \"cmake_data\",\n srcs = glob(\n [\n \"**\",\n ],\n exclude = [\n \"WORKSPACE\",\n \"WORKSPACE.bazel\",\n \"BUILD\",\n \"BUILD.bazel\",\n \"**/* *\",\n ],\n ),\n)\n\nnative_tool_toolchain(\n name = \"cmake_tool\",\n path = \"bin/cmake\",\n target = \":cmake_data\",\n env = {\"CMAKE\": \"$(execpath :cmake_bin)\"},\n tools = [\":cmake_bin\"],\n)\n" + } + }, + "cmake-3.31.7-macos-universal": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "urls": [ + "https://github.com/Kitware/CMake/releases/download/v3.31.7/cmake-3.31.7-macos-universal.tar.gz" + ], + "sha256": "1cb11aa2edae8551bb0f22807c6f5246bd0eb60ae9fa1474781eb4095d299aca", + "strip_prefix": "cmake-3.31.7-macos-universal/CMake.app/Contents", + "build_file_content": "load(\"@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl\", \"native_tool_toolchain\")\n\npackage(default_visibility = [\"//visibility:public\"])\n\nfilegroup(\n name = \"cmake_bin\",\n srcs = [\"bin/cmake\"],\n)\n\nfilegroup(\n name = \"cmake_data\",\n srcs = glob(\n [\n \"**\",\n ],\n exclude = [\n \"WORKSPACE\",\n \"WORKSPACE.bazel\",\n \"BUILD\",\n \"BUILD.bazel\",\n \"**/* *\",\n ],\n ),\n)\n\nnative_tool_toolchain(\n name = \"cmake_tool\",\n path = \"bin/cmake\",\n target = \":cmake_data\",\n env = {\"CMAKE\": \"$(execpath :cmake_bin)\"},\n tools = [\":cmake_bin\"],\n)\n" + } + }, + "cmake-3.31.7-windows-i386": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "urls": [ + "https://github.com/Kitware/CMake/releases/download/v3.31.7/cmake-3.31.7-windows-i386.zip" + ], + "sha256": "9d545715a45efb5fada0e687ec274629c590296037f21181c30ea5c2e079277e", + "strip_prefix": "cmake-3.31.7-windows-i386", + "build_file_content": "load(\"@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl\", \"native_tool_toolchain\")\n\npackage(default_visibility = [\"//visibility:public\"])\n\nfilegroup(\n name = \"cmake_bin\",\n srcs = [\"bin/cmake.exe\"],\n)\n\nfilegroup(\n name = \"cmake_data\",\n srcs = glob(\n [\n \"**\",\n ],\n exclude = [\n \"WORKSPACE\",\n \"WORKSPACE.bazel\",\n \"BUILD\",\n \"BUILD.bazel\",\n \"**/* *\",\n ],\n ),\n)\n\nnative_tool_toolchain(\n name = \"cmake_tool\",\n path = \"bin/cmake.exe\",\n target = \":cmake_data\",\n env = {\"CMAKE\": \"$(execpath :cmake_bin)\"},\n tools = [\":cmake_bin\"],\n)\n" + } + }, + "cmake-3.31.7-windows-x86_64": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "urls": [ + "https://github.com/Kitware/CMake/releases/download/v3.31.7/cmake-3.31.7-windows-x86_64.zip" + ], + "sha256": "ab1c7f46a1b1314f9fcb766c2573148679af599d94c5566bc12b8b35bb563362", + "strip_prefix": "cmake-3.31.7-windows-x86_64", + "build_file_content": "load(\"@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl\", \"native_tool_toolchain\")\n\npackage(default_visibility = [\"//visibility:public\"])\n\nfilegroup(\n name = \"cmake_bin\",\n srcs = [\"bin/cmake.exe\"],\n)\n\nfilegroup(\n name = \"cmake_data\",\n srcs = glob(\n [\n \"**\",\n ],\n exclude = [\n \"WORKSPACE\",\n \"WORKSPACE.bazel\",\n \"BUILD\",\n \"BUILD.bazel\",\n \"**/* *\",\n ],\n ),\n)\n\nnative_tool_toolchain(\n name = \"cmake_tool\",\n path = \"bin/cmake.exe\",\n target = \":cmake_data\",\n env = {\"CMAKE\": \"$(execpath :cmake_bin)\"},\n tools = [\":cmake_bin\"],\n)\n" + } + }, + "cmake_3.31.7_toolchains": { + "repoRuleId": "@@rules_foreign_cc+//toolchains:prebuilt_toolchains_repository.bzl%prebuilt_toolchains_repository", + "attributes": { + "repos": { + "cmake-3.31.7-linux-aarch64": [ + "@platforms//cpu:aarch64", + "@platforms//os:linux" + ], + "cmake-3.31.7-linux-x86_64": [ + "@platforms//cpu:x86_64", + "@platforms//os:linux" + ], + "cmake-3.31.7-macos-universal": [ + "@platforms//os:macos" + ], + "cmake-3.31.7-windows-i386": [ + "@platforms//cpu:x86_32", + "@platforms//os:windows" + ], + "cmake-3.31.7-windows-x86_64": [ + "@platforms//cpu:x86_64", + "@platforms//os:windows" + ] + }, + "tool": "cmake" + } + }, + "ninja_1.12.1_linux": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "urls": [ + "https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-linux.zip" + ], + "sha256": "6f98805688d19672bd699fbbfa2c2cf0fc054ac3df1f0e6a47664d963d530255", + "strip_prefix": "", + "build_file_content": "load(\"@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl\", \"native_tool_toolchain\")\n\npackage(default_visibility = [\"//visibility:public\"])\n\nfilegroup(\n name = \"ninja_bin\",\n srcs = [\"ninja\"],\n)\n\nnative_tool_toolchain(\n name = \"ninja_tool\",\n env = {\"NINJA\": \"$(execpath :ninja_bin)\"},\n path = \"$(execpath :ninja_bin)\",\n target = \":ninja_bin\",\n)\n" + } + }, + "ninja_1.12.1_linux-aarch64": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "urls": [ + "https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-linux-aarch64.zip" + ], + "sha256": "5c25c6570b0155e95fce5918cb95f1ad9870df5768653afe128db822301a05a1", + "strip_prefix": "", + "build_file_content": "load(\"@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl\", \"native_tool_toolchain\")\n\npackage(default_visibility = [\"//visibility:public\"])\n\nfilegroup(\n name = \"ninja_bin\",\n srcs = [\"ninja\"],\n)\n\nnative_tool_toolchain(\n name = \"ninja_tool\",\n env = {\"NINJA\": \"$(execpath :ninja_bin)\"},\n path = \"$(execpath :ninja_bin)\",\n target = \":ninja_bin\",\n)\n" + } + }, + "ninja_1.12.1_mac": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "urls": [ + "https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-mac.zip" + ], + "sha256": "89a287444b5b3e98f88a945afa50ce937b8ffd1dcc59c555ad9b1baf855298c9", + "strip_prefix": "", + "build_file_content": "load(\"@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl\", \"native_tool_toolchain\")\n\npackage(default_visibility = [\"//visibility:public\"])\n\nfilegroup(\n name = \"ninja_bin\",\n srcs = [\"ninja\"],\n)\n\nnative_tool_toolchain(\n name = \"ninja_tool\",\n env = {\"NINJA\": \"$(execpath :ninja_bin)\"},\n path = \"$(execpath :ninja_bin)\",\n target = \":ninja_bin\",\n)\n" + } + }, + "ninja_1.12.1_mac_aarch64": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "urls": [ + "https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-mac.zip" + ], + "sha256": "89a287444b5b3e98f88a945afa50ce937b8ffd1dcc59c555ad9b1baf855298c9", + "strip_prefix": "", + "build_file_content": "load(\"@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl\", \"native_tool_toolchain\")\n\npackage(default_visibility = [\"//visibility:public\"])\n\nfilegroup(\n name = \"ninja_bin\",\n srcs = [\"ninja\"],\n)\n\nnative_tool_toolchain(\n name = \"ninja_tool\",\n env = {\"NINJA\": \"$(execpath :ninja_bin)\"},\n path = \"$(execpath :ninja_bin)\",\n target = \":ninja_bin\",\n)\n" + } + }, + "ninja_1.12.1_win": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "urls": [ + "https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-win.zip" + ], + "sha256": "f550fec705b6d6ff58f2db3c374c2277a37691678d6aba463adcbb129108467a", + "strip_prefix": "", + "build_file_content": "load(\"@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl\", \"native_tool_toolchain\")\n\npackage(default_visibility = [\"//visibility:public\"])\n\nfilegroup(\n name = \"ninja_bin\",\n srcs = [\"ninja.exe\"],\n)\n\nnative_tool_toolchain(\n name = \"ninja_tool\",\n env = {\"NINJA\": \"$(execpath :ninja_bin)\"},\n path = \"$(execpath :ninja_bin)\",\n target = \":ninja_bin\",\n)\n" + } + }, + "ninja_1.12.1_toolchains": { + "repoRuleId": "@@rules_foreign_cc+//toolchains:prebuilt_toolchains_repository.bzl%prebuilt_toolchains_repository", + "attributes": { + "repos": { + "ninja_1.12.1_linux": [ + "@platforms//cpu:x86_64", + "@platforms//os:linux" + ], + "ninja_1.12.1_linux-aarch64": [ + "@platforms//cpu:aarch64", + "@platforms//os:linux" + ], + "ninja_1.12.1_mac": [ + "@platforms//cpu:x86_64", + "@platforms//os:macos" + ], + "ninja_1.12.1_mac_aarch64": [ + "@platforms//cpu:aarch64", + "@platforms//os:macos" + ], + "ninja_1.12.1_win": [ + "@platforms//cpu:x86_64", + "@platforms//os:windows" + ] + }, + "tool": "ninja" + } + } + }, + "recordedRepoMappingEntries": [ + [ + "rules_foreign_cc+", + "bazel_tools", + "bazel_tools" + ], + [ + "rules_foreign_cc+", + "rules_foreign_cc", + "rules_foreign_cc+" + ] + ] + } + }, "@@rules_kotlin+//src/main/starlark/core/repositories:bzlmod_setup.bzl%rules_kotlin_extensions": { "general": { "bzlTransitiveDigest": "BpKZEsNfgjUOuN2PY8cZR/67fJnftlcLJE4ZBh7TZ58=", diff --git a/aspect/BUILD b/aspect/BUILD index 4759ea5b1bf..29a986a11e2 100644 --- a/aspect/BUILD +++ b/aspect/BUILD @@ -7,19 +7,6 @@ load(":build_defs.bzl", "aspect_files", "aspect_library") licenses(["notice"]) -# Files needed at runtime for blaze-invoking integration tests -filegroup( - name = "integration_test_files", - srcs = [ - "artifacts.bzl", - "intellij_info_impl.bzl", - "make_variables.bzl", - "xcode_query.bzl", - ":BUILD.bazel", - ], - visibility = ["//visibility:public"], -) - # the aspect files that will be bundled with the final plugin zip aspect_library( name = "aspect_lib", @@ -33,6 +20,13 @@ aspect_library( visibility = ["//visibility:public"], ) +aspect_library( + name = "aspect_modules", + files = glob(["modules/*.bzl"]), + namespace = "aspect/modules", + visibility = ["//visibility:public"], +) + _dev_aspect_path = package_name() # Aspect references have different label paths in development vs. when bundled with the plugin. diff --git a/aspect/intellij_info_impl.bzl b/aspect/intellij_info_impl.bzl index b7d4d2c15af..f22deb1073e 100644 --- a/aspect/intellij_info_impl.bzl +++ b/aspect/intellij_info_impl.bzl @@ -19,6 +19,8 @@ load( ":make_variables.bzl", "expand_make_variables", ) +load(":modules/foreign_cc.bzl", "module_foreign_cc_collect_dependencies") +load(":modules/transitive_cc_dependencies.bzl", "module_transitive_cc_dependencies_collect") load(":python_info.bzl", "get_py_info", "py_info_in_target") IntelliJInfo = provider( @@ -311,65 +313,66 @@ def collect_py_info(target, ctx, semantics, ide_info, ide_info_file, output_grou update_sync_output_groups(output_groups, "intellij-resolve-py", to_build) return True -def collect_cpp_info(target, ctx, semantics, ide_info, ide_info_file, output_groups): - """Updates C++-specific output groups, returns false if not a C++ target.""" - - if CcInfo not in target: - return False +def collect_cc_rule_context(ctx): + """Collect additional information from the rule attributes of cc_xxx rules.""" - # ignore cc_proto_library, attach to proto_library with aspect attached instead - if ctx.rule.kind == "cc_proto_library": - return False + if not ctx.rule.kind.startswith("cc_"): + return struct() - # Go targets always provide CcInfo. Usually it's empty, but even if it isn't we don't handle it - if ctx.rule.kind.startswith("go_"): - return False - - sources = artifacts_from_target_list_attr(ctx, "srcs") - headers = artifacts_from_target_list_attr(ctx, "hdrs") - textual_headers = artifacts_from_target_list_attr(ctx, "textual_hdrs") - - target_copts = [] - if hasattr(ctx.rule.attr, "copts"): - target_copts += ctx.rule.attr.copts - extra_targets = [] - if hasattr(ctx.rule.attr, "additional_compiler_inputs"): - extra_targets += ctx.rule.attr.additional_compiler_inputs - if hasattr(semantics, "cc") and hasattr(semantics.cc, "get_default_copts"): - target_copts += semantics.cc.get_default_copts(ctx) + return struct( + sources = artifacts_from_target_list_attr(ctx, "srcs"), + headers = artifacts_from_target_list_attr(ctx, "hdrs"), + textual_headers = artifacts_from_target_list_attr(ctx, "textual_hdrs"), + copts = expand_make_variables(ctx, True, getattr(ctx.rule.attr, "copts", [])), + args = expand_make_variables(ctx, True, getattr(ctx.rule.attr, "args", [])), + include_prefix = getattr(ctx.rule.attr, "include_prefix", ""), + strip_include_prefix = getattr(ctx.rule.attr, "strip_include_prefix", ""), + ) - target_copts = expand_make_variables(ctx, True, target_copts) - args = expand_make_variables(ctx, True, getattr(ctx.rule.attr, "args", [])) +def collect_cc_compilation_context(ctx, target): + """Collect information from the compilation context provided by the CcInfo provider.""" compilation_context = target[CcInfo].compilation_context - # Merge current compilation context with context of implementation dependencies. - if hasattr(ctx.rule.attr, "implementation_deps"): - implementation_deps = ctx.rule.attr.implementation_deps + # merge current compilation context with context of implementation dependencies + if ctx.rule.kind.startswith("cc_") and hasattr(ctx.rule.attr, "implementation_deps"): + impl_deps = ctx.rule.attr.implementation_deps + compilation_context = cc_common.merge_compilation_contexts( - compilation_contexts = - [compilation_context] + [impl[CcInfo].compilation_context for impl in implementation_deps], + compilation_contexts = [compilation_context] + [it[CcInfo].compilation_context for it in impl_deps], ) # external_includes available since bazel 7 external_includes = getattr(compilation_context, "external_includes", depset()).to_list() - c_info = struct_omit_none( - header = headers, - source = sources, - target_copt = target_copts, - textual_header = textual_headers, - transitive_define = compilation_context.defines.to_list(), - transitive_include_directory = compilation_context.includes.to_list(), - transitive_quote_include_directory = compilation_context.quote_includes.to_list(), - # both system and external includes are add using `-isystem` - transitive_system_include_directory = compilation_context.system_includes.to_list() + external_includes, - include_prefix = getattr(ctx.rule.attr, "include_prefix", None), - strip_include_prefix = getattr(ctx.rule.attr, "strip_include_prefix", None), - args = args, + return struct( + direct_headers = [artifact_location(it) for it in compilation_context.direct_headers], + defines = compilation_context.defines.to_list(), + includes = compilation_context.includes.to_list(), + quote_includes = compilation_context.quote_includes.to_list(), + # both system and external includes are added using `-isystem` + system_includes = compilation_context.system_includes.to_list() + external_includes, ) - ide_info["c_ide_info"] = c_info - resolve_files = compilation_context.headers + +def collect_cpp_info(target, ctx, semantics, ide_info, ide_info_file, output_groups, dependencies): + """Updates C++-specific output groups, returns false if not a C++ target.""" + + if CcInfo not in target: + return False + + # Go targets always provide CcInfo. Usually it's empty, but even if it isn't we don't handle it + if ctx.rule.kind.startswith("go_"): + return False + + aspect_ids = get_aspect_ids(ctx) + + ide_info["c_ide_info"] = struct( + rule_context = collect_cc_rule_context(ctx), + compilation_context = collect_cc_compilation_context(ctx, target), + dependencies = [make_target_key(it.label, aspect_ids) for it in dependencies], + foreign_dependencies = module_foreign_cc_collect_dependencies(ctx, target), + ) + resolve_files = target[CcInfo].compilation_context.headers # TODO(brendandouglas): target to cpp files only compile_files = target[OutputGroupInfo].compilation_outputs if hasattr(target[OutputGroupInfo], "compilation_outputs") else depset([]) @@ -597,9 +600,11 @@ def intellij_info_aspect_impl(target, ctx, semantics): # Collect test info ide_info["test_info"] = build_test_info(ctx) + cc_dependencies = module_transitive_cc_dependencies_collect(ctx, target) + handled = False 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_cpp_info(target, ctx, semantics, ide_info, ide_info_file, output_groups, cc_dependencies.targets) or handled handled = collect_c_toolchain_info(target, ctx, semantics, ide_info, ide_info_file, output_groups) or handled # Any extra ide info @@ -622,7 +627,7 @@ def intellij_info_aspect_impl(target, ctx, semantics): target_key = target_key, ), OutputGroupInfo(**output_groups), - ] + ] + cc_dependencies.providers def semantics_extra_deps(base, semantics, name): if not hasattr(semantics, name): diff --git a/aspect/modules/foreign_cc.bzl b/aspect/modules/foreign_cc.bzl new file mode 100644 index 00000000000..a75cd9bb7b7 --- /dev/null +++ b/aspect/modules/foreign_cc.bzl @@ -0,0 +1,13 @@ +load("@rules_foreign_cc//foreign_cc:providers.bzl", "ForeignCcDepsInfo") + +def module_foreign_cc_collect_dependencies(ctx, target): + if ForeignCcDepsInfo not in target: + return [] + + return [ + struct( + gen_dir = dep.gen_dir.path, + include_dir_name = dep.include_dir_name, + ) + for dep in target[ForeignCcDepsInfo].artifacts.to_list() + ] diff --git a/aspect/modules/transitive_cc_dependencies.bzl b/aspect/modules/transitive_cc_dependencies.bzl new file mode 100644 index 00000000000..1fe906dd44d --- /dev/null +++ b/aspect/modules/transitive_cc_dependencies.bzl @@ -0,0 +1,47 @@ +load("@rules_cc//cc:defs.bzl", "CcInfo") + +DEPS = [ + "_stl", # from cc rules + "malloc", # from cc_binary rules + "deps", + "implementation_deps", +] + +CcDepInfo = provider( + fields = ["targets"], +) + +def _flatten(xss): + return [x for xs in xss for x in xs] + +def _attr_get_target(attr, name): + """Returns the value of a target attribute or a target list attribute.""" + value = getattr(attr, name, None) + value_type = type(value) + + if value_type == "Target": + return [value] + elif value_type == "list": + return value + else: + return [] + +def _attr_get_targets(attr, names): + """Returns the value of multiple target attributes as a list.""" + return _flatten([_attr_get_target(attr, name) for name in names]) + +def module_transitive_cc_dependencies_collect(ctx, target): + """Collects all transitive dependencies in of a target.""" + transitive = [dep[CcDepInfo].targets for dep in _attr_get_targets(ctx.rule.attr, DEPS) if CcDepInfo in dep] + + if CcInfo in target: + local = [target] + else: + local = [] + + targets = depset(local, transitive = transitive) + + return struct( + providers = [CcDepInfo(targets = targets)], + targets = targets.to_list(), + ) diff --git a/aspect/testing/BUILD b/aspect/testing/BUILD index 6435fbebff9..ed768e306b4 100644 --- a/aspect/testing/BUILD +++ b/aspect/testing/BUILD @@ -23,3 +23,21 @@ java_library( "//aspect/testing/rules:IntellijAspectTest", ], ) + +# All aspect tests. +test_suite( + name = "aspect_tests", + tests = [ + "//aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/ccbinary:CcBinaryTest", + "//aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/cclibrary:CcLibraryTest", + "//aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/cctest:CcTestTest", + "//aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/cctoolchain:CcToolchainTest", + "//aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/coptsmakevars:CoptsMakeVarsTest", + "//aspect/testing/tests/src/com/google/idea/blaze/aspect/general/alias:AliasTest", + "//aspect/testing/tests/src/com/google/idea/blaze/aspect/general/analysistest:AnalysisTestTest", + "//aspect/testing/tests/src/com/google/idea/blaze/aspect/general/artifacts:ArtifactTest", + "//aspect/testing/tests/src/com/google/idea/blaze/aspect/general/build:BuildFileTest", + "//aspect/testing/tests/src/com/google/idea/blaze/aspect/general/noide:NoIdeTest", + "//aspect/testing/tests/src/com/google/idea/blaze/aspect/general/tags:TagTest", + ], +) diff --git a/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/ccbinary/BUILD b/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/ccbinary/BUILD index cfbbbbca1f2..0c9fc3122ae 100644 --- a/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/ccbinary/BUILD +++ b/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/ccbinary/BUILD @@ -8,6 +8,7 @@ load( cc_binary( name = "simple", srcs = ["simple/simple.cc"], + args = ["simpleArg"], ) cc_binary( @@ -28,8 +29,8 @@ genrule( intellij_aspect_test_fixture( name = "aspect_fixture", deps = [ - ":simple", ":expand_datadeps", + ":simple", ], ) diff --git a/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/ccbinary/CcBinaryTest.java b/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/ccbinary/CcBinaryTest.java index 0bde868c0ee..5729d3a299f 100644 --- a/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/ccbinary/CcBinaryTest.java +++ b/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/ccbinary/CcBinaryTest.java @@ -31,18 +31,20 @@ public void testCcBinary() throws Exception { final var target = findTarget(testFixture, ":simple"); assertThat(target.getKindString()).isEqualTo("cc_binary"); - assertThat(target.hasCIdeInfo()).isTrue(); - assertThat(target.hasJavaIdeInfo()).isFalse(); - assertThat(target.hasAndroidIdeInfo()).isFalse(); - final var cTargetIdeInfo = target.getCIdeInfo(); + final var ideInfo = target.getCIdeInfo(); + assertThat(ideInfo.hasCompilationContext()).isTrue(); + assertThat(ideInfo.hasRuleContext()).isTrue(); - assertThat(cTargetIdeInfo.getTargetCoptList()).isEmpty(); + // rule context + final var ruleCtx = ideInfo.getRuleContext(); + assertThat(ruleCtx.getCoptsList()).isEmpty(); + assertThat(ruleCtx.getArgs(0)).isEqualTo("simpleArg"); + assertThat(ruleCtx.getSources(0).getRelativePath()).endsWith("simple/simple.cc"); + // output groups assertThat(getOutputGroupFiles(testFixture, "intellij-resolve-cpp")).isEmpty(); assertThat(getOutputGroupFiles(testFixture, "intellij-info-generic")).isEmpty(); - - assertThat(getOutputGroupFiles(testFixture, "intellij-info-cpp")).contains( - testRelative(intellijInfoFileName("simple"))); + assertThat(getOutputGroupFiles(testFixture, "intellij-info-cpp")).contains(testRelative(intellijInfoFileName("simple"))); } @Test @@ -51,9 +53,8 @@ public void testExpandDataDeps() throws Exception { final var target = findTarget(testFixture, ":expand_datadeps"); assertThat(target.getKindString()).isEqualTo("cc_binary"); - final var args = target.getCIdeInfo().getArgsList(); + final var args = target.getCIdeInfo().getRuleContext().getArgsList(); assertThat(args).hasSize(1); - assertThat(args.get(0)).endsWith( - "/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/ccbinary/datadepfile.txt"); + assertThat(args.get(0)).endsWith("datadepfile.txt"); } } diff --git a/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/cclibrary/CcLibraryTest.java b/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/cclibrary/CcLibraryTest.java index 0e3088fb0a7..fdac8e2eedd 100644 --- a/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/cclibrary/CcLibraryTest.java +++ b/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/cclibrary/CcLibraryTest.java @@ -31,35 +31,35 @@ /** Tests cc_library */ @RunWith(JUnit4.class) public class CcLibraryTest extends BazelIntellijAspectTest { + @Test public void testCcLibrary() throws Exception { - IntellijAspectTestFixture testFixture = loadTestFixture(":simple_fixture"); - TargetIdeInfo target = findTarget(testFixture, ":simple"); - + final var testFixture = loadTestFixture(":simple_fixture"); + final var target = findTarget(testFixture, ":simple"); assertThat(target.getKindString()).isEqualTo("cc_library"); - assertThat(target.hasCIdeInfo()).isTrue(); - assertThat(target.hasJavaIdeInfo()).isFalse(); - assertThat(target.hasAndroidIdeInfo()).isFalse(); - assertThat(target.hasPyIdeInfo()).isFalse(); - assertThat(relativePathsForArtifacts(target.getCIdeInfo().getSourceList())) + final var ideInfo = target.getCIdeInfo(); + assertThat(ideInfo.hasCompilationContext()).isTrue(); + assertThat(ideInfo.hasRuleContext()).isTrue(); + + // rule context + final var ruleCtx = target.getCIdeInfo().getRuleContext(); + assertThat(relativePathsForArtifacts(ruleCtx.getSourcesList())) .containsExactly(testRelative("simple/simple.cc")); - assertThat(relativePathsForArtifacts(target.getCIdeInfo().getHeaderList())) + assertThat(relativePathsForArtifacts(ruleCtx.getHeadersList())) .containsExactly(testRelative("simple/simple.h")); - assertThat(relativePathsForArtifacts(target.getCIdeInfo().getTextualHeaderList())) + assertThat(relativePathsForArtifacts(ruleCtx.getTextualHeadersList())) .containsExactly(testRelative("simple/simple_textual.h")); - - CIdeInfo cTargetIdeInfo = target.getCIdeInfo(); - assertThat(cTargetIdeInfo.getTargetCoptList()) + assertThat(ruleCtx.getCoptsList()) .containsExactly("-DGOPT", "-Ifoo/baz/", "-I", "other/headers"); - // Make sure our understanding of where this attributes show up in other providers is correct. - assertThat(cTargetIdeInfo.getTransitiveSystemIncludeDirectoryList()) - .contains(testRelative("foo/bar")); - assertThat(cTargetIdeInfo.getTransitiveDefineList()).contains("VERSION2"); - - List transQuoteIncludeDirList = cTargetIdeInfo.getTransitiveQuoteIncludeDirectoryList(); - assertThat(transQuoteIncludeDirList).contains("."); + // compilation context + final var compilationCtx = target.getCIdeInfo().getCompilationContext(); + assertThat(compilationCtx.getDefinesList()).containsExactly("VERSION2"); + assertThat(compilationCtx.getSystemIncludesList()).contains(testRelative("foo/bar")); + assertThat(compilationCtx.getQuoteIncludesList()).contains("."); + assertThat(relativePathsForArtifacts(compilationCtx.getDirectHeadersList())) + .containsExactly(testRelative("simple/simple.h")); // Can't test for this because the cc code stuffs source artifacts into // the output group @@ -68,21 +68,14 @@ public void testCcLibrary() throws Exception { @Test public void testCcLibraryHasToolchain() throws Exception { - IntellijAspectTestFixture testFixture = loadTestFixture(":simple_fixture"); - List toolchains = - testFixture.getTargetsList().stream() - .filter(x -> x.hasCToolchainIdeInfo() && x.getKindString().equals("cc_toolchain_alias")) - .collect(Collectors.toList()); - // TODO(b/200011173): Remove once Blaze/Bazel has been released with Starlark cc_library. - if (toolchains.isEmpty()) { - toolchains = - testFixture.getTargetsList().stream() - .filter(TargetIdeInfo::hasCToolchainIdeInfo) - .collect(toImmutableList()); - } + final var testFixture = loadTestFixture(":simple_fixture"); + final var toolchains = testFixture.getTargetsList().stream() + .filter(x -> x.hasCToolchainIdeInfo() && x.getKindString().equals("cc_toolchain_alias")) + .collect(Collectors.toList()); + assertThat(toolchains).hasSize(1); - TargetIdeInfo target = findTarget(testFixture, ":simple"); + final var target = findTarget(testFixture, ":simple"); assertThat(dependenciesForTarget(target)).contains(dep(toolchains.get(0))); } @@ -94,16 +87,15 @@ public void testCcDependencies() throws Exception { assertThat(lib1.hasCIdeInfo()).isTrue(); assertThat(lib2.hasCIdeInfo()).isTrue(); - CIdeInfo cIdeInfo1 = lib1.getCIdeInfo(); + final var ruleContext = lib1.getCIdeInfo().getRuleContext(); + final var compilationContext = lib1.getCIdeInfo().getCompilationContext(); - assertThat(cIdeInfo1.getTransitiveSystemIncludeDirectoryList()) - .contains(testRelative("foo/bar")); - assertThat(cIdeInfo1.getTransitiveSystemIncludeDirectoryList()) - .contains(testRelative("baz/lib")); + assertThat(compilationContext.getSystemIncludesList()).contains(testRelative("foo/bar")); + assertThat(compilationContext.getSystemIncludesList()).contains(testRelative("baz/lib")); - assertThat(cIdeInfo1.getTargetCoptList()).containsExactly("-DGOPT", "-Ifoo/baz/"); + assertThat(ruleContext.getCoptsList()).containsExactly("-DGOPT", "-Ifoo/baz/"); - assertThat(cIdeInfo1.getTransitiveDefineList()).contains("VERSION2"); - assertThat(cIdeInfo1.getTransitiveDefineList()).contains("COMPLEX_IMPL"); + assertThat(compilationContext.getDefinesList()).contains("VERSION2"); + assertThat(compilationContext.getDefinesList()).contains("COMPLEX_IMPL"); } } diff --git a/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/cctest/CcTestTest.java b/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/cctest/CcTestTest.java index 3ece3d23b59..4098868349e 100644 --- a/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/cctest/CcTestTest.java +++ b/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/cctest/CcTestTest.java @@ -39,7 +39,7 @@ public void testCcTest() throws Exception { assertThat(target.hasAndroidIdeInfo()).isFalse(); CIdeInfo cTargetIdeInfo = target.getCIdeInfo(); - assertThat(cTargetIdeInfo.getTargetCoptList()).isEmpty(); + assertThat(cTargetIdeInfo.getRuleContext().getCoptsList()).isEmpty(); // Can't test for this because the cc code stuffs source // artifacts into the output group diff --git a/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/coptsmakevars/CoptsMakeVarsTest.java b/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/coptsmakevars/CoptsMakeVarsTest.java index 7949b54581d..bc7055c913b 100644 --- a/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/coptsmakevars/CoptsMakeVarsTest.java +++ b/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/coptsmakevars/CoptsMakeVarsTest.java @@ -39,32 +39,32 @@ private CIdeInfo getCIdeInfo(String targetName) throws IOException { @Test public void testCoptsPrefinedMakeVars() throws IOException { final var ideInfo = getCIdeInfo(":simple_prefined"); - assertThat(ideInfo.getTargetCoptList()).hasSize(2); + assertThat(ideInfo.getRuleContext().getCoptsList()).hasSize(2); // These predefined variables' values are dependent on build system and configuration. - assertThat(ideInfo.getTargetCoptList().get(0)).containsMatch("^-DPREFINED_BINDIR=bazel-out/[0-9a-z_-]+/bin$"); - assertThat(ideInfo.getTargetCoptList().get(1)).isEqualTo("-DPREFINED_BINDIR2=$(BINDIR)"); + assertThat(ideInfo.getRuleContext().getCoptsList().get(0)).containsMatch("^-DPREFINED_BINDIR=bazel-out/[0-9a-z_-]+/bin$"); + assertThat(ideInfo.getRuleContext().getCoptsList().get(1)).isEqualTo("-DPREFINED_BINDIR2=$(BINDIR)"); } @Test public void testCoptsEmptyVariable() throws IOException { final var ideInfo = getCIdeInfo(":empty_variable"); - assertThat(ideInfo.getTargetCoptList()).hasSize(1); - assertThat(ideInfo.getTargetCoptList()).contains("-Wall"); + assertThat(ideInfo.getRuleContext().getCoptsList()).hasSize(1); + assertThat(ideInfo.getRuleContext().getCoptsList()).contains("-Wall"); } @Test public void testCoptsMakeVars() throws IOException { final var ideInfo = getCIdeInfo(":simple_make_var"); - assertThat(ideInfo.getTargetCoptList()).hasSize(4); + assertThat(ideInfo.getRuleContext().getCoptsList()).hasSize(4); - assertThat(ideInfo.getTargetCopt(0)).isEqualTo( + assertThat(ideInfo.getRuleContext().getCopts(0)).isEqualTo( "-DEXECPATH=\"aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/coptsmakevars/simple/simple.cc\""); - assertThat(ideInfo.getTargetCopt(1)).isEqualTo( + assertThat(ideInfo.getRuleContext().getCopts(1)).isEqualTo( "-DROOTPATH=\"aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/coptsmakevars/simple/simple.cc\""); - assertThat(ideInfo.getTargetCopt(2)).isEqualTo( + assertThat(ideInfo.getRuleContext().getCopts(2)).isEqualTo( "-DRLOCATIONPATH=\"_main/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/coptsmakevars/simple/simple.cc\""); - assertThat(ideInfo.getTargetCopt(3)).isEqualTo( + assertThat(ideInfo.getRuleContext().getCopts(3)).isEqualTo( "-DLOCATION=\"aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/coptsmakevars/simple/simple.cc\""); } } diff --git a/aspect/testing/tests/src/com/google/idea/blaze/aspect/general/artifacts/ArtifactTest.java b/aspect/testing/tests/src/com/google/idea/blaze/aspect/general/artifacts/ArtifactTest.java index 68821bbb87b..faffabc5dff 100644 --- a/aspect/testing/tests/src/com/google/idea/blaze/aspect/general/artifacts/ArtifactTest.java +++ b/aspect/testing/tests/src/com/google/idea/blaze/aspect/general/artifacts/ArtifactTest.java @@ -33,7 +33,7 @@ public void testSourceFilesAreCorrectlyMarkedAsSourceOrGenerated() throws Except IntellijAspectTestFixture testFixture = loadTestFixture(":gen_sources_fixture"); TargetIdeInfo source = findTarget(testFixture, ":source"); TargetIdeInfo gen = findTarget(testFixture, ":gen"); - assertThat(getOnlyElement(source.getCIdeInfo().getSourceList()).getIsSource()).isTrue(); - assertThat(getOnlyElement(gen.getCIdeInfo().getSourceList()).getIsSource()).isFalse(); + assertThat(getOnlyElement(source.getCIdeInfo().getRuleContext().getSourcesList()).getIsSource()).isTrue(); + assertThat(getOnlyElement(gen.getCIdeInfo().getRuleContext().getSourcesList()).getIsSource()).isFalse(); } } diff --git a/base/BUILD b/base/BUILD index 621aab5d586..160fa4b9565 100644 --- a/base/BUILD +++ b/base/BUILD @@ -31,6 +31,7 @@ kt_jvm_library( visibility = PLUGIN_PACKAGES_VISIBILITY, deps = [ "//aspect:aspect_lib", + "//aspect:aspect_modules", "//aspect:aspect_template_lib", "//base/src/com/google/idea/blaze/base/command/buildresult/bepparser", "//common/actions", diff --git a/base/src/META-INF/blaze-base.xml b/base/src/META-INF/blaze-base.xml index 4f28b818394..3f065ed0149 100644 --- a/base/src/META-INF/blaze-base.xml +++ b/base/src/META-INF/blaze-base.xml @@ -159,9 +159,12 @@ class="com.google.idea.blaze.base.wizard2.BazelDisableImportNotification$Action" text="Dismiss import notification"/> - + diff --git a/base/src/com/google/idea/blaze/base/actions/BazelDumpCacheDirectories.kt b/base/src/com/google/idea/blaze/base/actions/BazelDumpCacheDirectories.kt new file mode 100644 index 00000000000..98dc5661269 --- /dev/null +++ b/base/src/com/google/idea/blaze/base/actions/BazelDumpCacheDirectories.kt @@ -0,0 +1,80 @@ +/* + * Copyright 2025 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.base.actions + +import com.google.idea.blaze.base.logging.LoggedDirectoryProvider +import com.intellij.openapi.actionSystem.ActionUpdateThread +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.diagnostic.Logger +import com.intellij.openapi.project.DumbAwareAction +import java.io.IOException +import java.nio.file.Files +import java.nio.file.Path +import kotlin.jvm.optionals.getOrNull + +private val LOG = Logger.getInstance(BazelDumpCacheDirectories::class.java) + +class BazelDumpCacheDirectories : DumbAwareAction() { + + override fun getActionUpdateThread(): ActionUpdateThread { + return ActionUpdateThread.BGT + } + + override fun actionPerformed(event: AnActionEvent) { + val project = event.project + if (project == null) { + LOG.warn("no open project found") + return + } + + LOG.info("################################### CACHE DIRS #################################") + for (provider in LoggedDirectoryProvider.EP_NAME.extensionList) { + val directory = provider.getLoggedDirectory(project).getOrNull() ?: continue + + val exists = Files.exists(directory.path()) + val size = if (exists) collectDirectorySize(directory.path()) else null + + LOG.info("Directory: ${directory.path().toAbsolutePath()}") + LOG.info("-> purpose: ${directory.purpose()}") + LOG.info("-> origin: ${directory.originatingIdePart()}") + LOG.info("-> exists: $exists") + + if (size != null) { + LOG.info("-> size: ${size.size}B") + LOG.info("-> items: ${size.items}") + } + } + LOG.info("################################################################################") + } +} + +private data class DirectorySize(val items: Long, val size: Long) + +private fun collectDirectorySize(path: Path): DirectorySize? { + var items = 0L + var size = 0L + + try { + for (item in Files.walk(path)) { + items++ + size += Files.size(item) + } + } catch (e: IOException) { + LOG.warn("failed to collect directory size $path", e) + } + + return DirectorySize(items, size) +} \ No newline at end of file diff --git a/base/src/com/google/idea/blaze/base/actions/BazelDumpVFSAction.kt b/base/src/com/google/idea/blaze/base/actions/BazelDumpVFSAction.kt index 6f6d677cd49..8cdcf0c8c28 100644 --- a/base/src/com/google/idea/blaze/base/actions/BazelDumpVFSAction.kt +++ b/base/src/com/google/idea/blaze/base/actions/BazelDumpVFSAction.kt @@ -22,6 +22,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.project.DumbAwareAction import com.intellij.openapi.vfs.VirtualFileManager +import kotlin.io.path.extension private val LOG = Logger.getInstance(BazelDumpVFSAction::class.java) @@ -56,8 +57,16 @@ class BazelDumpVFSAction : DumbAwareAction() { return } + val histogram = mutableMapOf() LOG.info("################################## EXECROOT VFS ################################") - VfsUtil.getVfsChildrenAsSequence(virtualRoot).forEach { LOG.info(it.toString()) } + for (child in VfsUtil.getVfsChildrenAsSequence(virtualRoot)) { + histogram[child.extension] = histogram.getOrDefault(child.extension, 0) + 1L + LOG.info(child.toString()) + } + LOG.info("################################## EXECROOT MAP ################################") + for ((ext, size) in histogram.entries.sortedByDescending { it.value }) { + LOG.info(String.format("%6d - %s", size, ext)) + } LOG.info("################################################################################") } } diff --git a/base/src/com/google/idea/blaze/base/ideinfo/CIdeInfo.java b/base/src/com/google/idea/blaze/base/ideinfo/CIdeInfo.java index 3597928cf2c..e9057ae7a90 100644 --- a/base/src/com/google/idea/blaze/base/ideinfo/CIdeInfo.java +++ b/base/src/com/google/idea/blaze/base/ideinfo/CIdeInfo.java @@ -15,322 +15,248 @@ */ package com.google.idea.blaze.base.ideinfo; +import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import com.google.devtools.intellij.ideinfo.IntellijIdeInfo; -import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.idea.blaze.base.model.primitives.ExecutionRootPath; -import java.util.Objects; - -/** Ide info specific to cc rules. */ -public final class CIdeInfo implements ProtoWrapper { - private final ImmutableList sources; - private final ImmutableList headers; - private final ImmutableList textualHeaders; - - private final ImmutableList localCopts; - // From the cpp compilation context provider. - // These should all be for the entire transitive closure. - private final ImmutableList transitiveIncludeDirectories; - private final ImmutableList transitiveQuoteIncludeDirectories; - private final ImmutableList transitiveDefines; - private final ImmutableList transitiveSystemIncludeDirectories; - - private final String includePrefix; - private final String stripIncludePrefix; - - private final ImmutableList args; - - private CIdeInfo( - ImmutableList sources, - ImmutableList headers, - ImmutableList textualHeaders, - ImmutableList localCopts, - ImmutableList transitiveIncludeDirectories, - ImmutableList transitiveQuoteIncludeDirectories, - ImmutableList transitiveDefines, - ImmutableList transitiveSystemIncludeDirectories, - String includePrefix, - String stripIncludePrefix, - ImmutableList args) { - this.sources = sources; - this.headers = headers; - this.textualHeaders = textualHeaders; - this.localCopts = localCopts; - this.transitiveIncludeDirectories = transitiveIncludeDirectories; - this.transitiveQuoteIncludeDirectories = transitiveQuoteIncludeDirectories; - this.transitiveDefines = transitiveDefines; - this.transitiveSystemIncludeDirectories = transitiveSystemIncludeDirectories; - this.includePrefix = includePrefix; - this.stripIncludePrefix = stripIncludePrefix; - this.args = args; - } - static CIdeInfo fromProto(IntellijIdeInfo.CIdeInfo proto) { - return new CIdeInfo( - ProtoWrapper.map(proto.getSourceList(), ArtifactLocation::fromProto), - ProtoWrapper.map(proto.getHeaderList(), ArtifactLocation::fromProto), - ProtoWrapper.map(proto.getTextualHeaderList(), ArtifactLocation::fromProto), - ProtoWrapper.internStrings(proto.getTargetCoptList()), - ProtoWrapper.map(proto.getTransitiveIncludeDirectoryList(), ExecutionRootPath::fromProto), - ProtoWrapper.map( - proto.getTransitiveQuoteIncludeDirectoryList(), ExecutionRootPath::fromProto), - ProtoWrapper.internStrings(proto.getTransitiveDefineList()), - ProtoWrapper.map( - proto.getTransitiveSystemIncludeDirectoryList(), ExecutionRootPath::fromProto), - proto.getIncludePrefix(), - proto.getStripIncludePrefix(), - ProtoWrapper.internStrings(proto.getArgsList())); - } +/** + * Ide info specific to cc rules. + */ +@AutoValue +public abstract class CIdeInfo implements ProtoWrapper { - @Override - public IntellijIdeInfo.CIdeInfo toProto() { - return IntellijIdeInfo.CIdeInfo.newBuilder() - .addAllSource(ProtoWrapper.mapToProtos(sources)) - .addAllHeader(ProtoWrapper.mapToProtos(headers)) - .addAllTextualHeader(ProtoWrapper.mapToProtos(textualHeaders)) - .addAllTargetCopt(localCopts) - .addAllTransitiveIncludeDirectory(ProtoWrapper.mapToProtos(transitiveIncludeDirectories)) - .addAllTransitiveQuoteIncludeDirectory( - ProtoWrapper.mapToProtos(transitiveQuoteIncludeDirectories)) - .addAllTransitiveDefine(transitiveDefines) - .addAllTransitiveSystemIncludeDirectory( - ProtoWrapper.mapToProtos(transitiveSystemIncludeDirectories)) - .addAllArgs(args) - .build(); - } + @AutoValue + public static abstract class RuleContext implements ProtoWrapper { - public ImmutableList getSources() { - return sources; - } + private static final RuleContext EMPTY = builder().build(); - public ImmutableList getHeaders() { - return headers; - } + public abstract ImmutableList sources(); - public ImmutableList getTextualHeaders() { - return textualHeaders; - } + public abstract ImmutableList headers(); - public ImmutableList getLocalCopts() { - return localCopts; - } + public abstract ImmutableList textualHeaders(); - public ImmutableList getTransitiveIncludeDirectories() { - return transitiveIncludeDirectories; - } + public abstract ImmutableList copts(); - public ImmutableList getTransitiveQuoteIncludeDirectories() { - return transitiveQuoteIncludeDirectories; - } + public abstract ImmutableList args(); - public ImmutableList getTransitiveDefines() { - return transitiveDefines; - } + public abstract String includePrefix(); - public ImmutableList getTransitiveSystemIncludeDirectories() { - return transitiveSystemIncludeDirectories; - } + public abstract String stripIncludePrefix(); - public String getIncludePrefix() { - return includePrefix; - } + public static CIdeInfo.RuleContext fromProto(IntellijIdeInfo.CIdeInfo.RuleContext proto) { + return builder() + .setSources(ProtoWrapper.map(proto.getSourcesList(), ArtifactLocation::fromProto)) + .setHeaders(ProtoWrapper.map(proto.getHeadersList(), ArtifactLocation::fromProto)) + .setTextualHeaders(ProtoWrapper.map(proto.getTextualHeadersList(), ArtifactLocation::fromProto)) + .setCopts(ProtoWrapper.internStrings(proto.getCoptsList())) + .setArgs(ProtoWrapper.internStrings(proto.getArgsList())) + .setIncludePrefix(ProtoWrapper.internString(proto.getIncludePrefix())) + .setStripIncludePrefix(ProtoWrapper.internString(proto.getStripIncludePrefix())) + .build(); + } - public String getStripIncludePrefix() { - return stripIncludePrefix; - } + @Override + public IntellijIdeInfo.CIdeInfo.RuleContext toProto() { + return IntellijIdeInfo.CIdeInfo.RuleContext.newBuilder() + .addAllSources(ProtoWrapper.mapToProtos(sources())) + .addAllHeaders(ProtoWrapper.mapToProtos(headers())) + .addAllTextualHeaders(ProtoWrapper.mapToProtos(textualHeaders())) + .addAllCopts(copts()) + .addAllArgs(args()) + .setIncludePrefix(includePrefix()) + .setStripIncludePrefix(stripIncludePrefix()) + .build(); + } - public ImmutableList getArgs() { - return args; - } + public static Builder builder() { + return new AutoValue_CIdeInfo_RuleContext.Builder() + .setSources(ImmutableList.of()) + .setHeaders(ImmutableList.of()) + .setTextualHeaders(ImmutableList.of()) + .setCopts(ImmutableList.of()) + .setArgs(ImmutableList.of()) + .setIncludePrefix("") + .setStripIncludePrefix(""); + } - public static Builder builder() { - return new Builder(); - } + @AutoValue.Builder + public abstract static class Builder { - /** Builder for c rule info */ - public static class Builder { - private final ImmutableList.Builder sources = ImmutableList.builder(); - private final ImmutableList.Builder headers = ImmutableList.builder(); - private final ImmutableList.Builder textualHeaders = ImmutableList.builder(); - - private final ImmutableList.Builder localCopts = ImmutableList.builder(); - private final ImmutableList.Builder transitiveIncludeDirectories = - ImmutableList.builder(); - private final ImmutableList.Builder transitiveQuoteIncludeDirectories = - ImmutableList.builder(); - private final ImmutableList.Builder transitiveDefines = ImmutableList.builder(); - private final ImmutableList.Builder transitiveSystemIncludeDirectories = - ImmutableList.builder(); - - private String includePrefix = ""; - private String stripIncludePrefix = ""; - - private final ImmutableList.Builder args = ImmutableList.builder(); - - @CanIgnoreReturnValue - public Builder addSources(Iterable sources) { - this.sources.addAll(sources); - return this; - } + public abstract Builder setSources(ImmutableList value); - @CanIgnoreReturnValue - public Builder addSource(ArtifactLocation source) { - this.sources.add(source); - return this; - } + public abstract Builder setHeaders(ImmutableList value); - @CanIgnoreReturnValue - public Builder addHeaders(Iterable headers) { - this.headers.addAll(headers); - return this; - } + public abstract Builder setTextualHeaders(ImmutableList value); - @CanIgnoreReturnValue - public Builder addHeader(ArtifactLocation header) { - this.headers.add(header); - return this; - } + public abstract Builder setCopts(ImmutableList value); - @CanIgnoreReturnValue - public Builder addTextualHeaders(Iterable textualHeaders) { - this.textualHeaders.addAll(textualHeaders); - return this; - } + public abstract Builder setArgs(ImmutableList value); + + public abstract Builder setIncludePrefix(String value); - @CanIgnoreReturnValue - public Builder addTextualHeader(ArtifactLocation textualHeader) { - this.textualHeaders.add(textualHeader); - return this; + public abstract Builder setStripIncludePrefix(String value); + + public abstract RuleContext build(); } + } + + @AutoValue + public static abstract class CompilationContext implements ProtoWrapper { + + private static final CompilationContext EMPTY = builder().build(); + + public abstract ImmutableList directHeaders(); + + public abstract ImmutableList defines(); + + public abstract ImmutableList includes(); + + public abstract ImmutableList quoteIncludes(); + + public abstract ImmutableList systemIncludes(); - @CanIgnoreReturnValue - public Builder addLocalCopts(Iterable copts) { - this.localCopts.addAll(copts); - return this; + public static CIdeInfo.CompilationContext fromProto(IntellijIdeInfo.CIdeInfo.CompilationContext proto) { + return builder() + .setDirectHeaders(ProtoWrapper.map(proto.getDirectHeadersList(), ArtifactLocation::fromProto)) + .setDefines(ProtoWrapper.internStrings(proto.getDefinesList())) + .setIncludes(ProtoWrapper.map(proto.getIncludesList(), ExecutionRootPath::fromProto)) + .setQuoteIncludes(ProtoWrapper.map(proto.getQuoteIncludesList(), ExecutionRootPath::fromProto)) + .setSystemIncludes(ProtoWrapper.map(proto.getSystemIncludesList(), ExecutionRootPath::fromProto)) + .build(); } - @CanIgnoreReturnValue - public Builder addTransitiveIncludeDirectories( - Iterable transitiveIncludeDirectories) { - this.transitiveIncludeDirectories.addAll(transitiveIncludeDirectories); - return this; + @Override + public IntellijIdeInfo.CIdeInfo.CompilationContext toProto() { + return IntellijIdeInfo.CIdeInfo.CompilationContext.newBuilder() + .addAllDirectHeaders(ProtoWrapper.mapToProtos(directHeaders())) + .addAllDefines(defines()) + .addAllIncludes(ProtoWrapper.mapToProtos(includes())) + .addAllQuoteIncludes(ProtoWrapper.mapToProtos(quoteIncludes())) + .addAllSystemIncludes(ProtoWrapper.mapToProtos(systemIncludes())) + .build(); } - @CanIgnoreReturnValue - public Builder addTransitiveQuoteIncludeDirectories( - Iterable transitiveQuoteIncludeDirectories) { - this.transitiveQuoteIncludeDirectories.addAll(transitiveQuoteIncludeDirectories); - return this; + public static Builder builder() { + return new AutoValue_CIdeInfo_CompilationContext.Builder() + .setDirectHeaders(ImmutableList.of()) + .setDefines(ImmutableList.of()) + .setIncludes(ImmutableList.of()) + .setQuoteIncludes(ImmutableList.of()) + .setSystemIncludes(ImmutableList.of()); } - @CanIgnoreReturnValue - public Builder addTransitiveDefines(Iterable transitiveDefines) { - this.transitiveDefines.addAll(transitiveDefines); - return this; + @AutoValue.Builder + public abstract static class Builder { + + public abstract Builder setDirectHeaders(ImmutableList value); + + public abstract Builder setDefines(ImmutableList value); + + public abstract Builder setIncludes(ImmutableList value); + + public abstract Builder setQuoteIncludes(ImmutableList value); + + public abstract Builder setSystemIncludes(ImmutableList value); + + public abstract CompilationContext build(); } + } + + @AutoValue + public static abstract class ForeignDependency implements ProtoWrapper { + + public abstract ExecutionRootPath genDir(); - @CanIgnoreReturnValue - public Builder addTransitiveSystemIncludeDirectories( - Iterable transitiveSystemIncludeDirectories) { - this.transitiveSystemIncludeDirectories.addAll(transitiveSystemIncludeDirectories); - return this; + public abstract String includeDirName(); + + public static CIdeInfo.ForeignDependency fromProto(IntellijIdeInfo.CIdeInfo.ForeignDependency proto) { + return builder() + .setGenDir(ExecutionRootPath.fromNullableProto(proto.getGenDir())) + .setIncludeDirName(ProtoWrapper.internString(proto.getIncludeDirName())) + .build(); } - @CanIgnoreReturnValue - public Builder setIncludePrefix(String includePrefix) { - this.includePrefix = includePrefix; - return this; + @Override + public IntellijIdeInfo.CIdeInfo.ForeignDependency toProto() { + return IntellijIdeInfo.CIdeInfo.ForeignDependency.newBuilder() + .setGenDir(genDir().toProto()) + .setIncludeDirName(includeDirName()) + .build(); } - @CanIgnoreReturnValue - public Builder setStripIncludePrefix(String stripIncludePrefix) { - this.stripIncludePrefix = stripIncludePrefix; - return this; + public static Builder builder() { + return new AutoValue_CIdeInfo_ForeignDependency.Builder(); } - public CIdeInfo build() { - return new CIdeInfo( - sources.build(), - headers.build(), - textualHeaders.build(), - localCopts.build(), - transitiveIncludeDirectories.build(), - transitiveQuoteIncludeDirectories.build(), - transitiveDefines.build(), - transitiveSystemIncludeDirectories.build(), - includePrefix, - stripIncludePrefix, - args.build()); + @AutoValue.Builder + public abstract static class Builder { + + public abstract Builder setGenDir(ExecutionRootPath value); + + public abstract Builder setIncludeDirName(String value); + + public abstract ForeignDependency build(); } } - @Override - public String toString() { - return "CIdeInfo{" - + "\n" - + " sources=" - + getSources() - + "\n" - + " headers=" - + getHeaders() - + "\n" - + " textualHeaders=" - + getTextualHeaders() - + "\n" - + " localCopts=" - + getLocalCopts() - + "\n" - + " transitiveIncludeDirectories=" - + getTransitiveIncludeDirectories() - + "\n" - + " transitiveQuoteIncludeDirectories=" - + getTransitiveQuoteIncludeDirectories() - + "\n" - + " transitiveDefines=" - + getTransitiveDefines() - + "\n" - + " transitiveSystemIncludeDirectories=" - + getTransitiveSystemIncludeDirectories() - + "\n" - + " args=" - + getArgs() - + "\n" - + '}'; - } + public abstract RuleContext ruleContext(); - @Override - public boolean equals(Object o) { - if (this == o) { - return true; + public abstract CompilationContext compilationContext(); + + public abstract ImmutableList dependencies(); + + public abstract ImmutableList foreignDependencies(); + + public static CIdeInfo fromProto(IntellijIdeInfo.CIdeInfo proto) { + final var builder = builder(); + + if (proto.hasRuleContext()) { + builder.setRuleContext(RuleContext.fromProto(proto.getRuleContext())); } - if (o == null || getClass() != o.getClass()) { - return false; + if (proto.hasCompilationContext()) { + builder.setCompilationContext(CompilationContext.fromProto(proto.getCompilationContext())); } - CIdeInfo cIdeInfo = (CIdeInfo) o; - return Objects.equals(sources, cIdeInfo.sources) - && Objects.equals(headers, cIdeInfo.headers) - && Objects.equals(textualHeaders, cIdeInfo.textualHeaders) - && Objects.equals(localCopts, cIdeInfo.localCopts) - && Objects.equals(transitiveIncludeDirectories, cIdeInfo.transitiveIncludeDirectories) - && Objects.equals( - transitiveQuoteIncludeDirectories, cIdeInfo.transitiveQuoteIncludeDirectories) - && Objects.equals(transitiveDefines, cIdeInfo.transitiveDefines) - && Objects.equals( - transitiveSystemIncludeDirectories, cIdeInfo.transitiveSystemIncludeDirectories) - && Objects.equals(args, cIdeInfo.args); + + builder.setDependencies(ProtoWrapper.map(proto.getDependenciesList(), TargetKey::fromProto)); + builder.setForeignDependencies(ProtoWrapper.map(proto.getForeignDependenciesList(), ForeignDependency::fromProto)); + + return builder.build(); } @Override - public int hashCode() { - return Objects.hash( - sources, - headers, - textualHeaders, - localCopts, - transitiveIncludeDirectories, - transitiveQuoteIncludeDirectories, - transitiveDefines, - transitiveSystemIncludeDirectories, - args); + public IntellijIdeInfo.CIdeInfo toProto() { + final var builder = IntellijIdeInfo.CIdeInfo.newBuilder() + .setCompilationContext(compilationContext().toProto()) + .addAllDependencies(ProtoWrapper.mapToProtos(dependencies())); + + if (ruleContext() != null) { + builder.setRuleContext(ruleContext().toProto()); + } + + return builder.build(); + } + + public static Builder builder() { + return new AutoValue_CIdeInfo.Builder() + .setRuleContext(RuleContext.EMPTY) + .setCompilationContext(CompilationContext.EMPTY) + .setDependencies(ImmutableList.of()) + .setForeignDependencies(ImmutableList.of()); + } + + @AutoValue.Builder + public abstract static class Builder { + + public abstract Builder setRuleContext(RuleContext value); + + public abstract Builder setCompilationContext(CompilationContext value); + + public abstract Builder setDependencies(ImmutableList value); + + public abstract Builder setForeignDependencies(ImmutableList value); + + public abstract CIdeInfo build(); } } diff --git a/base/src/com/google/idea/blaze/base/ideinfo/ProtoWrapper.java b/base/src/com/google/idea/blaze/base/ideinfo/ProtoWrapper.java index 67d49c721e7..9e0a6041239 100644 --- a/base/src/com/google/idea/blaze/base/ideinfo/ProtoWrapper.java +++ b/base/src/com/google/idea/blaze/base/ideinfo/ProtoWrapper.java @@ -63,6 +63,10 @@ static ImmutableList internStrings(Iterable iterable) { return map(iterable, ProjectDataInterner::intern); } + static String internString(String string) { + return ProjectDataInterner.intern(string); + } + static

void unwrapAndSetIfNotNull(Consumer

setter, @Nullable ProtoWrapper

wrapper) { if (wrapper != null) { setter.accept(wrapper.toProto()); diff --git a/base/src/com/google/idea/blaze/base/ideinfo/TargetIdeInfo.java b/base/src/com/google/idea/blaze/base/ideinfo/TargetIdeInfo.java index 4972f8d49d2..375bc3c7520 100644 --- a/base/src/com/google/idea/blaze/base/ideinfo/TargetIdeInfo.java +++ b/base/src/com/google/idea/blaze/base/ideinfo/TargetIdeInfo.java @@ -120,9 +120,9 @@ public static TargetIdeInfo fromProto( CIdeInfo cIdeInfo = null; if (proto.hasCIdeInfo()) { cIdeInfo = CIdeInfo.fromProto(proto.getCIdeInfo()); - sourcesBuilder.addAll(cIdeInfo.getSources()); - sourcesBuilder.addAll(cIdeInfo.getHeaders()); - sourcesBuilder.addAll(cIdeInfo.getTextualHeaders()); + sourcesBuilder.addAll(cIdeInfo.ruleContext().sources()); + sourcesBuilder.addAll(cIdeInfo.ruleContext().headers()); + sourcesBuilder.addAll(cIdeInfo.ruleContext().textualHeaders()); } JavaIdeInfo javaIdeInfo = null; if (proto.hasJavaIdeInfo()) { @@ -471,9 +471,12 @@ public Builder setJavaInfo(JavaIdeInfo.Builder builder) { @CanIgnoreReturnValue public Builder setCInfo(CIdeInfo.Builder cInfoBuilder) { this.cIdeInfo = cInfoBuilder.build(); - this.sources.addAll(cIdeInfo.getSources()); - this.sources.addAll(cIdeInfo.getHeaders()); - this.sources.addAll(cIdeInfo.getTextualHeaders()); + this.sources.addAll(cIdeInfo.ruleContext().sources()); + this.sources.addAll(cIdeInfo.ruleContext().headers()); + this.sources.addAll(cIdeInfo.ruleContext().textualHeaders()); + + // TODO: add compilation context direct headers here too? (they can contain duplicates, filter?) + return this; } diff --git a/base/src/com/google/idea/blaze/base/model/primitives/Label.java b/base/src/com/google/idea/blaze/base/model/primitives/Label.java index 9c7b851b21c..c2dd3ec111a 100644 --- a/base/src/com/google/idea/blaze/base/model/primitives/Label.java +++ b/base/src/com/google/idea/blaze/base/model/primitives/Label.java @@ -140,6 +140,14 @@ public WorkspacePath blazePackage() { return new WorkspacePath(labelStr.substring(startIndex, colonIndex)); } + public ExecutionRootPath executionRootPath() { + String labelStr = toString(); + int startIndex = labelStr.indexOf("//") + "//".length(); + int colonIndex = labelStr.lastIndexOf(':'); + logger.assertTrue(colonIndex >= 0); + return ExecutionRootPath.create(labelStr.substring(startIndex) + "/" + labelStr.substring(colonIndex)); + } + /** A new label with the same workspace and package paths, but a different target name. */ @Nullable public Label withTargetName(@Nullable String targetName) { diff --git a/base/src/com/google/idea/blaze/base/sync/aspects/storage/AspectModuleWriter.kt b/base/src/com/google/idea/blaze/base/sync/aspects/storage/AspectModuleWriter.kt new file mode 100644 index 00000000000..62912c1dce1 --- /dev/null +++ b/base/src/com/google/idea/blaze/base/sync/aspects/storage/AspectModuleWriter.kt @@ -0,0 +1,119 @@ +/* + * Copyright 2025 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.base.sync.aspects.storage + +import com.google.common.collect.ImmutableList +import com.google.idea.blaze.base.sync.SyncProjectState +import com.google.idea.blaze.base.sync.SyncScope.SyncFailedException +import com.intellij.openapi.project.Project +import com.intellij.openapi.util.registry.Registry +import java.io.IOException +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.StandardOpenOption + +private const val DEFAULT_FUNCTION_TEMPLATE = """ +def %s(ctx, target): + return %s +""" + +private const val MODULES_DIRECTORY = "modules" + +abstract class AspectModuleWriter : AspectWriter { + + protected fun interface Dependency { + fun isFulfilled(state: SyncProjectState): Boolean + } + + protected fun ruleSetDependency(name: String) = Dependency { state -> + state.externalWorkspaceData?.getByRepoName(name) != null + } + + protected fun registryKeyDependency(key: String) = Dependency { + Registry.`is`(key) + } + + protected fun bazelDependency(minVersion: Int) = Dependency { state -> + state.blazeVersionData.bazelIsAtLeastVersion(minVersion, 0, 0) + } + + protected abstract fun dependencies(): ImmutableList + + protected data class Function(val name: String, val defaultValue: String) + + protected abstract fun functions(): ImmutableList + + @Throws(IOException::class) + private fun copyImplementation(dst: Path) { + Files.createDirectories(dst.resolve(MODULES_DIRECTORY)) + + val fileName = String.format("%s.bzl", name()) + + val srcResource = String.format("%s/%s", AspectRepositoryProvider.ASPECT_MODULE_DIRECTORY, fileName) + val srcStream = this.javaClass.classLoader.getResourceAsStream(srcResource) + ?: throw IOException("could not module resource file: $srcResource") + + srcStream.use { srcStream -> + Files.newOutputStream( + dst.resolve(MODULES_DIRECTORY).resolve(fileName), + StandardOpenOption.CREATE, + StandardOpenOption.TRUNCATE_EXISTING, + ).use { dstStream -> srcStream.transferTo(dstStream) } + } + } + + @Throws(IOException::class) + private fun generateDefault(dst: Path) { + Files.createDirectories(dst.resolve(MODULES_DIRECTORY)) + + val fileName = String.format("%s.bzl", name()) + + val writer = Files.newOutputStream( + dst.resolve(MODULES_DIRECTORY).resolve(fileName), + StandardOpenOption.CREATE, + StandardOpenOption.TRUNCATE_EXISTING, + ).bufferedWriter() + + writer.use { + for (function in functions()) { + writer.write(String.format(DEFAULT_FUNCTION_TEMPLATE, function.name, function.defaultValue)) + } + } + } + + @Throws(SyncFailedException::class) + override fun writeDumb(dst: Path, project: Project) { + try { + generateDefault(dst) + } catch (e: IOException) { + throw SyncFailedException("Could not generate default implementation for module: ${name()}", e) + } + } + + @Throws(SyncFailedException::class) + override fun write(dst: Path, project: Project, state: SyncProjectState) { + if (dependencies().any { !it.isFulfilled(state) }) { + writeDumb(dst, project) + return + } + + try { + copyImplementation(dst) + } catch (e: IOException) { + throw SyncFailedException("Could not copy implementation for module: ${name()}", e) + } + } +} diff --git a/base/src/com/google/idea/blaze/base/sync/aspects/storage/AspectRepositoryProvider.kt b/base/src/com/google/idea/blaze/base/sync/aspects/storage/AspectRepositoryProvider.kt index 9512b3ab2e8..5a37ca3ba07 100644 --- a/base/src/com/google/idea/blaze/base/sync/aspects/storage/AspectRepositoryProvider.kt +++ b/base/src/com/google/idea/blaze/base/sync/aspects/storage/AspectRepositoryProvider.kt @@ -22,6 +22,7 @@ object AspectRepositoryProvider { const val ASPECT_DIRECTORY: String = "aspect/default" const val ASPECT_TEMPLATE_DIRECTORY: String = "aspect/template" const val ASPECT_QSYNC_DIRECTORY: String = "aspect/qsync" + const val ASPECT_MODULE_DIRECTORY: String = "aspect/modules" @JvmStatic fun aspectQSyncFile(file: String): ByteSource { diff --git a/base/src/com/google/idea/blaze/base/sync/workspace/ExecutionRootPathResolver.java b/base/src/com/google/idea/blaze/base/sync/workspace/ExecutionRootPathResolver.java index ef40062027f..20f6ef2e033 100644 --- a/base/src/com/google/idea/blaze/base/sync/workspace/ExecutionRootPathResolver.java +++ b/base/src/com/google/idea/blaze/base/sync/workspace/ExecutionRootPathResolver.java @@ -71,6 +71,9 @@ static ExecutionRootPathResolver fromProjectData(Project project, BlazeProjectDa * This method should be used for directories. Returns all workspace files corresponding to the given * execution-root-relative path. If the file does not exist inside a workspace (e.g. for blaze output files), returns * the path rooted in the execution root. + * + * This function should not be used i.e. should not be necessary when VirtualIncludesService is enabled. But since + * this is in base, it is not possible to check in the implementation that whether the service is enabled or not. */ ImmutableList resolveToIncludeDirectories(ExecutionRootPath path); diff --git a/base/src/com/google/idea/blaze/base/sync/workspace/VirtualIncludesHandler.java b/base/src/com/google/idea/blaze/base/sync/workspace/VirtualIncludesHandler.java index d1651410fe3..9ca878e515f 100644 --- a/base/src/com/google/idea/blaze/base/sync/workspace/VirtualIncludesHandler.java +++ b/base/src/com/google/idea/blaze/base/sync/workspace/VirtualIncludesHandler.java @@ -96,12 +96,12 @@ static ImmutableList resolveVirtualInclude( return ImmutableList.of(); } - if (!cIdeInfo.getIncludePrefix().isEmpty()) { + if (!cIdeInfo.ruleContext().includePrefix().isEmpty()) { // it is not possible to handle include prefixes here, fallback to virtual include directory return ImmutableList.of(); } - var stripPrefix = cIdeInfo.getStripIncludePrefix(); + var stripPrefix = cIdeInfo.ruleContext().stripIncludePrefix(); if (stripPrefix == null || stripPrefix.isBlank()) { return ImmutableList.of(); } diff --git a/base/tests/unittests/com/google/idea/blaze/base/sync/workspace/ExecutionRootPathResolverTest.java b/base/tests/unittests/com/google/idea/blaze/base/sync/workspace/ExecutionRootPathResolverTest.java index e1dd7155c1a..544e367b165 100644 --- a/base/tests/unittests/com/google/idea/blaze/base/sync/workspace/ExecutionRootPathResolverTest.java +++ b/base/tests/unittests/com/google/idea/blaze/base/sync/workspace/ExecutionRootPathResolverTest.java @@ -98,14 +98,14 @@ private static String getStripPrefix(TargetName targetName) { private static TargetIdeInfo getTargetIdeInfo(TargetName targetName) { String stripPrefix = getStripPrefix(targetName); - CIdeInfo.Builder cIdeInfoBuilder = CIdeInfo.builder().setStripIncludePrefix(stripPrefix); + final var ruleContextBuilder = CIdeInfo.RuleContext.builder(); + ruleContextBuilder.setStripIncludePrefix(stripPrefix); + if (targetName.equals(TARGET_WITH_INCLUDE_PREFIX)) { - cIdeInfoBuilder.setIncludePrefix(INCLUDE_PREFIX); + ruleContextBuilder.setIncludePrefix(INCLUDE_PREFIX); } - return TargetIdeInfo.builder() - .setCInfo(cIdeInfoBuilder) - .build(); + return TargetIdeInfo.builder().setCInfo(CIdeInfo.builder().setRuleContext(ruleContextBuilder.build())).build(); } @NotNull diff --git a/clwb/BUILD b/clwb/BUILD index 99c044500bb..5ef98bb4fe4 100644 --- a/clwb/BUILD +++ b/clwb/BUILD @@ -161,7 +161,10 @@ clwb_headless_test( clwb_headless_test( name = "virtual_includes_headless_test", - srcs = ["tests/headlesstests/com/google/idea/blaze/clwb/VirtualIncludesTest.java"], + srcs = [ + "tests/headlesstests/com/google/idea/blaze/clwb/VirtualIncludesCacheTest.java", + "tests/headlesstests/com/google/idea/blaze/clwb/VirtualIncludesTest.java", + ], project = "virtual_includes", ) @@ -207,6 +210,15 @@ clwb_headless_test( project = "clang_cl", ) +clwb_headless_test( + name = "protobuf_headless_test", + srcs = [ + "tests/headlesstests/com/google/idea/blaze/clwb/ProtobufCacheTest.java", + "tests/headlesstests/com/google/idea/blaze/clwb/ProtobufTest.java", + ], + project = "protobuf", +) + test_suite( name = "headless_tests", tests = [ @@ -214,22 +226,23 @@ test_suite( ":example_headless_test", ":execution_headless_test", ":external_includes_headless_test", + ":lib_cpp_headless_test", ":llvm_toolchain_headless_test", + ":protobuf_headless_test", ":simple_headless_test", ":target_compatible_headless_test", ":virtual_includes_headless_test", - ":lib_cpp_headless_test", ], ) clwb_integration_test( - name = "copts_processor", - srcs = ["tests/integrationtests/com/google/idea/blaze/clwb/CoptsProcessorTest.kt"], + name = "copts_processor", + srcs = ["tests/integrationtests/com/google/idea/blaze/clwb/CoptsProcessorTest.kt"], ) test_suite( name = "integration_tests", tests = [ - ":copts_processor", + ":copts_processor", ], ) diff --git a/clwb/clwb.bazelproject b/clwb/clwb.bazelproject index acf0f1c1eda..36a9497157c 100644 --- a/clwb/clwb.bazelproject +++ b/clwb/clwb.bazelproject @@ -1,17 +1,12 @@ directories: . - -ijwb - -aswb - -plugin_dev -examples - -java - -golang -clwb/tests/projects - -testing/test_deps/projects targets: //clwb:all //clwb:clwb_bazel_dev + //aspect/testing:aspect_tests workspace_type: intellij_plugin diff --git a/clwb/src/com/google/idea/blaze/clwb/run/BlazeCidrLauncher.java b/clwb/src/com/google/idea/blaze/clwb/run/BlazeCidrLauncher.java index 169c54df3f2..a9191c929aa 100644 --- a/clwb/src/com/google/idea/blaze/clwb/run/BlazeCidrLauncher.java +++ b/clwb/src/com/google/idea/blaze/clwb/run/BlazeCidrLauncher.java @@ -245,7 +245,7 @@ private ImmutableList getTargetArguments(TargetExpression target) { .stream() .map(TargetIdeInfo::getcIdeInfo) .filter(Objects::nonNull) - .flatMap(it -> it.getArgs().stream()) + .flatMap(it -> it.ruleContext().args().stream()) .collect(ImmutableList.toImmutableList()); } diff --git a/clwb/tests/headlesstests/com/google/idea/blaze/clwb/ProtobufCacheTest.java b/clwb/tests/headlesstests/com/google/idea/blaze/clwb/ProtobufCacheTest.java new file mode 100644 index 00000000000..a895f7dd87d --- /dev/null +++ b/clwb/tests/headlesstests/com/google/idea/blaze/clwb/ProtobufCacheTest.java @@ -0,0 +1,60 @@ +package com.google.idea.blaze.clwb; + +import static com.google.common.truth.Truth.assertThat; +import static com.google.idea.blaze.clwb.base.Assertions.assertContainsHeader; +import static com.google.idea.blaze.clwb.base.Assertions.assertCachedHeader; +import static com.google.idea.blaze.clwb.base.TestUtils.setIncludesCacheEnabled; + +import com.google.idea.blaze.base.bazel.BazelVersion; +import com.google.idea.blaze.clwb.base.ClwbHeadlessTestCase; +import com.google.idea.testing.headless.BazelVersionRule; +import com.google.idea.testing.headless.ProjectViewBuilder; +import com.intellij.util.system.OS; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class ProtobufCacheTest extends ClwbHeadlessTestCase { + + // protobuf requires bazel 7+ + @Rule + public final BazelVersionRule bazelRule = new BazelVersionRule(7, 0); + + // on windows clang-cl is required to compile protobuf and therefore also bazel 8+ + @Rule + public final BazelVersionRule bazelWindowsRule = new BazelVersionRule(OS.Windows, 8, 0); + + @Test + public void testClwb() { + setIncludesCacheEnabled(true); + + final var errors = runSync(defaultSyncParams().build()); + errors.assertNoErrors(); + + checkProto(); + } + + @Override + protected ProjectViewBuilder projectViewText(BazelVersion version) { + final var builder = super.projectViewText(version); + + if (OS.CURRENT.equals(OS.Windows)) { + builder.addBuildFlag("--extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl"); + builder.addBuildFlag("--extra_execution_platforms=//:x64_windows-clang-cl"); + } + + return builder; + } + + private void checkProto() { + final var compilerSettings = findFileCompilerSettings("main/main.cc"); + + final var headersSearchRoots = compilerSettings.getHeadersSearchRoots().getAllRoots(); + assertThat(headersSearchRoots).isNotEmpty(); + + assertContainsHeader("proto/addressbook.pb.h", compilerSettings); + assertCachedHeader("proto/addressbook.pb.h", compilerSettings, myProject); + } +} diff --git a/clwb/tests/headlesstests/com/google/idea/blaze/clwb/ProtobufTest.java b/clwb/tests/headlesstests/com/google/idea/blaze/clwb/ProtobufTest.java new file mode 100644 index 00000000000..2ea7bb332dc --- /dev/null +++ b/clwb/tests/headlesstests/com/google/idea/blaze/clwb/ProtobufTest.java @@ -0,0 +1,66 @@ +package com.google.idea.blaze.clwb; + +import static com.google.common.truth.Truth.assertThat; +import static com.google.idea.blaze.clwb.base.Assertions.assertContainsHeader; +import static com.google.idea.blaze.clwb.base.TestUtils.setIncludesCacheEnabled; + +import com.google.idea.blaze.base.bazel.BazelVersion; +import com.google.idea.blaze.clwb.base.AllowedVfsRoot; +import com.google.idea.blaze.clwb.base.ClwbHeadlessTestCase; +import com.google.idea.testing.headless.BazelVersionRule; +import com.google.idea.testing.headless.ProjectViewBuilder; +import com.intellij.util.system.OS; +import java.util.ArrayList; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class ProtobufTest extends ClwbHeadlessTestCase { + + // protobuf requires bazel 7+ + @Rule + public final BazelVersionRule bazelRule = new BazelVersionRule(7, 0); + + // on windows clang-cl is required to compile protobuf and therefore also bazel 8+ + @Rule + public final BazelVersionRule bazelWindowsRule = new BazelVersionRule(OS.Windows, 8, 0); + + @Test + public void testClwb() { + setIncludesCacheEnabled(false); + + final var errors = runSync(defaultSyncParams().build()); + errors.assertNoErrors(); + + checkProto(); + } + + @Override + protected ProjectViewBuilder projectViewText(BazelVersion version) { + final var builder = super.projectViewText(version); + + if (OS.CURRENT.equals(OS.Windows)) { + builder.addBuildFlag("--extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl"); + builder.addBuildFlag("--extra_execution_platforms=//:x64_windows-clang-cl"); + } + + return builder; + } + + @Override + protected void addAllowedVfsRoots(ArrayList roots) { + super.addAllowedVfsRoots(roots); + roots.add(AllowedVfsRoot.bazelBinRecursive(myBazelInfo, "proto")); + } + + private void checkProto() { + final var compilerSettings = findFileCompilerSettings("main/main.cc"); + + final var headersSearchRoots = compilerSettings.getHeadersSearchRoots().getAllRoots(); + assertThat(headersSearchRoots).isNotEmpty(); + + assertContainsHeader("proto/addressbook.pb.h", compilerSettings); + } +} diff --git a/clwb/tests/headlesstests/com/google/idea/blaze/clwb/VirtualIncludesCacheTest.java b/clwb/tests/headlesstests/com/google/idea/blaze/clwb/VirtualIncludesCacheTest.java new file mode 100644 index 00000000000..dcbf35234b6 --- /dev/null +++ b/clwb/tests/headlesstests/com/google/idea/blaze/clwb/VirtualIncludesCacheTest.java @@ -0,0 +1,71 @@ +package com.google.idea.blaze.clwb; + +import static com.google.common.truth.Truth.assertThat; +import static com.google.idea.blaze.clwb.base.Assertions.assertContainsHeader; +import static com.google.idea.blaze.clwb.base.Assertions.assertCachedHeader; +import static com.google.idea.blaze.clwb.base.Assertions.assertWorkspaceHeader; +import static com.google.idea.blaze.clwb.base.TestUtils.setIncludesCacheEnabled; + +import com.google.idea.blaze.clwb.base.ClwbHeadlessTestCase; +import com.google.idea.testing.headless.BazelVersionRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class VirtualIncludesCacheTest extends ClwbHeadlessTestCase { + + // use_repo_rule requires bazel 7+ + @Rule + public final BazelVersionRule bazelRule = new BazelVersionRule(7, 0); + + @Test + public void testClwb() { + setIncludesCacheEnabled(true); + + final var errors = runSync(defaultSyncParams().build()); + errors.assertNoErrors(); + + checkIncludes(); + checkImplDeps(); + } + + private void checkIncludes() { + final var compilerSettings = findFileCompilerSettings("main/virtual_includes.cc"); + + assertContainsHeader("strip_absolut/strip_absolut.h", compilerSettings); + assertCachedHeader("strip_absolut/strip_absolut.h", compilerSettings, myProject); + + assertContainsHeader("strip_absolut/generated.h", compilerSettings); + assertCachedHeader("strip_absolut/generated.h", compilerSettings, myProject); + + assertContainsHeader("strip_relative.h", compilerSettings); + assertCachedHeader("strip_relative.h", compilerSettings, myProject); + + assertContainsHeader("raw_default.h", compilerSettings); + assertWorkspaceHeader("raw_default.h", compilerSettings, myProject); + + assertContainsHeader("raw_system.h", compilerSettings); + assertWorkspaceHeader("raw_system.h", compilerSettings, myProject); + + assertContainsHeader("raw_quote.h", compilerSettings); + assertWorkspaceHeader("raw_quote.h", compilerSettings, myProject); + + assertContainsHeader("lib/transitive/generated.h", compilerSettings); + assertCachedHeader("lib/transitive/generated.h", compilerSettings, myProject); + + assertContainsHeader("sqlite3.h", compilerSettings); + assertCachedHeader("sqlite3.h", compilerSettings, myProject); + } + + private void checkImplDeps() { + final var compilerSettings = findFileCompilerSettings("lib/impl_deps/impl.cc"); + + final var headersSearchRoots = compilerSettings.getHeadersSearchRoots().getAllRoots(); + assertThat(headersSearchRoots).isNotEmpty(); + + assertContainsHeader("strip_relative.h", compilerSettings); + assertCachedHeader("strip_relative.h", compilerSettings, myProject); + } +} diff --git a/clwb/tests/headlesstests/com/google/idea/blaze/clwb/VirtualIncludesTest.java b/clwb/tests/headlesstests/com/google/idea/blaze/clwb/VirtualIncludesTest.java index 36c1829c71c..03f9a5f645b 100644 --- a/clwb/tests/headlesstests/com/google/idea/blaze/clwb/VirtualIncludesTest.java +++ b/clwb/tests/headlesstests/com/google/idea/blaze/clwb/VirtualIncludesTest.java @@ -2,16 +2,17 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.idea.blaze.clwb.base.Assertions.assertContainsHeader; +import static com.google.idea.blaze.clwb.base.TestUtils.setIncludesCacheEnabled; import com.google.idea.blaze.base.bazel.BazelVersion; import com.google.idea.blaze.clwb.base.AllowedVfsRoot; import com.google.idea.blaze.clwb.base.ClwbHeadlessTestCase; +import com.google.idea.testing.headless.BazelVersionRule; import com.google.idea.testing.headless.ProjectViewBuilder; -import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.system.OS; -import com.jetbrains.cidr.lang.workspace.OCCompilerSettings; +import com.google.idea.blaze.clwb.base.TestUtils; import java.util.ArrayList; -import org.jetbrains.annotations.Nullable; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -19,8 +20,14 @@ @RunWith(JUnit4.class) public class VirtualIncludesTest extends ClwbHeadlessTestCase { + // use_repo_rule requires bazel 7+ + @Rule + public final BazelVersionRule bazelRule = new BazelVersionRule(7, 0); + @Test public void testClwb() { + setIncludesCacheEnabled(false); + final var errors = runSync(defaultSyncParams().build()); errors.assertNoErrors(); @@ -45,26 +52,12 @@ protected ProjectViewBuilder projectViewText(BazelVersion version) { protected void addAllowedVfsRoots(ArrayList roots) { super.addAllowedVfsRoots(roots); roots.add(AllowedVfsRoot.bazelBinRecursive(myBazelInfo, "lib/strip_absolut/_virtual_includes")); - } - - private @Nullable VirtualFile findHeader(String fileName, OCCompilerSettings settings) { - final var roots = settings.getHeadersSearchRoots().getAllRoots(); - - for (final var root : roots) { - final var rootFile = root.getVirtualFile(); - if (rootFile == null) continue; - - final var headerFile = rootFile.findFileByRelativePath(fileName); - if (headerFile == null) continue; - - return headerFile; - } - - return null; + roots.add(AllowedVfsRoot.bazelBinRecursive(myBazelInfo, "lib/transitive")); + roots.add(AllowedVfsRoot.bazelBinRecursive(myBazelInfo, "external/+_repo_rules+sqlite")); } private void checkIncludes() { - final var compilerSettings = findFileCompilerSettings("main/hello-world.cc"); + final var compilerSettings = findFileCompilerSettings("main/virtual_includes.cc"); assertContainsHeader("strip_absolut/strip_absolut.h", compilerSettings); assertContainsHeader("strip_absolut/generated.h", compilerSettings); @@ -72,24 +65,26 @@ private void checkIncludes() { assertContainsHeader("raw_default.h", compilerSettings); assertContainsHeader("raw_system.h", compilerSettings); assertContainsHeader("raw_quote.h", compilerSettings); + assertContainsHeader("lib/transitive/generated.h", compilerSettings); + assertContainsHeader("sqlite3.h", compilerSettings); assertThat(findProjectFile("lib/strip_absolut/strip_absolut.h")) - .isEqualTo(findHeader("strip_absolut/strip_absolut.h", compilerSettings)); + .isEqualTo(TestUtils.resolveHeader("strip_absolut/strip_absolut.h", compilerSettings)); assertThat(findProjectFile("lib/strip_relative/include/strip_relative.h")) - .isEqualTo(findHeader("strip_relative.h", compilerSettings)); + .isEqualTo(TestUtils.resolveHeader("strip_relative.h", compilerSettings)); assertThat(findProjectFile("lib/impl_deps/impl.h")) - .isEqualTo(findHeader("lib/impl_deps/impl.h", compilerSettings)); + .isEqualTo(TestUtils.resolveHeader("lib/impl_deps/impl.h", compilerSettings)); assertThat(findProjectFile("lib/raw_files/default/raw_default.h")) - .isEqualTo(findHeader("raw_default.h", compilerSettings)); + .isEqualTo(TestUtils.resolveHeader("raw_default.h", compilerSettings)); assertThat(findProjectFile("lib/raw_files/system/raw_system.h")) - .isEqualTo(findHeader("raw_system.h", compilerSettings)); + .isEqualTo(TestUtils.resolveHeader("raw_system.h", compilerSettings)); assertThat(findProjectFile("lib/raw_files/quote/raw_quote.h")) - .isEqualTo(findHeader("raw_quote.h", compilerSettings)); + .isEqualTo(TestUtils.resolveHeader("raw_quote.h", compilerSettings)); } private void checkImplDeps() { diff --git a/clwb/tests/headlesstests/com/google/idea/blaze/clwb/base/Assertions.java b/clwb/tests/headlesstests/com/google/idea/blaze/clwb/base/Assertions.java index f1880565eb3..ad6fc093fd9 100644 --- a/clwb/tests/headlesstests/com/google/idea/blaze/clwb/base/Assertions.java +++ b/clwb/tests/headlesstests/com/google/idea/blaze/clwb/base/Assertions.java @@ -5,7 +5,10 @@ import static com.google.idea.testing.headless.Assertions.abort; import com.google.common.truth.StringSubject; +import com.google.idea.blaze.base.settings.BlazeImportSettingsManager; import com.google.idea.blaze.base.util.VfsUtil; +import com.google.idea.blaze.cpp.sync.CcIncludesCacheService; +import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -109,4 +112,28 @@ public static void assertVfsLoads(Path executionRoot, List allow abort(String.format("%s not in allowed roots: [%s], debug with: '-Dfile.system.trace.loading=%s'", child, roots, child)); } } + + public static void assertCachedHeader(String fileName, OCCompilerSettings settings, Project project) { + final var header = TestUtils.resolveHeader(fileName, settings); + assertThat(header).isNotNull(); + + final var service = CcIncludesCacheService.of(project); + assertThat(CcIncludesCacheService.getEnabled()).isTrue(); + + assertWithMessage(String.format("file does not reside in the include cache: %s", header.getPath())) + .that(header.toNioPath().startsWith(service.getCacheDirectory())) + .isTrue(); + } + + public static void assertWorkspaceHeader(String fileName, OCCompilerSettings compilerSettings, Project project) { + final var header = TestUtils.resolveHeader(fileName, compilerSettings); + assertThat(header).isNotNull(); + + final var importSettings = BlazeImportSettingsManager.getInstance(project).getImportSettings(); + assertThat(importSettings).isNotNull(); + + assertWithMessage(String.format("file does not reside in the workspace: %s", header.getPath())) + .that(header.toNioPath().startsWith(importSettings.getWorkspaceRoot())) + .isTrue(); + } } diff --git a/clwb/tests/headlesstests/com/google/idea/blaze/clwb/base/ClwbHeadlessTestCase.java b/clwb/tests/headlesstests/com/google/idea/blaze/clwb/base/ClwbHeadlessTestCase.java index 065c4e56123..5f99eac9afb 100644 --- a/clwb/tests/headlesstests/com/google/idea/blaze/clwb/base/ClwbHeadlessTestCase.java +++ b/clwb/tests/headlesstests/com/google/idea/blaze/clwb/base/ClwbHeadlessTestCase.java @@ -9,6 +9,7 @@ import com.intellij.ide.plugins.PluginManager; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.extensions.PluginId; +import com.intellij.testFramework.HeavyPlatformTestCase; import com.jetbrains.cidr.lang.CLanguageKind; import com.jetbrains.cidr.lang.workspace.OCCompilerSettings; import com.jetbrains.cidr.lang.workspace.OCResolveConfiguration; @@ -17,6 +18,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import org.jetbrains.annotations.Nullable; public abstract class ClwbHeadlessTestCase extends HeadlessTestCase { @@ -28,11 +30,14 @@ protected void setUp() throws Exception { } @Override - protected void tearDown() { + protected void tearDown() throws Exception { final var roots = new ArrayList(); addAllowedVfsRoots(roots); Assertions.assertVfsLoads(myBazelInfo.executionRoot(), roots); + HeavyPlatformTestCase.cleanupApplicationCaches(myProject); + + super.tearDown(); } private void setupSandboxBin() { @@ -50,7 +55,9 @@ private void setupSandboxBin() { assertExists(sdkBinPath.toFile()); try { - Files.createSymbolicLink(Path.of(PathManager.getBinPath()), sdkBinPath); + final var link = Path.of(PathManager.getBinPath()); + Files.deleteIfExists(link); + Files.createSymbolicLink(link, sdkBinPath); } catch (IOException e) { abort("could not create bin path symlink", e); } diff --git a/clwb/tests/headlesstests/com/google/idea/blaze/clwb/base/TestUtils.java b/clwb/tests/headlesstests/com/google/idea/blaze/clwb/base/TestUtils.java new file mode 100644 index 00000000000..a3229efba92 --- /dev/null +++ b/clwb/tests/headlesstests/com/google/idea/blaze/clwb/base/TestUtils.java @@ -0,0 +1,31 @@ +package com.google.idea.blaze.clwb.base; + +import com.intellij.openapi.util.registry.Registry; +import com.intellij.openapi.vfs.VirtualFile; +import com.jetbrains.cidr.lang.workspace.OCCompilerSettings; +import org.jetbrains.annotations.Nullable; + +public class TestUtils { + + @Nullable + public static VirtualFile resolveHeader(String fileName, OCCompilerSettings settings) { + final var roots = settings.getHeadersSearchRoots().getAllRoots(); + + for (final var root : roots) { + final var rootFile = root.getVirtualFile(); + if (rootFile == null) continue; + + final var headerFile = rootFile.findFileByRelativePath(fileName); + if (headerFile == null) continue; + + return headerFile; + } + + return null; + } + + public static void setIncludesCacheEnabled(boolean enabled) { + Registry.get("bazel.cpp.sync.allow.bazel.bin.header.search.path").setValue(!enabled); + Registry.get("bazel.cc.includes.cache.enabled").setValue(enabled); + } +} diff --git a/clwb/tests/projects/protobuf/BUILD b/clwb/tests/projects/protobuf/BUILD new file mode 100644 index 00000000000..4f91cb38759 --- /dev/null +++ b/clwb/tests/projects/protobuf/BUILD @@ -0,0 +1,8 @@ +platform( + name = "x64_windows-clang-cl", + constraint_values = [ + "@platforms//cpu:x86_64", + "@platforms//os:windows", + "@bazel_tools//tools/cpp:clang-cl", + ], +) diff --git a/clwb/tests/projects/protobuf/MODULE.bazel b/clwb/tests/projects/protobuf/MODULE.bazel new file mode 100644 index 00000000000..ad8aa9a2ee9 --- /dev/null +++ b/clwb/tests/projects/protobuf/MODULE.bazel @@ -0,0 +1,6 @@ +bazel_dep(name = "rules_cc", version = "0.1.4") +bazel_dep(name = "platforms", version = "1.0.0") +bazel_dep(name = "protobuf", version = "31.1") + +cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure_extension") +use_repo(cc_configure, "local_config_cc") \ No newline at end of file diff --git a/clwb/tests/projects/protobuf/main/BUILD b/clwb/tests/projects/protobuf/main/BUILD new file mode 100644 index 00000000000..134509e64db --- /dev/null +++ b/clwb/tests/projects/protobuf/main/BUILD @@ -0,0 +1,11 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary") + +cc_binary( + name = "main", + srcs = ["main.cc"], + deps = [ + "//proto:addressbook_cc_proto", + "@protobuf//:protobuf", + "@protobuf//src/google/protobuf/util:time_util", + ], +) diff --git a/clwb/tests/projects/protobuf/main/main.cc b/clwb/tests/projects/protobuf/main/main.cc new file mode 100644 index 00000000000..74246b799b6 --- /dev/null +++ b/clwb/tests/projects/protobuf/main/main.cc @@ -0,0 +1,95 @@ +#include +#include +#include + +#include "proto/addressbook.pb.h" + +using namespace std; + +// This function fills in a Person message based on user input. +void PromptForAddress(tutorial::Person* person) { + cout << "Enter person ID number: "; + int id; + cin >> id; + person->set_id(id); + cin.ignore(256, '\n'); + + cout << "Enter name: "; + getline(cin, *person->mutable_name()); + + cout << "Enter email address (blank for none): "; + string email; + getline(cin, email); + if (!email.empty()) { + person->set_email(email); + } + + while (true) { + cout << "Enter a phone number (or leave blank to finish): "; + string number; + getline(cin, number); + if (number.empty()) { + break; + } + + tutorial::Person::PhoneNumber* phone_number = person->add_phones(); + phone_number->set_number(number); + + cout << "Is this a mobile, home, or work phone? "; + string type; + getline(cin, type); + if (type == "mobile") { + phone_number->set_type(tutorial::Person::PHONE_TYPE_MOBILE); + } else if (type == "home") { + phone_number->set_type(tutorial::Person::PHONE_TYPE_HOME); + } else if (type == "work") { + phone_number->set_type(tutorial::Person::PHONE_TYPE_WORK); + } else { + cout << "Unknown phone type. Using default." << endl; + } + } +} + +// Main function: Reads the entire address book from a file, +// adds one person based on user input, then writes it back out to the same +// file. +int main(int argc, char* argv[]) { + // Verify that the version of the library that we linked against is + // compatible with the version of the headers we compiled against. + GOOGLE_PROTOBUF_VERIFY_VERSION; + + if (argc != 2) { + cerr << "Usage: " << argv[0] << " ADDRESS_BOOK_FILE" << endl; + return -1; + } + + tutorial::AddressBook address_book; + + { + // Read the existing address book. + fstream input(argv[1], ios::in | ios::binary); + if (!input) { + cout << argv[1] << ": File not found. Creating a new file." << endl; + } else if (!address_book.ParseFromIstream(&input)) { + cerr << "Failed to parse address book." << endl; + return -1; + } + } + + // Add an address. + PromptForAddress(address_book.add_people()); + + { + // Write the new address book back to disk. + fstream output(argv[1], ios::out | ios::trunc | ios::binary); + if (!address_book.SerializeToOstream(&output)) { + cerr << "Failed to write address book." << endl; + return -1; + } + } + + // Optional: Delete all global objects allocated by libprotobuf. + google::protobuf::ShutdownProtobufLibrary(); + + return 0; +} diff --git a/clwb/tests/projects/protobuf/proto/BUILD b/clwb/tests/projects/protobuf/proto/BUILD new file mode 100644 index 00000000000..712e04eecde --- /dev/null +++ b/clwb/tests/projects/protobuf/proto/BUILD @@ -0,0 +1,14 @@ +load("@protobuf//bazel:cc_proto_library.bzl", "cc_proto_library") +load("@protobuf//bazel:proto_library.bzl", "proto_library") + +proto_library( + name = "addressbook_proto", + srcs = ["addressbook.proto"], + deps = ["@protobuf//:timestamp_proto"], +) + +cc_proto_library( + name = "addressbook_cc_proto", + visibility = ["//visibility:public"], + deps = [":addressbook_proto"], +) diff --git a/clwb/tests/projects/protobuf/proto/addressbook.proto b/clwb/tests/projects/protobuf/proto/addressbook.proto new file mode 100644 index 00000000000..f6b85328521 --- /dev/null +++ b/clwb/tests/projects/protobuf/proto/addressbook.proto @@ -0,0 +1,28 @@ +syntax = "proto2"; + +package tutorial; + +message Person { + optional string name = 1; + optional int32 id = 2; + optional string email = 3; + + enum PhoneType { + PHONE_TYPE_UNSPECIFIED = 0; + PHONE_TYPE_MOBILE = 1; + PHONE_TYPE_HOME = 2; + PHONE_TYPE_WORK = 3; + } + + message PhoneNumber { + optional string number = 1; + optional PhoneType type = 2 [default = PHONE_TYPE_HOME]; + } + + repeated PhoneNumber phones = 4; +} + +message AddressBook { + repeated Person people = 1; +} + diff --git a/clwb/tests/projects/virtual_includes/.bazelrc b/clwb/tests/projects/virtual_includes/.bazelrc new file mode 100644 index 00000000000..b7e8bd58882 --- /dev/null +++ b/clwb/tests/projects/virtual_includes/.bazelrc @@ -0,0 +1,2 @@ +# required for sqlite and pkgconfig +build --repo_env=BAZEL_CONLYOPTS="-std=gnu17" \ No newline at end of file diff --git a/clwb/tests/projects/virtual_includes/MODULE.bazel b/clwb/tests/projects/virtual_includes/MODULE.bazel index cab3d603a6f..e981cb264c8 100644 --- a/clwb/tests/projects/virtual_includes/MODULE.bazel +++ b/clwb/tests/projects/virtual_includes/MODULE.bazel @@ -1,3 +1,16 @@ bazel_dep(name = "rules_cc", version = "0.2.8") bazel_dep(name = "platforms", version = "1.0.0") +bazel_dep(name = "rules_foreign_cc", version = "0.15.0") +http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "sqlite", + build_file = "//third_party/sqlite:BUILD.sqlite.bazel", + sha256 = "f52b72a5c319c3e516ed7a92e123139a6e87af08a2dc43d7757724f6132e6db0", + strip_prefix = "sqlite-autoconf-3350500", + urls = [ + "https://mirror.bazel.build/www.sqlite.org/2021/sqlite-autoconf-3350500.tar.gz", + "https://www.sqlite.org/2021/sqlite-autoconf-3350500.tar.gz", + ], +) diff --git a/clwb/tests/projects/virtual_includes/lib/strip_absolut/BUILD b/clwb/tests/projects/virtual_includes/lib/strip_absolut/BUILD index 0252c71ba29..97fdbf1e4a7 100644 --- a/clwb/tests/projects/virtual_includes/lib/strip_absolut/BUILD +++ b/clwb/tests/projects/virtual_includes/lib/strip_absolut/BUILD @@ -21,4 +21,5 @@ cc_library( hdrs = ["generated.h"], strip_include_prefix = "/lib", visibility = ["//visibility:public"], + deps = ["//lib/transitive"], ) diff --git a/clwb/tests/projects/virtual_includes/lib/transitive/BUILD b/clwb/tests/projects/virtual_includes/lib/transitive/BUILD new file mode 100644 index 00000000000..abd84ededd9 --- /dev/null +++ b/clwb/tests/projects/virtual_includes/lib/transitive/BUILD @@ -0,0 +1,15 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +genrule( + name = "generate", + srcs = [], + outs = ["generated.h"], + cmd = r"""echo '#define LIB_GENERATED_MACRO 1' > $@""", +) + +cc_library( + name = "transitive", + srcs = [], + hdrs = ["generated.h"], + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/clwb/tests/projects/virtual_includes/main/BUILD b/clwb/tests/projects/virtual_includes/main/BUILD index d7779f3cbfa..719983824e5 100644 --- a/clwb/tests/projects/virtual_includes/main/BUILD +++ b/clwb/tests/projects/virtual_includes/main/BUILD @@ -1,9 +1,9 @@ load("@rules_cc//cc:defs.bzl", "cc_binary") cc_binary( - name = "hello-world", + name = "virtual_includes", srcs = [ - "hello-world.cc", + "virtual_includes.cc", "//lib/raw_files:lib", ], # basically manual strip absolut, different flags required for MSVC @@ -12,6 +12,7 @@ cc_binary( "/Ilib/raw_files/default", "/external:Ilib/raw_files/system", "/external:Ilib/raw_files/quote", + "/external:W0", ], "//conditions:default": [ "-Ilib/raw_files/default", @@ -24,5 +25,6 @@ cc_binary( "//lib/strip_absolut:gen", "//lib/strip_absolut:lib", "//lib/strip_relative:lib", + "@sqlite", ], ) diff --git a/clwb/tests/projects/virtual_includes/main/hello-world.cc b/clwb/tests/projects/virtual_includes/main/virtual_includes.cc similarity index 74% rename from clwb/tests/projects/virtual_includes/main/hello-world.cc rename to clwb/tests/projects/virtual_includes/main/virtual_includes.cc index 95caba427a9..49dc88c396f 100644 --- a/clwb/tests/projects/virtual_includes/main/hello-world.cc +++ b/clwb/tests/projects/virtual_includes/main/virtual_includes.cc @@ -5,11 +5,15 @@ #include "raw_default.h" #include "raw_system.h" #include "raw_quote.h" +#include "lib/transitive/generated.h" +#include "sqlite3.h" int main() { strip_absolut_function(); strip_relative_function(); impl_deps_function(); - return GENERATED_MACRO + RAW_DEFAULT_MACRO + RAW_SYSTEM_MACRO + RAW_QUOTE_MACRO; + sqlite3_initialize(); + + return GENERATED_MACRO + RAW_DEFAULT_MACRO + RAW_SYSTEM_MACRO + RAW_QUOTE_MACRO + LIB_GENERATED_MACRO; } diff --git a/clwb/tests/projects/virtual_includes/third_party/sqlite/BUILD b/clwb/tests/projects/virtual_includes/third_party/sqlite/BUILD new file mode 100644 index 00000000000..e69de29bb2d diff --git a/clwb/tests/projects/virtual_includes/third_party/sqlite/BUILD.sqlite.bazel b/clwb/tests/projects/virtual_includes/third_party/sqlite/BUILD.sqlite.bazel new file mode 100644 index 00000000000..c98a22588da --- /dev/null +++ b/clwb/tests/projects/virtual_includes/third_party/sqlite/BUILD.sqlite.bazel @@ -0,0 +1,20 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "sqlite", + env = select({ + "@platforms//os:macos": {"AR": ""}, + "//conditions:default": {}, + }), + lib_source = ":all_srcs", + out_static_libs = ["libsqlite3.a"], + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/cpp/src/META-INF/blaze-cpp.xml b/cpp/src/META-INF/blaze-cpp.xml index 11387d72eea..7dc78dfdec0 100644 --- a/cpp/src/META-INF/blaze-cpp.xml +++ b/cpp/src/META-INF/blaze-cpp.xml @@ -37,6 +37,10 @@ + + + + @@ -52,6 +56,7 @@ +