forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make attribute and rule info extraction non-throwing
Until `bazel query` can properly handle formatter exceptions which are not i/o exceptions, buildRuleInfo must not throw in order to be usable in query output. PiperOrigin-RevId: 680575449 Change-Id: If0b55bebc62ca92a1ca0731b6489a2b1ab90eec7
- Loading branch information
1 parent
6f946cf
commit 6e6c9a8
Showing
9 changed files
with
105 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/test/java/com/google/devtools/build/lib/packages/BuildTypeTestHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2024 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.devtools.build.lib.packages; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Modifier; | ||
|
||
/** Utils for testing {@link Type}, {@link Types}, and {@link BuildType}. */ | ||
// Must live in the same package as BuildType to access non-public fields. | ||
public final class BuildTypeTestHelper { | ||
|
||
/** | ||
* Returns all build types defined in {@link Type}, {@link Types}, and {@link BuildType}. | ||
* | ||
* @param publicOnly if true, only returns public types; otherwise, returns both public and | ||
* internal package-private ones. | ||
*/ | ||
public static ImmutableList<Type<?>> getAllBuildTypes(boolean publicOnly) | ||
throws IllegalAccessException { | ||
ImmutableList.Builder<Type<?>> builder = ImmutableList.builder(); | ||
collectBuildTypeStaticFields(builder, Type.class, publicOnly); | ||
collectBuildTypeStaticFields(builder, Types.class, publicOnly); | ||
collectBuildTypeStaticFields(builder, BuildType.class, publicOnly); | ||
return builder.build(); | ||
} | ||
|
||
private static void collectBuildTypeStaticFields( | ||
ImmutableList.Builder<Type<?>> builder, Class<?> clazz, boolean publicOnly) | ||
throws IllegalAccessException { | ||
for (Field field : clazz.getDeclaredFields()) { | ||
if (Modifier.isStatic(field.getModifiers()) | ||
&& (Modifier.isPublic(field.getModifiers()) || !publicOnly) | ||
&& Type.class.isAssignableFrom(field.getType())) { | ||
builder.add((Type<?>) field.get(null)); | ||
} | ||
} | ||
} | ||
|
||
private BuildTypeTestHelper() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters