Moved /features to /tools/package/features.

Change-Id: I6b52c92b688a833b9e3813416b785533cb4dd829
diff --git a/modules.defs b/modules.defs
index dabd5f9..c43a273 100644
--- a/modules.defs
+++ b/modules.defs
@@ -304,5 +304,18 @@
     '//apps/kafka-integration/app:onos-apps-kafka-integration-app',
 ]
 
+FEATURES = [
+  '//tools/package/features:onos-thirdparty-base',
+  '//tools/package/features:onos-thirdparty-web',
+  '//tools/package/features:onos-api',
+  '//tools/package/features:onos-core',
+  '//tools/package/features:onos-incubator',
+  '//tools/package/features:onos-rest',
+  '//tools/package/features:onos-gui',
+  '//tools/package/features:onos-gui2',
+  '//tools/package/features:onos-cli',
+  '//tools/package/features:onos-security',
+]
+
 APPS = ONOS_DRIVERS + ONOS_PROVIDERS + ONOS_APPS + MODELS + PIPELINES \
         + PROTOCOL_APPS
diff --git a/pom.xml b/pom.xml
index b32e8a9..862234f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -64,10 +64,10 @@
 
         <module>apps</module>
         <module>incubator</module>
-        <module>features</module>
 
         <module>models</module>
 
+        <module>tools/package/features</module>
         <module>tools/package/archetypes</module>
         <module>tools/package/branding</module>
         <module>tools/package/maven-plugin</module>
diff --git a/tools/package/BUCK b/tools/package/BUCK
index 9324c2c..b7adf19 100644
--- a/tools/package/BUCK
+++ b/tools/package/BUCK
@@ -2,19 +2,6 @@
 BRANDING = '//tools/package/branding:onos-tools-package-branding'
 PATCHES = '//lib:apache-karaf-patches'
 
-FEATURES = [
-  '//features:onos-thirdparty-base',
-  '//features:onos-thirdparty-web',
-  '//features:onos-api',
-  '//features:onos-core',
-  '//features:onos-incubator',
-  '//features:onos-rest',
-  '//features:onos-gui',
-  '//features:onos-gui2',
-  '//features:onos-cli',
-  '//features:onos-security',
-]
-
 #TODO move to buck-tools
 export_file (
   name = 'onos-prep-karaf',
@@ -28,17 +15,11 @@
   out = 'karaf.zip',
 )
 
-compile_features(
-  name = 'onos-features',
-  features = FEATURES,
-  maven_coords = 'org.onosproject:onos-features:xml:features:' + ONOS_VERSION,
-)
-
 staged_repos = ['$(location %s-repo)' % f for f in FEATURES]
 staged_apps = ['$(location %s)' % a for a in APPS]
 
 # feature_coords = 'foo:bar:1.3'
-sources = [ '$(location :onos-features)', ]
+sources = [ '$(location //tools/package/features:onos-features)', ]
 sources += staged_repos + staged_apps
 
 tar_file(
diff --git a/tools/package/BUILD b/tools/package/BUILD
index 93a0e1c..2067140 100644
--- a/tools/package/BUILD
+++ b/tools/package/BUILD
@@ -22,7 +22,7 @@
 
 # FIXME: Move /features to under tools/package/features
 PACKAGING_REQUIREMENTS = [
-    "//features:onos-features",
+    "//tools/package/features:onos-features",
     ":onos-karaf",
 ]
 
@@ -35,6 +35,7 @@
     cmd = "$(location onos_stage.py) $(location onos.tar.gz) %s $(location :onos-karaf) $(SRCS)" % ONOS_VERSION,
     visibility = ["//visibility:public"],
     tools = ["onos_stage.py"],
+    output_to_bindir = True,
 )
 
 filegroup(
@@ -50,6 +51,7 @@
     cmd = "mkdir onos-admin-%s; cp $(SRCS) onos-admin-%s; tar zcf $(location onos-admin.tar.gz) onos-admin-%s"\
           % (ONOS_VERSION, ONOS_VERSION, ONOS_VERSION),
     visibility = ["//visibility:public"],
+    output_to_bindir = True,
 )
 
 # Generates the onos-test.tar.gz file with test tools
