Skip to content

Commit

Permalink
Remove debug specific configurations from ComponentsConfiguration
Browse files Browse the repository at this point in the history
Summary:
## Important
This is a "copy" of D52563388, which was reverted due to three classes that were still referring to the old configurations and somehow Sandcastle missed. I'm updating those references on top of this copy.

## Original Description
This diff removes debug specific configurations from `ComponentsConfiguration` in Litho into a new abstraction named `LithoDebugConfigurations`. The goal is that we move further into having `ComponentsConfiguration` to be more focused in internals/behaviors of Litho.

Reviewed By: adityasharat

Differential Revision: D52779201

fbshipit-source-id: 8f540efbe2691f7b8c22d1b199a14ff02f986c9c
  • Loading branch information
Fabio Carballo authored and facebook-github-bot committed Jan 15, 2024
1 parent 8fe6f93 commit 0e03c02
Show file tree
Hide file tree
Showing 51 changed files with 201 additions and 143 deletions.
3 changes: 2 additions & 1 deletion litho-core/src/main/java/com/facebook/litho/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.facebook.infer.annotation.ThreadSafe;
import com.facebook.litho.annotations.EventHandlerRebindMode;
import com.facebook.litho.config.ComponentsConfiguration;
import com.facebook.litho.config.LithoDebugConfigurations;
import com.facebook.litho.drawable.ComparableColorDrawable;
import com.facebook.litho.drawable.ComparableDrawable;
import com.facebook.rendercore.Equivalence;
Expand Down Expand Up @@ -2304,7 +2305,7 @@ static LinkedList<String> generateHierarchy(String globalKey) {
*/
@Nullable
private final AttributesHolder mDebugAttributesHolder =
ComponentsConfiguration.isDebugModeEnabled ? new AttributesHolder() : null;
LithoDebugConfigurations.isDebugModeEnabled ? new AttributesHolder() : null;

@Override
public <T> void setDebugAttributeKey(AttributeKey<T> attributeKey, T value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.facebook.litho

import android.content.Context
import com.facebook.litho.config.ComponentsConfiguration
import com.facebook.litho.config.LithoDebugConfigurations
import com.facebook.rendercore.visibility.VisibilityBoundsTransformer

object ComponentContextUtils {
Expand All @@ -37,7 +38,7 @@ object ComponentContextUtils {
componentsConfig = ComponentsConfiguration.defaultInstance,
areTransitionsEnabled = AnimationsDebug.areTransitionsEnabled(context),
isVisibilityProcessingEnabled = true,
incrementalMountEnabled = !ComponentsConfiguration.isIncrementalMountGloballyDisabled,
incrementalMountEnabled = !LithoDebugConfigurations.isIncrementalMountGloballyDisabled,
errorEventHandler = DefaultErrorEventHandler.INSTANCE,
logTag = logTagToUse,
logger = loggerToUse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import com.facebook.infer.annotation.ThreadSafe;
import com.facebook.litho.LithoLifecycleProvider.LithoLifecycle;
import com.facebook.litho.config.ComponentsConfiguration;
import com.facebook.litho.config.LithoDebugConfigurations;
import com.facebook.litho.debug.AttributionUtils;
import com.facebook.litho.debug.DebugOverlay;
import com.facebook.litho.debug.LithoDebugEvent;
Expand Down Expand Up @@ -521,7 +522,7 @@ protected ComponentTree(Builder builder) {
null,
builder.parentTreeProps);

if (ComponentsConfiguration.isTimelineEnabled) {
if (LithoDebugConfigurations.isTimelineEnabled) {
mTimeMachine = new DebugComponentTreeTimeMachine(this);
} else {
mTimeMachine = null;
Expand Down Expand Up @@ -559,7 +560,7 @@ protected ComponentTree(Builder builder) {
}

private static boolean incrementalMountGloballyDisabled() {
return ComponentsConfiguration.isIncrementalMountGloballyDisabled;
return LithoDebugConfigurations.isIncrementalMountGloballyDisabled;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions litho-core/src/main/java/com/facebook/litho/DebugDraw.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import android.graphics.Paint
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.view.View
import com.facebook.litho.config.ComponentsConfiguration
import com.facebook.litho.config.LithoDebugConfigurations

/** Draw operations used in developer options. */
internal object DebugDraw {
Expand Down Expand Up @@ -56,10 +56,10 @@ internal object DebugDraw {

@JvmStatic
fun draw(host: ComponentHost, canvas: Canvas) {
if (ComponentsConfiguration.debugHighlightInteractiveBounds) {
if (LithoDebugConfigurations.debugHighlightInteractiveBounds) {
highlightInteractiveBounds(host, canvas)
}
if (ComponentsConfiguration.debugHighlightMountBounds) {
if (LithoDebugConfigurations.debugHighlightMountBounds) {
highlightMountBounds(host, canvas)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.facebook.litho

import android.util.Log
import com.facebook.litho.config.ComponentsConfiguration
import com.facebook.litho.config.LithoDebugConfigurations
import com.facebook.rendercore.ErrorReporterDelegate
import com.facebook.rendercore.LogLevel
import java.lang.RuntimeException
Expand Down Expand Up @@ -59,7 +59,7 @@ open class DefaultComponentsReporter : ErrorReporterDelegate {
}

private fun applyOnInternalBuild(block: () -> Unit) {
if (ComponentsConfiguration.IS_INTERNAL_BUILD) {
if (LithoDebugConfigurations.isDebugModeEnabled) {
block()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.facebook.litho

import android.os.Build
import android.os.Trace
import com.facebook.litho.config.ComponentsConfiguration
import com.facebook.litho.config.LithoDebugConfigurations
import com.facebook.rendercore.RenderCoreSystrace
import com.facebook.rendercore.Systracer
import com.facebook.rendercore.Systracer.ArgsBuilder
Expand Down Expand Up @@ -57,7 +57,7 @@ open class DefaultComponentsSystrace : Systracer {
}

override fun isTracing(): Boolean =
ComponentsConfiguration.IS_INTERNAL_BUILD &&
LithoDebugConfigurations.isDebugModeEnabled &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 &&
(Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || Trace.isEnabled())

Expand Down
4 changes: 3 additions & 1 deletion litho-core/src/main/java/com/facebook/litho/LayoutState.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.facebook.litho.EndToEndTestingExtension.EndToEndTestingExtensionInput;
import com.facebook.litho.LithoViewAttributesExtension.ViewAttributesInput;
import com.facebook.litho.config.ComponentsConfiguration;
import com.facebook.litho.config.LithoDebugConfigurations;
import com.facebook.rendercore.LayoutCache;
import com.facebook.rendercore.LayoutResult;
import com.facebook.rendercore.MountItemsPool;
Expand Down Expand Up @@ -679,7 +680,8 @@ public TransitionId getRootTransitionId() {

/** Debug-only: return a string representation of this LayoutState and its LayoutOutputs. */
String dumpAsString() {
if (!ComponentsConfiguration.isDebugModeEnabled && !ComponentsConfiguration.isEndToEndTestRun) {
if (!LithoDebugConfigurations.isDebugModeEnabled
&& !ComponentsConfiguration.isEndToEndTestRun) {
throw new RuntimeException(
"LayoutState#dumpAsString() should only be called in debug mode or from e2e tests!");
}
Expand Down
6 changes: 3 additions & 3 deletions litho-core/src/main/java/com/facebook/litho/LithoNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import com.facebook.infer.annotation.ThreadConfined
import com.facebook.litho.CommonProps.DefaultLayoutProps
import com.facebook.litho.Transition.TransitionKeyType
import com.facebook.litho.annotations.ImportantForAccessibility
import com.facebook.litho.config.ComponentsConfiguration
import com.facebook.litho.config.LithoDebugConfigurations
import com.facebook.litho.drawable.ComparableColorDrawable
import com.facebook.rendercore.LayoutCache
import com.facebook.rendercore.LayoutContext
Expand Down Expand Up @@ -103,7 +103,7 @@ open class LithoNode : Node<LithoLayoutContext>, Cloneable {

val debugLayoutEditor: LayoutProps?
get() {
if (ComponentsConfiguration.isDebugModeEnabled && debugLayoutProps == null) {
if (LithoDebugConfigurations.isDebugModeEnabled && debugLayoutProps == null) {
debugLayoutProps = DefaultLayoutProps()
}
return debugLayoutProps
Expand Down Expand Up @@ -1470,7 +1470,7 @@ open class LithoNode : Node<LithoLayoutContext>, Cloneable {
}

private fun applyOverridesRecursive(node: LithoNode) {
if (ComponentsConfiguration.isDebugModeEnabled) {
if (LithoDebugConfigurations.isDebugModeEnabled) {
DebugComponent.applyOverrides(node.tailComponentContext, node)
for (i in 0 until node.childCount) {
applyOverridesRecursive(node.getChildAt(i))
Expand Down
4 changes: 2 additions & 2 deletions litho-core/src/main/java/com/facebook/litho/LithoNodeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import androidx.core.view.ViewCompat
import com.facebook.litho.Component.MountType
import com.facebook.litho.MountSpecLithoRenderUnit.UpdateState
import com.facebook.litho.annotations.ImportantForAccessibility
import com.facebook.litho.config.ComponentsConfiguration
import com.facebook.litho.config.LithoDebugConfigurations
import com.facebook.litho.drawable.BorderColorDrawable
import com.facebook.rendercore.LayoutResult
import com.facebook.rendercore.MountState
Expand Down Expand Up @@ -397,7 +397,7 @@ object LithoNodeUtils {

@JvmStatic
fun getDebugKey(componentKey: String?, @OutputUnitType outputUnitType: Int): String? =
if (ComponentsConfiguration.isDebugModeEnabled) {
if (LithoDebugConfigurations.isDebugModeEnabled) {
null
} else {
when (outputUnitType) {
Expand Down
5 changes: 3 additions & 2 deletions litho-core/src/main/java/com/facebook/litho/LithoReducer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.graphics.Rect
import androidx.collection.LongSparseArray
import androidx.core.view.ViewCompat
import com.facebook.litho.config.ComponentsConfiguration
import com.facebook.litho.config.LithoDebugConfigurations
import com.facebook.rendercore.LayoutResult
import com.facebook.rendercore.MountState
import com.facebook.rendercore.RenderTreeNode
Expand Down Expand Up @@ -130,7 +131,7 @@ object LithoReducer {
layoutState.mLayoutResult = null

// enabled for debugging and end to end tests
if (ComponentsConfiguration.isDebugModeEnabled || ComponentsConfiguration.isEndToEndTestRun) {
if (LithoDebugConfigurations.isDebugModeEnabled || ComponentsConfiguration.isEndToEndTestRun) {
layoutState.mRoot = nodeForSaving
layoutState.mLayoutResult = layoutResultForSaving
return
Expand Down Expand Up @@ -902,7 +903,7 @@ object LithoReducer {
private fun LithoNode.getDebugHierarchy(
parentHierarchy: DebugHierarchy.Node? = null,
): DebugHierarchy.Node? {
if (!ComponentsConfiguration.isDebugHierarchyEnabled) {
if (!LithoDebugConfigurations.isDebugHierarchyEnabled) {
return null
}
val infos: List<ScopedComponentInfo> = scopedComponentInfos
Expand Down
4 changes: 2 additions & 2 deletions litho-core/src/main/java/com/facebook/litho/Resolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.facebook.litho

import androidx.annotation.IntDef
import androidx.annotation.VisibleForTesting
import com.facebook.litho.config.ComponentsConfiguration
import com.facebook.litho.config.LithoDebugConfigurations
import com.facebook.litho.debug.LithoDebugEvent
import com.facebook.litho.debug.LithoDebugEventAttributes
import com.facebook.rendercore.debug.DebugEventDispatcher
Expand Down Expand Up @@ -378,7 +378,7 @@ object Resolver {
c.treeProps = descendants
}

if (ComponentsConfiguration.isDebugModeEnabled) {
if (LithoDebugConfigurations.isDebugModeEnabled) {
DebugComponent.applyOverrides(c, component, c.globalKey)
}
return c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package com.facebook.litho

import com.facebook.litho.config.ComponentsConfiguration
import com.facebook.litho.config.LithoDebugConfigurations

/** Hosts API to debug state */
val KStateContainer.state: List<Any?>
get() =
if (ComponentsConfiguration.isDebugModeEnabled) {
if (LithoDebugConfigurations.isDebugModeEnabled) {
states
} else {
error("State should only be read by debugging utilities.")
Expand Down
5 changes: 3 additions & 2 deletions litho-core/src/main/java/com/facebook/litho/ThreadUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.os.Process
import androidx.annotation.IntDef
import androidx.annotation.VisibleForTesting
import com.facebook.litho.config.ComponentsConfiguration
import com.facebook.litho.config.LithoDebugConfigurations

/** Thread assertion utilities. */
object ThreadUtils {
Expand Down Expand Up @@ -61,15 +62,15 @@ object ThreadUtils {

@JvmStatic
fun assertHoldsLock(lock: Any) {
if (!ComponentsConfiguration.IS_INTERNAL_BUILD) {
if (!LithoDebugConfigurations.isDebugModeEnabled) {
return
}
check(Thread.holdsLock(lock)) { "This method should be called while holding the lock" }
}

@JvmStatic
fun assertDoesntHoldLock(lock: Any) {
if (!ComponentsConfiguration.IS_INTERNAL_BUILD) {
if (!LithoDebugConfigurations.isDebugModeEnabled) {
return
}
check(!Thread.holdsLock(lock)) { "This method should be called outside the lock." }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,31 @@ internal constructor(

companion object {

@JvmField var defaultInstance: ComponentsConfiguration = ComponentsConfiguration()
/**
* This is just a proxy to [LithoDebugConfigurations.isDebugModeEnabled]. We have to keep it
* until we release a new oss version and we can refer to [LithoDebugConfigurations] directly on
* Flipper.
*/
@Deprecated("Use the LithoDebugConfigurations instead")
var isDebugModeEnabled: Boolean
get() = LithoDebugConfigurations.isDebugModeEnabled
set(value) {
LithoDebugConfigurations.isDebugModeEnabled = value
}

/**
* Indicates whether this is an internal build. Note that the implementation of `BuildConfig ` *
* that this class is compiled against may not be the one that is included in the APK. See:
* [android_build_config](http://facebook.github.io/buck/rule/android_build_config.html).
* This is just a proxy to [LithoDebugConfigurations.isDebugHierarchyEnabled]. We have to keep
* it until we release a new oss version and we can refer to [LithoDebugConfigurations] directly
* on Flipper.
*/
@JvmField val IS_INTERNAL_BUILD: Boolean = BuildConfig.IS_INTERNAL_BUILD
@Deprecated("Use the LithoDebugConfigurations instead")
var isDebugHierarchyEnabled: Boolean
get() = LithoDebugConfigurations.isDebugHierarchyEnabled
set(value) {
LithoDebugConfigurations.isDebugHierarchyEnabled = value
}

@JvmField var defaultInstance: ComponentsConfiguration = ComponentsConfiguration()

/** Indicates that the incremental mount helper is required for this build. */
@JvmField val USE_INCREMENTAL_MOUNT_HELPER: Boolean = BuildConfig.USE_INCREMENTAL_MOUNT_HELPER
Expand All @@ -105,21 +122,6 @@ internal constructor(
*/
const val DEFAULT_CHANGE_SET_THREAD_PRIORITY: Int = 0

@JvmField var isDebugModeEnabled: Boolean = IS_INTERNAL_BUILD

/**
* Option to enabled debug mode. This will save extra data associated with each node and allow
* more info about the hierarchy to be retrieved. Used to enable stetho integration. It is
* highly discouraged to enable this in production builds. Due to how the Litho releases are
* distributed in open source IS_INTERNAL_BUILD will always be false. It is therefore required
* to override this value using your own application build configs. Recommended place for this
* is in a Application subclass onCreate() method.
*/
@JvmField var isRenderInfoDebuggingEnabled: Boolean = isDebugModeEnabled

/** Lightweight tracking of component class hierarchy of MountItems. */
@JvmField var isDebugHierarchyEnabled: Boolean = false

/**
* Populates additional metadata to find mounted components at runtime. Defaults to the presence
* of an
Expand Down Expand Up @@ -158,9 +160,6 @@ internal constructor(
*/
@JvmField var computeRangeOnSyncLayout: Boolean = false

/** When `true`, disables incremental mount globally. */
@JvmField var isIncrementalMountGloballyDisabled: Boolean = false

/** Keeps the litho layout result tree in the LayoutState. This will increase memory use. */
@JvmField var keepLayoutResults: Boolean = false

Expand All @@ -173,10 +172,6 @@ internal constructor(

@JvmField var hostComponentPoolSize: Int = 30

/** When `true` ComponentTree records state change snapshots */
@JvmField var isTimelineEnabled: Boolean = isRenderInfoDebuggingEnabled
@JvmField var timelineDocsLink: String? = null

/** Skip checking for root component and tree-props while layout */
@JvmField var isSkipRootCheckingEnabled: Boolean = false
@JvmField var enableComputeLayoutAsyncAfterInsertion: Boolean = true
Expand Down Expand Up @@ -206,14 +201,7 @@ internal constructor(
@JvmField var bindOnSameComponentTree: Boolean = true
@JvmField var enableStateUpdatesBatching: Boolean = true
@JvmField var componentsLogger: ComponentsLogger? = null

/** Debug option to highlight interactive areas in mounted components. */
@JvmField var debugHighlightInteractiveBounds: Boolean = false

/** Debug option to highlight mount bounds of mounted components. */
@JvmField var debugHighlightMountBounds: Boolean = false
@JvmField var isEventHandlerRebindLoggingEnabled: Boolean = false
@JvmField var eventHandlerRebindLoggingSamplingRate: Int = 0
@JvmField var isObjectTreePropEnabled: Boolean = false

/**
Expand Down
Loading

0 comments on commit 0e03c02

Please sign in to comment.