xref: /aosp_15_r20/external/libchrome/base/android/java/templates/NativeLibraries.template (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package org.chromium.base.library_loader;
6
7public class NativeLibraries {
8    /**
9     * IMPORTANT NOTE: The variables defined here must _not_ be 'final'.
10     *
11     * The reason for this is very subtle:
12     *
13     * - This template is used to generate several distinct, but similar
14     *   files used in different contexts:
15     *
16     *   o .../gen/templates/org/chromium/base/library_loader/NativeLibraries.java
17     *
18     *     This file is used to build base.jar, which is the library
19     *     jar used by chromium projects. However, the
20     *     corresponding NativeLibraries.class file will _not_ be part
21     *     of the final base.jar.
22     *
23     *   o .../$PROJECT/native_libraries_java/NativeLibraries.java
24     *
25     *     This file is used to build an APK (e.g. $PROJECT
26     *     could be 'content_shell_apk'). Its content will depend on
27     *     this target's specific build configuration, and differ from
28     *     the source file above.
29     *
30     * - During the final link, all .jar files are linked together into
31     *   a single .dex file, and the second version of NativeLibraries.class
32     *   will be put into the final output file, and used at runtime.
33     *
34     * - If the variables were defined as 'final', their value would be
35     *   optimized out inside of 'base.jar', and could not be specialized
36     *   for every chromium program. This, however, doesn't apply to arrays of
37     *   strings, which can be defined as final.
38     *
39     * This exotic scheme is used to avoid injecting project-specific, or
40     * even build-specific, values into the base layer. E.g. this is
41     * how the component build is supported on Android without modifying
42     * the sources of each and every Chromium-based target.
43     */
44
45    public static final int CPU_FAMILY_UNKNOWN = 0;
46    public static final int CPU_FAMILY_ARM = 1;
47    public static final int CPU_FAMILY_MIPS = 2;
48    public static final int CPU_FAMILY_X86 = 3;
49
50#if defined(ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE) && \
51    !defined(ENABLE_CHROMIUM_LINKER)
52#error "Must have ENABLE_CHROMIUM_LINKER to enable library in zip file"
53#endif
54
55    // Set to true to enable the use of the Chromium Linker.
56#if defined(ENABLE_CHROMIUM_LINKER)
57    public static boolean sUseLinker = true;
58#else
59    public static boolean sUseLinker = false;
60#endif
61
62#if defined(ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE)
63    public static boolean sUseLibraryInZipFile = true;
64#else
65    public static boolean sUseLibraryInZipFile = false;
66#endif
67
68#if defined(ENABLE_CHROMIUM_LINKER_TESTS)
69    public static boolean sEnableLinkerTests = true;
70#else
71    public static boolean sEnableLinkerTests = false;
72#endif
73
74    // This is the list of native libraries to be loaded (in the correct order)
75    // by LibraryLoader.java.  The base java library is compiled with no
76    // array defined, and then the build system creates a version of the file
77    // with the real list of libraries required (which changes based upon which
78    // .apk is being built).
79    // TODO(cjhopman): This is public since it is referenced by NativeTestActivity.java
80    // directly. The two ways of library loading should be refactored into one.
81    public static final String[] LIBRARIES =
82#if defined(NATIVE_LIBRARIES_LIST)
83      NATIVE_LIBRARIES_LIST;
84#else
85      {};
86#endif
87
88    // This is the expected version of the 'main' native library, which is the one that
89    // implements the initial set of base JNI functions including
90    // base::android::nativeGetVersionName()
91    static String sVersionNumber =
92#if defined(NATIVE_LIBRARIES_VERSION_NUMBER)
93      NATIVE_LIBRARIES_VERSION_NUMBER;
94#else
95      "";
96#endif
97
98    public static int sCpuFamily =
99#if defined(ANDROID_APP_CPU_FAMILY_ARM)
100        CPU_FAMILY_ARM;
101#elif defined(ANDROID_APP_CPU_FAMILY_X86)
102        CPU_FAMILY_X86;
103#elif defined(ANDROID_APP_CPU_FAMILY_MIPS)
104        CPU_FAMILY_MIPS;
105#else
106        CPU_FAMILY_UNKNOWN;
107#endif
108
109}
110