@@ -60,6 +62,7 @@
     cmd = "mkdir onos-test-%s; cp -r tools onos-test-%s; tar zcf $(location onos-test.tar.gz) onos-test-%s"\
           % (ONOS_VERSION, ONOS_VERSION, ONOS_VERSION),
     visibility = ["//visibility:public"],
+    output_to_bindir = True,
 )
 
 # Runs ONOS as a single instance from the /tmp directory
@@ -70,7 +73,7 @@
     srcs = ["onos-run-karaf", "onos-package"],
     cmd = "sed \"s#ONOS_TAR=#ONOS_TAR=$(location :onos-package)#\" $(location onos-run-karaf) > $(location onos-runner); chmod +x $(location onos-runner)",
     executable = True,
-    local = True,
+    output_to_bindir = True,
     visibility = ["//visibility:public"],
 )
 
diff --git a/features/BUCK b/tools/package/features/BUCK
similarity index 96%
rename from features/BUCK
rename to tools/package/features/BUCK
index 03ee6cf..479d488 100644
--- a/features/BUCK
+++ b/tools/package/features/BUCK
@@ -158,3 +158,9 @@
     '//core/security:onos-security',
   ]
 )
+
+compile_features(
+  name = 'onos-features',
+  features = FEATURES,
+  maven_coords = 'org.onosproject:onos-features:xml:features:' + ONOS_VERSION,
+)
diff --git a/features/BUILD b/tools/package/features/BUILD
similarity index 90%
rename from features/BUILD
rename to tools/package/features/BUILD
index 1957787..5443842 100644
--- a/features/BUILD
+++ b/tools/package/features/BUILD
@@ -107,16 +107,16 @@
 
 
 FEATURES = [
-    "//features:onos-thirdparty-base",
-    "//features:onos-thirdparty-web",
-    "//features:onos-api",
-    "//features:onos-core",
-#    "//features:onos-incubator",
-#    "//features:onos-rest",
-#    "//features:onos-gui",
-#    "//features:onos-gui2",
-#    "//features:onos-cli",
-#    "//features:onos-security",
+    "//tools/package/features:onos-thirdparty-base",
+    "//tools/package/features:onos-thirdparty-web",
+    "//tools/package/features:onos-api",
+    "//tools/package/features:onos-core",
+#    "//tools/package/features:onos-incubator",
+#    "//tools/package/features:onos-rest",
+#    "//tools/package/features:onos-gui",
+#    "//tools/package/features:onos-gui2",
+#    "//tools/package/features:onos-cli",
+#    "//tools/package/features:onos-security",
 ]
 
 osgi_feature_repo(
diff --git a/features/features.xml b/tools/package/features/features.xml
similarity index 100%
rename from features/features.xml
rename to tools/package/features/features.xml
diff --git a/features/pom.xml b/tools/package/features/pom.xml
similarity index 98%
rename from features/pom.xml
rename to tools/package/features/pom.xml
index 7fe9034..18dd3c4 100644
--- a/features/pom.xml
+++ b/tools/package/features/pom.xml
@@ -23,6 +23,7 @@
         <groupId>org.onosproject</groupId>
         <artifactId>onos</artifactId>
         <version>1.14.0-SNAPSHOT</version>
+        <relativePath>../../../pom.xml</relativePath>
     </parent>
 
     <artifactId>onos-features</artifactId>
diff --git a/tools/test/bin/onos-check-bits b/tools/test/bin/onos-check-bits
index cc08746..2b0acd3 100755
--- a/tools/test/bin/onos-check-bits
+++ b/tools/test/bin/onos-check-bits
@@ -12,6 +12,12 @@
   rm -f $ONOS_TAR >/dev/null; ln -s $BUCK_TAR $ONOS_TAR
 fi
 
+# If the Bazel-built bits are newer than the BUCK-built bits, use the former.
+# BAZEL_TAR=$ONOS_ROOT/bazel-bin/tools/package/onos.tar.gz
+# if [ -f $BAZEL_TAR ] && [ $BAZEL_TAR -nt $BUCK_TAR ]; then
+#   rm -f $ONOS_TAR >/dev/null; ln -s $BAZEL_TAR $ONOS_TAR
+# fi
+
 ls -lL $ONOS_TAR  && cksum $ONOS_TAR
 if [ $? -ne 0 ]; then
   echo "ONOS archive is unreadable" && exit 1