Merge v0.6.0 into master.

Adjust Android build system rules for recent changes in upstream
cpu_features.

Test: lunch aosp_arm-eng \
        && mmma external/cpu_features \
        && atest --test-mapping external/cpu_features:all
Test: lunch aosp_arm64-eng \
        && mmma external/cpu_features \
        && atest --test-mapping external/cpu_features:all
Test: lunch aosp_x86-eng \
        && mmma external/cpu_features \
        && atest --test-mapping external/cpu_features:all
Test: lunch aosp_x86_64-eng \
        && mmma external/cpu_features
Bug: 169921883
Bug: 128901000
Change-Id: I5fa712b4ea6e52f60128fb0c907a52cd894f34f1
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..a6d18b2
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,338 @@
+// This Blueprint file loosely follows the logic of cpu_features'
+// CMakeLists.txt and test/CMakeLists.txt files.
+
+cc_defaults {
+    name: "cpu_features-defaults",
+    host_supported: true,
+    local_include_dirs: [
+        "include",
+    ],
+    cflags: [
+        // Reserve 1024 bytes on the stack when reading from `/proc/cpuinfo`.
+        "-DSTACK_LINE_READER_BUFFER_SIZE=1024",
+        "-Wno-gnu-designator",
+    ],
+}
+
+cc_library {
+    name: "libcpu_features-utils",
+    defaults: ["cpu_features-defaults"],
+    srcs: [
+        "src/filesystem.c",
+        "src/stack_line_reader.c",
+        "src/string_view.c",
+    ],
+    target: {
+        windows: {
+            enabled: true,
+        },
+    },
+    apex_available: [
+        "com.android.art.release",
+        "com.android.art.debug",
+    ],
+}
+
+cc_library {
+    name: "libcpu_features-hwcaps",
+    defaults: ["cpu_features-defaults"],
+    srcs: [
+        "src/hwcaps.c",
+    ],
+    cflags: [
+        "-DHAVE_DLFCN_H",
+    ],
+    target: {
+        bionic: {
+            cflags: [
+                "-DHAVE_STRONG_GETAUXVAL",
+            ],
+        },
+    },
+    static_libs: [
+        "libcpu_features-utils",
+    ],
+    apex_available: [
+        "com.android.art.release",
+        "com.android.art.debug",
+    ],
+}
+
+cc_library {
+    name: "libcpu_features",
+    defaults: [
+        "cpu_features-defaults",
+    ],
+    export_include_dirs: ["include"],
+    whole_static_libs: [
+        "libcpu_features-utils",
+    ],
+    arch: {
+        arm: {
+            srcs: [
+                "src/cpuinfo_arm.c",
+            ],
+            whole_static_libs: [
+                "libcpu_features-hwcaps",
+            ],
+        },
+        arm64: {
+            srcs: [
+                "src/cpuinfo_aarch64.c",
+            ],
+            whole_static_libs: [
+                "libcpu_features-hwcaps",
+            ],
+            cflags: [
+                "-Wno-gnu-designator",
+            ],
+        },
+        x86: {
+            srcs: [
+                "src/cpuinfo_x86.c",
+            ],
+            cflags: [
+                "-Wno-unused-variable",
+            ],
+        },
+        x86_64: {
+            srcs: [
+                "src/cpuinfo_x86.c",
+            ],
+            cflags: [
+                "-Wno-unused-variable",
+            ],
+        },
+    },
+    target: {
+        windows: {
+            enabled: true,
+        },
+    },
+    apex_available: [
+        "com.android.art.release",
+        "com.android.art.debug",
+    ],
+}
+
+cc_binary {
+    name: "list_cpu_features",
+    defaults: [
+        "cpu_features-defaults",
+    ],
+    srcs: [
+        "src/utils/list_cpu_features.c",
+    ],
+    static_libs: [
+        "libcpu_features",
+    ],
+    arch: {
+        // Function `AddCacheInfo` in `src/utils/list_cpu_features.c` is only used on x86/x86_64 and
+        // triggers an error with `-Werror and `-Wunused-function` on other architectures; disable
+        // the latter flag to avoid compilation errors on those architectures.
+        arm: {
+            cflags: [
+                "-Wno-unused-function",
+            ],
+        },
+        arm64: {
+            cflags: [
+                "-Wno-unused-function",
+            ],
+        },
+    },
+}
+
+// Tests.
+
+cc_defaults {
+    name: "cpu_features-test-defaults",
+    test_suites: ["device-tests"],
+    host_supported: true,
+    compile_multilib: "both",
+    local_include_dirs: [
+        "include",
+    ],
+    cflags: [
+        "-DCPU_FEATURES_TEST",
+    ],
+}
+
+cc_test_library {
+    name: "libcpu_features-string_view",
+    defaults: ["cpu_features-test-defaults"],
+    srcs: [
+        "src/string_view.c",
+    ],
+}
+
+cc_test_library {
+    name: "libcpu_features-filesystem_for_testing",
+    defaults: ["cpu_features-test-defaults"],
+    cflags: [
+        "-DCPU_FEATURES_MOCK_FILESYSTEM",
+        // TODO: Handle unused parameters in
+        // test/filesystem_for_testing.cc and remove this flag.
+        "-Wno-unused-parameter",
+    ],
+    srcs: [
+        "test/filesystem_for_testing.cc",
+    ],
+}
+
+cc_test_library {
+    name: "libcpu_features-hwcaps_for_testing",
+    defaults: ["cpu_features-test-defaults"],
+    cflags: [
+        "-DCPU_FEATURES_MOCK_GET_ELF_HWCAP_FROM_GETAUXVAL",
+        "-DCPU_FEATURES_TEST",
+    ],
+    srcs: [
+        "src/hwcaps.c",
+        "test/hwcaps_for_testing.cc",
+    ],
+    static_libs: [
+        "libcpu_features-string_view",
+        "libcpu_features-filesystem_for_testing",
+    ],
+}
+
+cc_defaults {
+    name: "stack_line_reader-defaults",
+    cflags: [
+        "-DSTACK_LINE_READER_BUFFER_SIZE=1024",
+    ],
+}
+
+cc_test_library {
+    name: "libcpu_features-stack_line_reader",
+    defaults: [
+        "cpu_features-test-defaults",
+        "stack_line_reader-defaults",
+    ],
+    srcs: [
+        "src/stack_line_reader.c",
+    ],
+    static_libs: [
+        "libcpu_features-filesystem_for_testing",
+        "libcpu_features-string_view",
+    ],
+}
+
+cc_test_library {
+    name: "libcpu_features-stack_line_reader_for_test",
+    defaults: ["cpu_features-test-defaults"],
+    cflags: [
+        "-DSTACK_LINE_READER_BUFFER_SIZE=16",
+    ],
+    srcs: [
+        "src/stack_line_reader.c",
+    ],
+    whole_static_libs: [
+        "libcpu_features-filesystem_for_testing",
+        "libcpu_features-string_view",
+    ],
+}
+
+cc_test_library {
+    name: "libcpu_features-all_libraries",
+    defaults: [
+        "cpu_features-test-defaults",
+        "stack_line_reader-defaults",
+    ],
+    whole_static_libs: [
+        "libcpu_features-filesystem_for_testing",
+        "libcpu_features-hwcaps_for_testing",
+        "libcpu_features-stack_line_reader",
+        "libcpu_features-string_view",
+    ],
+}
+
+cc_test {
+    name: "cpu_features-bit_utils_test",
+    defaults: ["cpu_features-test-defaults"],
+    srcs: [
+        "test/bit_utils_test.cc",
+    ],
+}
+
+cc_test {
+    name: "cpu_features-string_view_test",
+    defaults: ["cpu_features-test-defaults"],
+    srcs: [
+        "test/string_view_test.cc",
+        "src/string_view.c",
+    ],
+    static_libs: [
+        "libcpu_features-string_view",
+    ],
+}
+
+cc_test {
+    name: "cpu_features-stack_line_reader_test",
+    defaults: [
+        "cpu_features-test-defaults",
+        "stack_line_reader-defaults",
+    ],
+    cflags: [
+        // TODO: Handle unused funtions in
+        // test/stack_line_reader_test.cc and remove this flag.
+        "-Wno-unused-function",
+    ],
+    srcs: [
+        "test/stack_line_reader_test.cc",
+    ],
+    static_libs: [
+        "libcpu_features-stack_line_reader_for_test",
+    ],
+}
+
+cc_test {
+    name: "cpu_features-cpuinfo_test",
+    defaults: [
+        "cpu_features-test-defaults",
+    ],
+    static_libs: [
+        "libcpu_features-all_libraries",
+    ],
+    cflags: [
+        "-DSTACK_LINE_READER_BUFFER_SIZE=1024",
+    ],
+    arch: {
+        x86: {
+            cflags: [
+                "-DCPU_FEATURES_MOCK_CPUID_X86",
+                "-Wno-unused-variable",
+            ],
+            srcs: [
+                "test/cpuinfo_x86_test.cc",
+                "src/cpuinfo_x86.c",
+            ],
+        },
+        x86_64: {
+            cflags: [
+                "-DCPU_FEATURES_MOCK_CPUID_X86",
+                "-Wno-unused-variable",
+            ],
+            srcs: [
+                "test/cpuinfo_x86_test.cc",
+                "src/cpuinfo_x86.c",
+            ],
+        },
+        arm: {
+            srcs: [
+                "test/cpuinfo_arm_test.cc",
+                "src/cpuinfo_arm.c",
+            ],
+        },
+        arm64: {
+            cflags: [
+                "-Wno-gnu-designator",
+            ],
+            srcs: [
+                "test/cpuinfo_aarch64_test.cc",
+                "src/cpuinfo_aarch64.c",
+            ],
+        },
+    },
+}
diff --git a/METADATA b/METADATA
new file mode 100644
index 0000000..5e2b871
--- /dev/null
+++ b/METADATA
@@ -0,0 +1,19 @@
+name: "cpu_features"
+description: "A cross platform C99 library to get cpu features at runtime."
+third_party {
+  url {
+    type: HOMEPAGE
+    value: "https://github.com/google/cpu_features"
+  }
+  url {
+    type: GIT
+    value: "https://github.com/google/cpu_features.git"
+  }
+  version: "v0.6.0"
+  license_type: NOTICE
+  last_upgrade_date {
+    year: 2020
+    month: 10
+    day: 15
+  }
+}
diff --git a/MODULE_LICENSE_APACHE2 b/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_APACHE2
diff --git a/OWNERS b/OWNERS
new file mode 100644
index 0000000..dc4f25c
--- /dev/null
+++ b/OWNERS
@@ -0,0 +1,3 @@
+gchatelet@google.com
+rpl@google.com
+*
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
new file mode 100644
index 0000000..321bab6
--- /dev/null
+++ b/PREUPLOAD.cfg
@@ -0,0 +1,2 @@
+[Builtin Hooks]
+bpfmt = true
diff --git a/TEST_MAPPING b/TEST_MAPPING
new file mode 100644
index 0000000..824f432
--- /dev/null
+++ b/TEST_MAPPING
@@ -0,0 +1,32 @@
+{
+  "presubmit": [
+    {
+      "name": "cpu_features-bit_utils_test",
+      "host": true
+    },
+    {
+      "name": "cpu_features-bit_utils_test"
+    },
+    {
+      "name": "cpu_features-string_view_test",
+      "host": true
+    },
+    {
+      "name": "cpu_features-string_view_test"
+    },
+    {
+      "name": "cpu_features-stack_line_reader_test",
+      "host": true
+    },
+    {
+      "name": "cpu_features-stack_line_reader_test"
+    },
+    {
+      "name": "cpu_features-cpuinfo_test",
+      "host": true
+    },
+    {
+      "name": "cpu_features-cpuinfo_test"
+    }
+  ]
+}