Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[6.3.0] Report dev/non-dev deps imported via non-dev/dev usages #18922

Merged
merged 2 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,28 @@ private static Optional<Event> generateFixupMessage(
String.join(", ", missingImports));
}

var nonDevImportsOfDevDeps =
ImmutableSortedSet.copyOf(Sets.intersection(expectedDevImports, actualImports));
if (!nonDevImportsOfDevDeps.isEmpty()) {
message +=
String.format(
"Imported as a regular dependency, but reported as a dev dependency by the "
+ "extension (may cause the build to fail when used by other modules):\n"
+ " %s\n\n",
String.join(", ", nonDevImportsOfDevDeps));
}

var devImportsOfNonDevDeps =
ImmutableSortedSet.copyOf(Sets.intersection(expectedImports, actualDevImports));
if (!devImportsOfNonDevDeps.isEmpty()) {
message +=
String.format(
"Imported as a dev dependency, but reported as a regular dependency by the "
+ "extension (may cause the build to fail when used by other modules):\n"
+ " %s\n\n",
String.join(", ", devImportsOfNonDevDeps));
}

var indirectDepImports =
ImmutableSortedSet.copyOf(
Sets.difference(Sets.intersection(allActualImports, allRepos), allExpectedImports));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1761,13 +1761,15 @@ public void extensionMetadata() throws Exception {
" ext,",
" 'indirect_dep',",
" 'invalid_dep',",
" 'dev_as_non_dev_dep',",
" my_direct_dep = 'direct_dep',",
")",
"ext_dev = use_extension('@ext//:defs.bzl', 'ext', dev_dependency = True)",
"use_repo(",
" ext_dev,",
" 'indirect_dev_dep',",
" 'invalid_dev_dep',",
" 'non_dev_as_dev_dep',",
" my_direct_dev_dep = 'direct_dev_dep',",
")");
scratch.file(workspaceRoot.getRelative("BUILD").getPathString());
Expand Down Expand Up @@ -1796,9 +1798,12 @@ public void extensionMetadata() throws Exception {
" data_repo(name='missing_direct_dev_dep')",
" data_repo(name='indirect_dep')",
" data_repo(name='indirect_dev_dep')",
" data_repo(name='dev_as_non_dev_dep')",
" data_repo(name='non_dev_as_dev_dep')",
" return ctx.extension_metadata(",
" root_module_direct_deps=['direct_dep', 'missing_direct_dep'],",
" root_module_direct_dev_deps=['direct_dev_dep', 'missing_direct_dev_dep'],",
" root_module_direct_deps=['direct_dep', 'missing_direct_dep', 'non_dev_as_dev_dep'],",
" root_module_direct_dev_deps=['direct_dev_dep', 'missing_direct_dev_dep',"
+ " 'dev_as_non_dev_dep'],",
" )",
"ext=module_extension(implementation=_ext_impl)");

Expand All @@ -1822,19 +1827,28 @@ public void extensionMetadata() throws Exception {
+ " build to fail):\n"
+ " missing_direct_dep, missing_direct_dev_dep\n"
+ "\n"
+ "Imported as a regular dependency, but reported as a dev dependency by the"
+ " extension (may cause the build to fail when used by other modules):\n"
+ " dev_as_non_dev_dep\n"
+ "\n"
+ "Imported as a dev dependency, but reported as a regular dependency by the"
+ " extension (may cause the build to fail when used by other modules):\n"
+ " non_dev_as_dev_dep\n"
+ "\n"
+ "Imported, but reported as indirect dependencies by the extension:\n"
+ " indirect_dep, indirect_dev_dep\n"
+ "\n"
+ "\033[35m\033[1m ** You can use the following buildozer command(s) to fix these"
+ " issues:\033[0m\n"
+ "\n"
+ "buildozer 'use_repo_add @ext//:defs.bzl ext missing_direct_dep' //MODULE.bazel:all\n"
+ "buildozer 'use_repo_remove @ext//:defs.bzl ext indirect_dep invalid_dep'"
+ " //MODULE.bazel:all\n"
+ "buildozer 'use_repo_add dev @ext//:defs.bzl ext missing_direct_dev_dep'"
+ "buildozer 'use_repo_add @ext//:defs.bzl ext missing_direct_dep non_dev_as_dev_dep'"
+ " //MODULE.bazel:all\n"
+ "buildozer 'use_repo_remove dev @ext//:defs.bzl ext indirect_dev_dep invalid_dev_dep'"
+ " //MODULE.bazel:all",
+ "buildozer 'use_repo_remove @ext//:defs.bzl ext dev_as_non_dev_dep"
+ " indirect_dep invalid_dep' //MODULE.bazel:all\n"
+ "buildozer 'use_repo_add dev @ext//:defs.bzl ext dev_as_non_dev_dep"
+ " missing_direct_dev_dep' //MODULE.bazel:all\n"
+ "buildozer 'use_repo_remove dev @ext//:defs.bzl ext indirect_dev_dep invalid_dev_dep"
+ " non_dev_as_dev_dep' //MODULE.bazel:all",
ImmutableSet.of(EventKind.WARNING));
}

Expand Down Expand Up @@ -1904,6 +1918,10 @@ public void extensionMetadata_all() throws Exception {
+ " build to fail):\n"
+ " missing_direct_dep, missing_direct_dev_dep\n"
+ "\n"
+ "Imported as a dev dependency, but reported as a regular dependency by the"
+ " extension (may cause the build to fail when used by other modules):\n"
+ " direct_dev_dep, indirect_dev_dep\n"
+ "\n"
+ "\033[35m\033[1m ** You can use the following buildozer command(s) to fix these"
+ " issues:\033[0m\n"
+ "\n"
Expand Down Expand Up @@ -1983,6 +2001,10 @@ public void extensionMetadata_allDev() throws Exception {
+ " build to fail):\n"
+ " missing_direct_dep, missing_direct_dev_dep\n"
+ "\n"
+ "Imported as a regular dependency, but reported as a dev dependency by the"
+ " extension (may cause the build to fail when used by other modules):\n"
+ " direct_dep, indirect_dep\n"
+ "\n"
+ "\033[35m\033[1m ** You can use the following buildozer command(s) to fix these"
+ " issues:\033[0m\n"
+ "\n"
Expand Down