Enable ONOS to be packaged into different profiles

Currently supported profiles:
- (default): builds everything
- minimal: builds ONOS and general device provider
- seba: builds ONOS with OpenFlow and SEBA-related apps
- stratum: builds ONOS with NG-SDN APIs and Stratum drivers
           (P4Runtime, gNMI, gNOI)

Change-Id: I6cdd01cba54e45fc23d60f345b23dd86318cdef9
diff --git a/BUILD b/BUILD
index 881deaf..a4f5688 100644
--- a/BUILD
+++ b/BUILD
@@ -1,14 +1,40 @@
 load("//tools/build/bazel:variables.bzl", "ONOS_VERSION")
-load("//tools/build/bazel:modules.bzl", "APPS", "CORE", "FEATURES")
+load(
+    "//tools/build/bazel:modules.bzl",
+    "CORE",
+    "FEATURES",
+    "apps",
+    "extensions",
+    "profiles",
+)
+
+#
+# ONOS Package Profiles
+# Usage: bazel build onos-package --define profile=<profile name>
+# Example: bazel build onos-package --define profile=minimal
+#
+# To view or update which apps and features are included in each
+# profile, open: tools/build/bazel/modules.bzl
+#
+profiles([
+    "minimal",
+    "seba",
+    "stratum",
+])
 
 filegroup(
     name = "onos",
-    srcs = CORE + APPS + [
+    srcs = CORE + [
         "//tools/build/conf:onos-build-conf",
         ":onos-package-admin",
         ":onos-package-test",
         ":onos-package",
-    ],
+    ] + select({
+        ":minimal_profile": extensions("minimal") + apps("minimal"),
+        ":seba_profile": extensions("seba") + apps("seba"),
+        ":stratum_profile": extensions("stratum") + apps("stratum"),
+        "//conditions:default": extensions() + apps(),
+    }),
     visibility = ["//visibility:public"],
 )
 
@@ -40,7 +66,12 @@
     srcs = [
         "//tools/package/features:onos-features",
         ":onos-karaf",
-    ] + APPS + FEATURES,
+    ] + FEATURES + select({
+        ":minimal_profile": apps("minimal"),
+        ":seba_profile": apps("seba"),
+        ":stratum_profile": apps("stratum"),
+        "//conditions:default": apps(),
+    }),
     outs = ["onos.tar.gz"],
     cmd = "$(location tools/package/onos_stage.py) $(location onos.tar.gz) %s $(location :onos-karaf) $(SRCS)" % ONOS_VERSION,
     output_to_bindir = True,
@@ -48,45 +79,6 @@
     tools = ["tools/package/onos_stage.py"],
 )
 
-# Generates the minimal onos-minimal.tar.gz bundle
-genrule(
-    name = "onos-package-minimal",
-    srcs = [
-        "//tools/package/features:onos-features",
-        ":onos-karaf",
-        "//drivers/default:onos-drivers-default-oar",
-    ] + FEATURES,
-    outs = ["onos-minimal.tar.gz"],
-    cmd = "$(location tools/package/onos_stage.py) $(location onos-minimal.tar.gz) %s $(location :onos-karaf) $(SRCS)" % ONOS_VERSION,
-    output_to_bindir = True,
-    tags = ["local"],
-    tools = ["tools/package/onos_stage.py"],
-)
-
-# Generates SEBA-specific onos-seba.tar.gz bundle
-genrule(
-    name = "onos-package-seba",
-    srcs = [
-        "//tools/package/features:onos-features",
-        ":onos-karaf",
-        "//drivers/default:onos-drivers-default-oar",
-        "//apps/optical-model:onos-apps-optical-model-oar",
-        "//providers/openflow/app:onos-providers-openflow-app-oar",
-        "//providers/openflow/base:onos-providers-openflow-base-oar",
-        "//providers/host:onos-providers-host-oar",
-        "//providers/lldp:onos-providers-lldp-oar",
-        "//apps/mcast:onos-apps-mcast-oar",
-        "//providers/netcfghost:onos-providers-netcfghost-oar",
-        "//apps/segmentrouting:onos-apps-segmentrouting-oar",
-        "//apps/route-service:onos-apps-route-service-oar",
-    ] + FEATURES,
-    outs = ["onos-seba.tar.gz"],
-    cmd = "$(location tools/package/onos_stage.py) $(location onos-seba.tar.gz) %s $(location :onos-karaf) $(SRCS)" % ONOS_VERSION,
-    output_to_bindir = True,
-    tags = ["local"],
-    tools = ["tools/package/onos_stage.py"],
-)
-
 # Generates the onos-admin.tar.gz file with remote admin tools
 genrule(
     name = "onos-package-admin",