Build changes to support other embedders other than chromium

The embedder is supposed to:
1) Set perfetto_build_with_embedder = true in its
   build_overrides/build.gni
2) Define protobuf targets and have a proto_library.gni
   that is API compatible with perfetto or chromium ones.
3) Set perfetto_protobuf_target_prefix to the GN path
   that contains the proto targets.

This change:
- Introduces a perfetto_build_with_embedder bool.
- Rename build_with_android -> perfetto_build_with_android
- Rename build_standalone -> perfetto_build_standalone

Change-Id: Ib8f4ab5be494c591e980158c1d2ea018b0f6298b
diff --git a/BUILD.gn b/BUILD.gn
index 9b69d54..a0a0285 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -13,14 +13,15 @@
 # limitations under the License.
 
 import("gn/perfetto.gni")
-if (!build_with_chromium) {
+
+if (perfetto_build_standalone || perfetto_build_with_android) {
   import("//gn/standalone/android.gni")
 } else {
   import("//build/config/android/config.gni")
 }
 
 # For use_libfuzzer.
-if (!build_with_chromium) {
+if (perfetto_build_standalone || perfetto_build_with_android) {
   import("//gn/standalone/sanitizers/vars.gni")
 } else {
   import("//build/config/sanitizers/sanitizers.gni")
@@ -34,10 +35,11 @@
 
   # libunwindstack requires API level 26 or newer.
   should_build_heapprofd =
-      !build_with_chromium && is_clang && (is_linux || is_android) &&
-      (!is_android || android_api_level >= 26 || build_with_android)
+      (perfetto_build_standalone || perfetto_build_with_android) && is_clang &&
+      (is_linux || is_android) &&
+      (!is_android || android_api_level >= 26 || perfetto_build_with_android)
 }
-assert(!monolithic_binaries || !build_with_android)
+assert(!monolithic_binaries || !perfetto_build_with_android)
 
 group("all") {
   testonly = true  # allow to build also test targets
@@ -45,35 +47,35 @@
     ":perfetto_unittests",
     "src/protozero/protoc_plugin($host_toolchain)",
   ]
-  if (!build_with_chromium) {
+  if (perfetto_build_standalone || perfetto_build_with_android) {
     deps += [
       ":perfetto",
-      ":perfetto_benchmarks",
       ":perfetto_integrationtests",
       ":traced",
       ":traced_probes",
       "protos/perfetto/config:merged_config",  # For syntax-checking the proto.
       "src/ipc/protoc_plugin:ipc_plugin($host_toolchain)",
-      "test/configs",
       "tools:protoc_helper",
-      "tools/ftrace_proto_gen:ftrace_proto_gen",
-      "tools/proto_to_cpp",
     ]
-    if (!build_with_android) {
+    if (perfetto_build_standalone) {
       deps += [
+        ":perfetto_benchmarks",
         ":trace_processor",
         "src/tracing:consumer_api_test",
+        "test/configs",
+        "tools/ftrace_proto_gen:ftrace_proto_gen",
+        "tools/proto_to_cpp",
         "tools/trace_to_text",
       ]
-    }
-    if (is_linux || is_android) {
-      deps += [ "tools/skippy" ]
-    }
-    if (is_linux) {
-      deps += [ "tools:pipestats" ]
-    }
-    if (use_libfuzzer) {
-      deps += [ ":fuzzers" ]
+      if (is_linux || is_android) {
+        deps += [ "tools/skippy" ]
+      }
+      if (is_linux) {
+        deps += [ "tools:pipestats" ]
+      }
+      if (use_libfuzzer) {
+        deps += [ ":fuzzers" ]
+      }
     }
   }
 }
@@ -88,7 +90,7 @@
   ]
 }
 
-if (build_standalone) {
+if (perfetto_build_standalone) {
   group("ui") {
     deps = [
       "ui",
@@ -114,7 +116,7 @@
     "src/tracing:unittests",
   ]
 
-  if (!build_with_chromium) {
+  if (perfetto_build_standalone || perfetto_build_with_android) {
     deps += [
       "src/ipc:unittests",
       "src/perfetto_cmd:unittests",
@@ -130,23 +132,12 @@
     # built using GCC in the Android tree.
     deps += [ "src/profiling/memory:unittests" ]
   }
-  if (build_standalone && !is_android) {
+  if (perfetto_build_standalone && !is_android) {
     deps += [ "src/trace_processor:unittests" ]
   }
 }
 
-if (!build_with_chromium) {
-  executable("perfetto_benchmarks") {
-    testonly = true
-    deps = [
-      "gn:default_deps",
-      "src/traced/probes/ftrace:benchmarks",
-      "src/tracing:tracing_benchmarks",
-      "test:benchmark_main",
-      "test:end_to_end_benchmarks",
-    ]
-  }
-
+if (perfetto_build_standalone || perfetto_build_with_android) {
   executable("perfetto_integrationtests") {
     testonly = true
     deps = [
@@ -155,10 +146,10 @@
       "src/traced/probes/ftrace:integrationtests",
       "test:end_to_end_integrationtests",
     ]
-    if (build_standalone && !is_android) {
+    if (perfetto_build_standalone && !is_android) {
       deps += [ "src/trace_processor:integrationtests" ]
     }
-    if (build_with_android) {
+    if (perfetto_build_with_android) {
       cflags = [ "-DPERFETTO_BUILD_WITH_ANDROID" ]
     }
   }
@@ -218,7 +209,7 @@
     if (is_android) {
       deps += [ "src/base:android_task_runner" ]
     }
-    if (build_with_android) {
+    if (perfetto_build_with_android) {
       cflags = [ "-DPERFETTO_BUILD_WITH_ANDROID" ]
       libs = [
         "binder",
@@ -228,7 +219,7 @@
     }
   }
 
-  if (build_with_android) {
+  if (perfetto_build_with_android) {
     executable("trace_to_text") {
       testonly = true
       deps = [
@@ -246,10 +237,15 @@
       ]
     }
   }
-}
+}  # if (perfetto_build_standalone || perfetto_build_with_android)
 
-if (build_with_chromium) {
-  component("libperfetto") {
+if (perfetto_build_with_embedder) {
+  if (build_with_chromium) {
+    libperfetto_target_type = "component"
+  } else {
+    libperfetto_target_type = "source_set"
+  }
+  target(libperfetto_target_type, "libperfetto") {
     public_configs = [ "gn:public_config" ]
     deps = [
       "src/tracing",
@@ -264,7 +260,18 @@
   }
 }
 
-if (!build_with_chromium) {
+if (perfetto_build_standalone) {
+  executable("perfetto_benchmarks") {
+    testonly = true
+    deps = [
+      "gn:default_deps",
+      "src/traced/probes/ftrace:benchmarks",
+      "src/tracing:tracing_benchmarks",
+      "test:benchmark_main",
+      "test:end_to_end_benchmarks",
+    ]
+  }
+
   group("fuzzers") {
     testonly = true
     deps = [
@@ -275,7 +282,7 @@
   }
 }
 
-if (!build_with_chromium) {
+if (perfetto_build_with_android) {
   # TODO(fmayer): Investigate shared library for common pieces.
   shared_library("heapprofd_client") {
     deps = [
diff --git a/gn/BUILD.gn b/gn/BUILD.gn
index ee30701..4d62eac 100644
--- a/gn/BUILD.gn
+++ b/gn/BUILD.gn
@@ -13,11 +13,12 @@
 # limitations under the License.
 
 import("perfetto.gni")
+import("proto_library.gni")
 
 # Used in production targets (i.e. testonly == false) for the FRIEND_TEST_*
 # macros.
 group("gtest_prod_config") {
-  if (!build_with_chromium) {
+  if (perfetto_build_standalone || perfetto_build_with_android) {
     public_configs = [ "//buildtools:googletest_prod_config" ]
   } else {
     public_configs = [ ":gtest_config" ]
@@ -25,7 +26,7 @@
 }
 
 config("gtest_config") {
-  if (build_with_chromium) {
+  if (perfetto_build_with_embedder) {
     include_dirs = [ "//testing/gtest/include" ]
   }
 }
@@ -35,7 +36,7 @@
 
   public_configs = [ ":gtest_config" ]
 
-  if (!build_with_chromium) {
+  if (perfetto_build_standalone || perfetto_build_with_android) {
     public_deps = [
       "//buildtools:gmock",
       "//buildtools:gtest",
@@ -51,7 +52,7 @@
 group("gtest_main") {
   testonly = true
 
-  if (!build_with_chromium) {
+  if (perfetto_build_standalone || perfetto_build_with_android) {
     public_deps = [
       "//buildtools:gtest_main",
     ]
@@ -65,36 +66,24 @@
 # protoc compiler library, for building protoc plugins on the host.
 if (current_toolchain == host_toolchain) {
   group("protoc_lib_deps") {
-    if (!build_with_chromium) {
-      public_deps = [
-        "//buildtools:protoc_lib",
-      ]
-    } else {
-      public_deps = [
-        "//third_party/protobuf:protoc_lib",
-      ]
-    }
+    public_deps = [
+      "${perfetto_protobuf_target_prefix}:protoc_lib",
+    ]
   }
 }
 
 group("protobuf_full_deps") {
   testonly = true
-  if (!build_with_chromium) {
-    public_deps = [
-      "//buildtools:protobuf_full",
-    ]
-  } else {
-    public_deps = [
-      "//third_party/protobuf:protobuf_full",
-    ]
-  }
+  public_deps = [
+    "${perfetto_protobuf_target_prefix}:protobuf_full",
+  ]
 }
 
 # All targets should depend on this target to inherit the right flags and
 # include directories.
 group("default_deps") {
   public_configs = [ ":default_config" ]
-  if (!build_with_chromium) {
+  if (perfetto_build_standalone || perfetto_build_with_android) {
     public_deps = [
       "//gn/standalone/libc++:deps",
       "//gn/standalone/sanitizers:deps",
@@ -137,7 +126,7 @@
 # For now JsonCpp is supported only in standalone builds outside of Android or
 # Chromium.
 group("jsoncpp_deps") {
-  if (build_standalone) {
+  if (perfetto_build_standalone) {
     public_configs = [ "//buildtools:jsoncpp_config" ]
     public_deps = [
       "//buildtools:jsoncpp",
diff --git a/gn/fuzzer.gni b/gn/fuzzer.gni
index a6ee675..ace0356 100644
--- a/gn/fuzzer.gni
+++ b/gn/fuzzer.gni
@@ -12,9 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build_overrides/build.gni")
+import("perfetto.gni")
 
-if (!build_with_chromium) {
+if (perfetto_build_standalone) {
   import("//gn/standalone/fuzzer.gni")
 } else {
   # TODO: integrate fuzzer support for chromium builds.
diff --git a/gn/ipc_library.gni b/gn/ipc_library.gni
index 5d0df92..064f4eb 100644
--- a/gn/ipc_library.gni
+++ b/gn/ipc_library.gni
@@ -12,9 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build_overrides/build.gni")
+import("perfetto.gni")
 
-if (!build_with_chromium) {
+if (perfetto_build_standalone || perfetto_build_with_android) {
   import("//gn/standalone/proto_library.gni")
 } else {
   import("//third_party/protobuf/proto_library.gni")
diff --git a/gn/perfetto.gni b/gn/perfetto.gni
index 5eb7ecd..3e06d60 100644
--- a/gn/perfetto.gni
+++ b/gn/perfetto.gni
@@ -14,25 +14,66 @@
 
 import("//build_overrides/build.gni")
 
+# Summary of our build configurations:
+
+# 1. Standalone builds
+#    perfetto_build_standalone = true
+#    perfetto_build_with_embedder = false
+#    perfetto_build_with_android = false
+#    build_with_chromium = false
+
+# 2. Android tree builds
+#    perfetto_build_standalone = false
+#    perfetto_build_with_android = true
+#    perfetto_build_with_embedder = false
+#    build_with_chromium = false
+
+# 3. Chromium tree builds
+#    perfetto_build_standalone = false
+#    perfetto_build_with_android = false
+#    perfetto_build_with_embedder = true
+#    build_with_chromium = true
+
+# 4. Builds in other embedder trees
+#    perfetto_build_standalone = false
+#    perfetto_build_with_android = false
+#    perfetto_build_with_embedder = true
+#    build_with_chromium = false
+
+# Note that |build_with_chromium| is a global convention used by several
+# projects, set outside of our control.
+
 declare_args() {
   # The Android blueprint file generator overrides this to true.
-  build_with_android = false
+  perfetto_build_with_android = false
 
   # Whether the ftrace producer and the service should be started
   # by the integration test or assumed to be running.
   start_daemons_for_testing = true
 }
 
-build_standalone = !build_with_android && !build_with_chromium
+if (!defined(perfetto_build_with_embedder)) {
+  perfetto_build_with_embedder = build_with_chromium
+}
 
-if (!build_with_chromium) {
+perfetto_build_standalone =
+    !perfetto_build_with_android && !build_with_chromium &&
+    !perfetto_build_with_embedder
+
+if (perfetto_build_standalone || perfetto_build_with_android) {
   perfetto_root_path = "//"
-} else {
+} else if (!defined(perfetto_root_path)) {
   perfetto_root_path = "//third_party/perfetto/"
 }
 
 # If we're building in the Android tree, we expect that the testing infra
 # will start the binaries in the system image before the tests are run.
-if (build_with_android) {
+if (perfetto_build_with_android) {
   start_daemons_for_testing = false
 }
+
+# Cross-checks.
+
+# If |build_with_chromium| is true then also |perfetto_build_with_embedder|
+# must be true
+assert(!build_with_chromium || perfetto_build_with_embedder)
diff --git a/gn/proto_library.gni b/gn/proto_library.gni
index 3ccdeab..a34419d 100644
--- a/gn/proto_library.gni
+++ b/gn/proto_library.gni
@@ -12,10 +12,22 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build_overrides/build.gni")
+import("perfetto.gni")
 
-if (!build_with_chromium) {
-  import("//gn/standalone/proto_library.gni")
-} else {
-  import("//third_party/protobuf/proto_library.gni")
+if (!defined(perfetto_protobuf_target_prefix)) {
+  if (perfetto_build_standalone || perfetto_build_with_android) {
+    perfetto_protobuf_target_prefix = "//buildtools"
+  } else {
+    perfetto_protobuf_target_prefix = "//third_party/protobuf"
+  }
 }
+
+if (!defined(perfetto_protobuf_gni)) {
+  if (perfetto_build_standalone || perfetto_build_with_android) {
+    perfetto_protobuf_gni = "//gn/standalone/proto_library.gni"
+  } else {
+    perfetto_protobuf_gni = "//third_party/protobuf/proto_library.gni"
+  }
+}
+
+import(perfetto_protobuf_gni)
diff --git a/src/protozero/protozero_library.gni b/gn/protozero_library.gni
similarity index 90%
rename from src/protozero/protozero_library.gni
rename to gn/protozero_library.gni
index 4965016..89e7969 100644
--- a/src/protozero/protozero_library.gni
+++ b/gn/protozero_library.gni
@@ -12,13 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build_overrides/build.gni")
-
-if (!build_with_chromium) {
-  import("//gn/standalone/proto_library.gni")
-} else {
-  import("//third_party/protobuf/proto_library.gni")
-}
+import("perfetto.gni")
+import("proto_library.gni")
 
 # Equivalent to proto_library (generation of .h/.cc from .proto files) but
 # enables also generation using the protozero plugin.
diff --git a/gn/wasm.gni b/gn/wasm.gni
index 3a0733c..87326c9 100644
--- a/gn/wasm.gni
+++ b/gn/wasm.gni
@@ -15,7 +15,7 @@
 import("//build_overrides/build.gni")
 import("perfetto.gni")
 
-if (build_standalone) {
+if (perfetto_build_standalone) {
   import("//gn/standalone/wasm.gni")
 } else {
   is_wasm = false  # The WASM toolchain is supported only in standalone builds.
diff --git a/include/perfetto/base/BUILD.gn b/include/perfetto/base/BUILD.gn
index 5ee76ba..18fce4a 100644
--- a/include/perfetto/base/BUILD.gn
+++ b/include/perfetto/base/BUILD.gn
@@ -42,7 +42,7 @@
   if (is_android) {
     sources += [ "android_task_runner.h" ]
   }
-  if (!build_with_chromium) {
+  if (perfetto_build_standalone || perfetto_build_with_android) {
     sources += [ "unix_socket.h" ]
   }
 }
diff --git a/protos/perfetto/common/BUILD.gn b/protos/perfetto/common/BUILD.gn
index 38603fd..93818fe 100644
--- a/protos/perfetto/common/BUILD.gn
+++ b/protos/perfetto/common/BUILD.gn
@@ -14,7 +14,7 @@
 
 import("../../../gn/perfetto.gni")
 import("../../../gn/proto_library.gni")
-import("../../../src/protozero/protozero_library.gni")
+import("../../../gn/protozero_library.gni")
 
 common_sources = [
   "commit_data_request.proto",
diff --git a/protos/perfetto/config/BUILD.gn b/protos/perfetto/config/BUILD.gn
index db89822..fb76c8f 100644
--- a/protos/perfetto/config/BUILD.gn
+++ b/protos/perfetto/config/BUILD.gn
@@ -14,7 +14,7 @@
 
 import("../../../gn/perfetto.gni")
 import("../../../gn/proto_library.gni")
-import("../../../src/protozero/protozero_library.gni")
+import("../../../gn/protozero_library.gni")
 
 proto_library("lite") {
   generate_python = false
diff --git a/protos/perfetto/trace/BUILD.gn b/protos/perfetto/trace/BUILD.gn
index aa1fe9a..7cef317 100644
--- a/protos/perfetto/trace/BUILD.gn
+++ b/protos/perfetto/trace/BUILD.gn
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("../../../src/protozero/protozero_library.gni")
+import("../../../gn/protozero_library.gni")
 import("../../../gn/perfetto.gni")
 import("../../../gn/proto_library.gni")
 
@@ -59,7 +59,7 @@
     "ps:lite",
     "sys_stats:lite",
   ]
-  if (!build_with_chromium) {
+  if (perfetto_build_standalone) {
     generate_descriptor = "$perfetto_root_path/protos/trace/trace.descriptor"
   }
   sources = proto_sources
diff --git a/protos/perfetto/trace/chrome/BUILD.gn b/protos/perfetto/trace/chrome/BUILD.gn
index b5191a6..967a08c 100644
--- a/protos/perfetto/trace/chrome/BUILD.gn
+++ b/protos/perfetto/trace/chrome/BUILD.gn
@@ -13,7 +13,7 @@
 # limitations under the License.
 
 import("../../../../gn/perfetto.gni")
-import("../../../../src/protozero/protozero_library.gni")
+import("../../../../gn/protozero_library.gni")
 
 chrome_proto_names = [ "chrome_trace_event.proto" ]
 minimal_chrome_proto_names = [ "chrome_trace_packet.proto" ]
diff --git a/protos/perfetto/trace/filesystem/BUILD.gn b/protos/perfetto/trace/filesystem/BUILD.gn
index 34e90c9..0937581 100644
--- a/protos/perfetto/trace/filesystem/BUILD.gn
+++ b/protos/perfetto/trace/filesystem/BUILD.gn
@@ -13,7 +13,7 @@
 # limitations under the License.
 
 import("../../../../gn/perfetto.gni")
-import("../../../../src/protozero/protozero_library.gni")
+import("../../../../gn/protozero_library.gni")
 
 inode_proto_names = [ "inode_file_map.proto" ]
 
diff --git a/protos/perfetto/trace/ftrace/BUILD.gn b/protos/perfetto/trace/ftrace/BUILD.gn
index 7cf04cb..8e24e04 100644
--- a/protos/perfetto/trace/ftrace/BUILD.gn
+++ b/protos/perfetto/trace/ftrace/BUILD.gn
@@ -13,12 +13,12 @@
 # limitations under the License.
 
 import("../../../../gn/perfetto.gni")
-import("../../../../src/protozero/protozero_library.gni")
+import("../../../../gn/protozero_library.gni")
 import("all_protos.gni")
 
 proto_library("lite") {
   generate_python = false
-  if (!build_with_chromium) {
+  if (perfetto_build_standalone) {
     generate_descriptor =
         "$perfetto_root_path/protos/perfetto/trace/ftrace.descriptor"
   }
diff --git a/protos/perfetto/trace/ps/BUILD.gn b/protos/perfetto/trace/ps/BUILD.gn
index 90b86b8..11236a6 100644
--- a/protos/perfetto/trace/ps/BUILD.gn
+++ b/protos/perfetto/trace/ps/BUILD.gn
@@ -13,7 +13,7 @@
 # limitations under the License.
 
 import("../../../../gn/perfetto.gni")
-import("../../../../src/protozero/protozero_library.gni")
+import("../../../../gn/protozero_library.gni")
 
 ps_proto_names = [ "process_tree.proto" ]
 
diff --git a/protos/perfetto/trace/sys_stats/BUILD.gn b/protos/perfetto/trace/sys_stats/BUILD.gn
index bb7f93b..27461fb 100644
--- a/protos/perfetto/trace/sys_stats/BUILD.gn
+++ b/protos/perfetto/trace/sys_stats/BUILD.gn
@@ -13,7 +13,7 @@
 # limitations under the License.
 
 import("../../../../gn/perfetto.gni")
-import("../../../../src/protozero/protozero_library.gni")
+import("../../../../gn/protozero_library.gni")
 
 sys_stats_proto_names = [ "sys_stats.proto" ]
 
diff --git a/src/base/BUILD.gn b/src/base/BUILD.gn
index ad3f170..76c3dc8 100644
--- a/src/base/BUILD.gn
+++ b/src/base/BUILD.gn
@@ -43,10 +43,11 @@
     ]
   }
 
-  if (!build_with_chromium && (is_linux || is_android)) {
+  if ((perfetto_build_standalone || perfetto_build_with_android) &&
+      (is_linux || is_android)) {
     sources += [ "watchdog_posix.cc" ]
   }
-  if (is_debug && build_standalone && !is_wasm) {
+  if (is_debug && perfetto_build_standalone && !is_wasm) {
     deps += [ ":debug_crash_stack_trace" ]
   }
 }
@@ -54,7 +55,7 @@
 # The "android_task_runner" should be depended on only by targets that
 # explicitly need it, as it pulls in a dependency on libandroid.so that in turn
 # pulls dozen of other .so(s).
-if (is_android && !build_with_chromium) {
+if (is_android && (perfetto_build_standalone || perfetto_build_with_android)) {
   source_set("android_task_runner") {
     deps = [
       ":base",
@@ -71,7 +72,7 @@
   }
 }
 
-if (is_debug && build_standalone && !is_wasm) {
+if (is_debug && perfetto_build_standalone && !is_wasm) {
   source_set("debug_crash_stack_trace") {
     sources = [
       "debug_crash_stack_trace.cc",
@@ -87,7 +88,7 @@
   }
 }
 
-if (!build_with_chromium) {
+if (perfetto_build_standalone || perfetto_build_with_android) {
   # This cannot be in :base as it does not build on WASM.
   source_set("unix_socket") {
     deps = [
@@ -132,7 +133,7 @@
     "../../gn:gtest_deps",
   ]
 
-  if (is_android && !build_with_chromium) {
+  if (is_android && (perfetto_build_standalone || perfetto_build_with_android)) {
     deps += [ ":android_task_runner" ]
   }
   sources = [
@@ -154,7 +155,7 @@
       "utils_unittest.cc",
     ]
   }
-  if (!build_with_chromium) {
+  if (perfetto_build_standalone || perfetto_build_with_android) {
     sources += [ "unix_socket_unittest.cc" ]
     if (is_linux || is_android) {
       sources += [ "watchdog_unittest.cc" ]
diff --git a/src/ipc/BUILD.gn b/src/ipc/BUILD.gn
index 8a7e4e1..670554f 100644
--- a/src/ipc/BUILD.gn
+++ b/src/ipc/BUILD.gn
@@ -18,13 +18,16 @@
 import("../../gn/proto_library.gni")
 
 # For use_libfuzzer.
-if (!build_with_chromium) {
+if (perfetto_build_standalone || perfetto_build_with_android) {
   import("//gn/standalone/sanitizers/vars.gni")
 } else {
   import("//build/config/sanitizers/sanitizers.gni")
 }
 
+# This build file should not be leaked into the embedder. For now they shouldn't
+# be depending on our IPC layer.
 assert(!build_with_chromium)
+assert(!perfetto_build_with_embedder)
 
 source_set("ipc") {
   public_configs = [ "../../gn:default_config" ]
diff --git a/src/protozero/BUILD.gn b/src/protozero/BUILD.gn
index d2d27aa..9b97c73 100644
--- a/src/protozero/BUILD.gn
+++ b/src/protozero/BUILD.gn
@@ -14,7 +14,7 @@
 
 import("../../gn/perfetto.gni")
 import("../../gn/proto_library.gni")
-import("protozero_library.gni")
+import("../../gn/protozero_library.gni")
 
 source_set("protozero") {
   public_configs = [ "../../gn:default_config" ]
diff --git a/src/trace_processor/BUILD.gn b/src/trace_processor/BUILD.gn
index a3da82c..2b468af 100644
--- a/src/trace_processor/BUILD.gn
+++ b/src/trace_processor/BUILD.gn
@@ -96,7 +96,7 @@
     "../base",
     "../protozero",
   ]
-  if (build_standalone) {
+  if (perfetto_build_standalone) {
     sources += [
       "json_trace_parser.cc",
       "json_trace_parser.h",
@@ -113,7 +113,7 @@
       "../../protos/perfetto/trace_processor:lite",
       "../base",
     ]
-    if (build_standalone) {
+    if (perfetto_build_standalone) {
       deps += [ "../../buildtools:linenoise" ]
     }
     sources = [
diff --git a/src/traced/probes/ftrace/BUILD.gn b/src/traced/probes/ftrace/BUILD.gn
index e65d709..e4f42b1 100644
--- a/src/traced/probes/ftrace/BUILD.gn
+++ b/src/traced/probes/ftrace/BUILD.gn
@@ -15,10 +15,10 @@
 import("../../../../gn/perfetto.gni")
 import("../../../../gn/proto_library.gni")
 import("../../../../gn/fuzzer.gni")
-import("../../../protozero/protozero_library.gni")
+import("../../../../gn/protozero_library.gni")
 
 # For use_libfuzzer.
-if (!build_with_chromium) {
+if (perfetto_build_standalone || perfetto_build_with_android) {
   import("//gn/standalone/sanitizers/vars.gni")
 } else {
   import("//build/config/sanitizers/sanitizers.gni")
@@ -157,7 +157,7 @@
   ]
 }
 
-if (!build_with_chromium) {
+if (perfetto_build_standalone) {
   source_set("benchmarks") {
     testonly = true
     deps = [
diff --git a/src/tracing/BUILD.gn b/src/tracing/BUILD.gn
index b90ce18..2992085 100644
--- a/src/tracing/BUILD.gn
+++ b/src/tracing/BUILD.gn
@@ -95,7 +95,7 @@
     "test/test_shared_memory.h",
   ]
 
-  if (!build_with_chromium) {
+  if (perfetto_build_standalone || perfetto_build_with_android) {
     deps += [ ":ipc" ]
     sources += [
       "ipc/posix_shared_memory_unittest.cc",
@@ -132,7 +132,7 @@
   ]
 }
 
-if (!build_with_chromium) {
+if (perfetto_build_standalone || perfetto_build_with_android) {
   executable("consumer_api_test") {
     deps = [
       ":api",
diff --git a/test/BUILD.gn b/test/BUILD.gn
index 6dd7835..226ff37 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -33,7 +33,7 @@
   sources = [
     "end_to_end_integrationtest.cc",
   ]
-  if (is_android && !build_with_chromium) {
+  if (is_android && (perfetto_build_standalone || perfetto_build_with_android)) {
     deps += [ "../src/base:android_task_runner" ]
   }
   if (start_daemons_for_testing) {
@@ -112,7 +112,7 @@
   }
 }
 
-if (!build_with_chromium) {
+if (perfetto_build_standalone) {
   source_set("end_to_end_benchmarks") {
     testonly = true
     deps = [
@@ -130,7 +130,7 @@
     sources = [
       "end_to_end_benchmark.cc",
     ]
-    if (is_android && !build_with_chromium) {
+    if (is_android) {
       deps += [ "../src/base:android_task_runner" ]
     }
     if (start_daemons_for_testing) {
diff --git a/test/configs/BUILD.gn b/test/configs/BUILD.gn
index cbc0970..e0c860e 100644
--- a/test/configs/BUILD.gn
+++ b/test/configs/BUILD.gn
@@ -14,7 +14,7 @@
 
 import("../../gn/perfetto.gni")
 
-if (!build_with_chromium) {
+if (perfetto_build_standalone) {
   action_foreach("configs") {
     testonly = true
     script = "$root_out_dir/protoc_helper"
diff --git a/tools/gen_android_bp b/tools/gen_android_bp
index f30bdb3..09b133e 100755
--- a/tools/gen_android_bp
+++ b/tools/gen_android_bp
@@ -64,7 +64,7 @@
 ]
 
 # Arguments for the GN output directory.
-gn_args = 'target_os="android" target_cpu="arm" is_debug=false build_with_android=true'
+gn_args = 'target_os="android" target_cpu="arm" is_debug=false perfetto_build_with_android=true'
 
 # All module names are prefixed with this string to avoid collisions.
 module_prefix = 'perfetto_'
diff --git a/tools/trace_to_text/BUILD.gn b/tools/trace_to_text/BUILD.gn
index 9bbc2d0..08b095c 100644
--- a/tools/trace_to_text/BUILD.gn
+++ b/tools/trace_to_text/BUILD.gn
@@ -87,7 +87,7 @@
 }
 
 # The one for the android tree is defined in the top-level BUILD.gn.
-if (!build_with_android) {
+if (!perfetto_build_with_android) {
   copy("trace_to_text") {
     testonly = true
     host_out_dir_ =