RESTRICT AUTOMERGE: Only applicable to mainline-prod

Asuite: atest_module_info migration.

This CL moved atest_module_info from atest-py2/Android.bp to
atest/Android.bp, however, it required pb2 files.

Bug: 176783136

Test: atest -v --host aidegen_unittests # must pass
atest -v --host acloud_test # must pass
atest -v --host atest_unittests # must pass
atest -v --host plugin_lib_unittests # must pass

Change-Id: I77bd449d604149af2620444bbd9e534010756262
Merged-In: I77bd449d604149af2620444bbd9e534010756262
Merged-In: I46bfec56872bf34393f250d9af35acaa294c2590
diff --git a/atest-py2/Android.bp b/atest-py2/Android.bp
index 0077652..5136051 100644
--- a/atest-py2/Android.bp
+++ b/atest-py2/Android.bp
@@ -40,44 +40,6 @@
     },
 }
 
-python_library_host {
-    name: "atest_module_info",
-    defaults: ["atest_lib_default"],
-    srcs: [
-        "atest_error.py",
-        "atest_decorator.py",
-        "atest_utils.py",
-        "constants.py",
-        "constants_default.py",
-        "module_info.py",
-    ],
-}
-
-// Move asuite_default and asuite_metrics to //tools/asuite when atest is
-// running as a prebuilt.
-python_defaults {
-    name: "asuite_default",
-    pkg_path: "asuite",
-    version: {
-        py2: {
-            enabled: true,
-            embedded_launcher: false,
-        },
-        py3: {
-            enabled: true,
-            embedded_launcher: false,
-        },
-    },
-}
-
-python_library_host {
-    name: "asuite_metrics",
-    defaults: ["asuite_default"],
-    srcs: [
-        "asuite_metrics.py",
-    ],
-}
-
 // Exclude atest_updatedb_unittest due to it's a test for ATest's wrapper of updatedb, but there's
 // no updatedb binary on test server.
 python_test_host {
@@ -129,33 +91,3 @@
         },
     },
 }
-
-python_library_host {
-    name: "asuite_cc_client",
-    defaults: ["asuite_default"],
-    srcs: [
-        "atest_error.py",
-        "atest_decorator.py",
-        "atest_utils.py",
-        "constants.py",
-        "constants_default.py",
-        "metrics/*.py",
-    ],
-    libs: [
-        "asuite_proto",
-        "asuite_metrics",
-    ],
-}
-
-genrule {
-    name: "asuite_version",
-    cmd: "DATETIME=$$(TZ='America/Log_Angelos' date +'%F');" +
-         "if [[ -n $$BUILD_NUMBER ]]; then" +
-         "  echo $${DATETIME}_$${BUILD_NUMBER} > $(out);" +
-         "else" +
-         "  echo $$(date +'%F_%R') > $(out);" +
-         "fi",
-    out: [
-        "VERSION",
-    ],
-}
diff --git a/atest/Android.bp b/atest/Android.bp
index e0f1e97..348bcad 100644
--- a/atest/Android.bp
+++ b/atest/Android.bp
@@ -113,6 +113,22 @@
 }
 
 python_library_host {
+    name: "atest_module_info",
+    defaults: ["atest_lib_default"],
+    srcs: [
+        "atest_error.py",
+        "atest_decorator.py",
+        "atest_utils.py",
+        "constants.py",
+        "constants_default.py",
+        "module_info.py",
+    ],
+    libs: [
+        "metrics-protos",
+    ]
+}
+
+python_library_host {
     name: "atest_py3_proto",
     defaults: ["atest_py3_default"],
     srcs: [
@@ -201,7 +217,6 @@
     test_suites: ["general-tests"],
     defaults: ["atest_py3_default"],
 }
-
 genrule {
     name: "asuite_version",
     cmd: "DATETIME=$$(TZ='America/Log_Angelos' date +'%F');" +
@@ -214,3 +229,4 @@
         "VERSION",
     ],
 }
+
diff --git a/atest/asuite_metrics.py b/atest/asuite_metrics.py
index 34ef39f..69dae5f 100644
--- a/atest/asuite_metrics.py
+++ b/atest/asuite_metrics.py
@@ -19,9 +19,13 @@
 import os
 import uuid
 
-from urllib.request import Request
-from urllib.request import urlopen
-
+try:
+    from urllib.request import Request
+    from urllib.request import urlopen
+except ImportError:
+    # for compatibility of asuite_metrics_lib_tests and asuite_cc_lib_tests.
+    from urllib2 import Request
+    from urllib2 import urlopen
 
 _JSON_HEADERS = {'Content-Type': 'application/json'}
 _METRICS_RESPONSE = 'done'
diff --git a/atest/metrics/clearcut_client.py b/atest/metrics/clearcut_client.py
index f8b2414..4987c17 100644
--- a/atest/metrics/clearcut_client.py
+++ b/atest/metrics/clearcut_client.py
@@ -27,10 +27,17 @@
 import threading
 import time
 
-from urllib.request import urlopen
-from urllib.request import Request
-from urllib.request import HTTPError
-from urllib.request import URLError
+try:
+    from urllib.request import urlopen
+    from urllib.request import Request
+    from urllib.request import HTTPError
+    from urllib.request import URLError
+except ImportError:
+    # for compatibility of asuite_metrics_lib_tests and asuite_cc_lib_tests.
+    from urllib2 import Request
+    from urllib2 import urlopen
+    from urllib2 import HTTPError
+    from urllib2 import URLError
 
 from proto import clientanalytics_pb2
 
diff --git a/atest/tools/Android.bp b/atest/tools/Android.bp
new file mode 100644
index 0000000..b1f383b
--- /dev/null
+++ b/atest/tools/Android.bp
@@ -0,0 +1,31 @@
+// Copyright 2021 The Android Open Source Project
+//
+// 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.
+
+// This is a copy of the proto from Tradefed at tools/tradefederation/core/proto
+python_library_host {
+    name: "metrics-protos",
+    pkg_path: "tools",
+    srcs: ["asuite/atest/tf_proto/*_pb2.py"],
+    proto: {
+        include_dirs: ["external/protobuf/src"],
+    },
+    version: {
+        py2: {
+            enabled: true,
+        },
+        py3: {
+            enabled: true,
+        },
+    },
+}