github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/soong/java/androidmk.go (about)

     1  // Copyright 2015 Google Inc. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package java
    16  
    17  import (
    18  	"fmt"
    19  	"io"
    20  	"strings"
    21  
    22  	"github.com/google/blueprint/proptools"
    23  
    24  	"android/soong/android"
    25  )
    26  
    27  func (library *Library) AndroidMk() android.AndroidMkData {
    28  	return android.AndroidMkData{
    29  		Class:      "JAVA_LIBRARIES",
    30  		OutputFile: android.OptionalPathForPath(library.implementationJarFile),
    31  		Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
    32  		Extra: []android.AndroidMkExtraFunc{
    33  			func(w io.Writer, outputFile android.Path) {
    34  				if len(library.logtagsSrcs) > 0 {
    35  					var logtags []string
    36  					for _, l := range library.logtagsSrcs {
    37  						logtags = append(logtags, l.Rel())
    38  					}
    39  					fmt.Fprintln(w, "LOCAL_LOGTAGS_FILES :=", strings.Join(logtags, " "))
    40  				}
    41  
    42  				if library.properties.Installable != nil && *library.properties.Installable == false {
    43  					fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
    44  				}
    45  				if library.dexJarFile != nil {
    46  					fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
    47  					if library.deviceProperties.Dex_preopt.Enabled != nil {
    48  						fmt.Fprintln(w, "LOCAL_DEX_PREOPT :=", *library.deviceProperties.Dex_preopt.Enabled)
    49  					}
    50  					if library.deviceProperties.Dex_preopt.App_image != nil {
    51  						fmt.Fprintln(w, "LOCAL_DEX_PREOPT_APP_IMAGE :=", *library.deviceProperties.Dex_preopt.App_image)
    52  					}
    53  					if library.deviceProperties.Dex_preopt.Profile_guided != nil {
    54  						fmt.Fprintln(w, "LOCAL_DEX_PREOPT_GENERATE_PROFILE :=", *library.deviceProperties.Dex_preopt.Profile_guided)
    55  					}
    56  					if library.deviceProperties.Dex_preopt.Profile != nil {
    57  						fmt.Fprintln(w, "LOCAL_DEX_PREOPT_GENERATE_PROFILE := true")
    58  						fmt.Fprintln(w, "LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING := $(LOCAL_PATH)/"+*library.deviceProperties.Dex_preopt.Profile)
    59  					}
    60  				}
    61  				fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(library.deviceProperties.Sdk_version))
    62  				fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
    63  
    64  				if library.jacocoReportClassesFile != nil {
    65  					fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", library.jacocoReportClassesFile.String())
    66  				}
    67  
    68  				// Temporary hack: export sources used to compile framework.jar to Make
    69  				// to be used for droiddoc
    70  				// TODO(ccross): remove this once droiddoc is in soong
    71  				if library.Name() == "framework" {
    72  					fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCS :=", strings.Join(library.compiledJavaSrcs.Strings(), " "))
    73  					fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCJARS :=", strings.Join(library.compiledSrcJars.Strings(), " "))
    74  				}
    75  			},
    76  		},
    77  		Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
    78  			android.WriteAndroidMkData(w, data)
    79  
    80  			if proptools.Bool(library.deviceProperties.Hostdex) && !library.Host() {
    81  				fmt.Fprintln(w, "include $(CLEAR_VARS)")
    82  				fmt.Fprintln(w, "LOCAL_MODULE := "+name+"-hostdex")
    83  				fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
    84  				fmt.Fprintln(w, "LOCAL_MODULE_CLASS := JAVA_LIBRARIES")
    85  				fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.implementationJarFile.String())
    86  				if library.properties.Installable != nil && *library.properties.Installable == false {
    87  					fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
    88  				}
    89  				if library.dexJarFile != nil {
    90  					fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
    91  				}
    92  				fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.implementationJarFile.String())
    93  				fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " "))
    94  				fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
    95  			}
    96  		},
    97  	}
    98  }
    99  
   100  func (prebuilt *Import) AndroidMk() android.AndroidMkData {
   101  	return android.AndroidMkData{
   102  		Class:      "JAVA_LIBRARIES",
   103  		OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
   104  		Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
   105  		Extra: []android.AndroidMkExtraFunc{
   106  			func(w io.Writer, outputFile android.Path) {
   107  				fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !proptools.Bool(prebuilt.properties.Installable))
   108  				fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
   109  				fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(prebuilt.properties.Sdk_version))
   110  			},
   111  		},
   112  	}
   113  }
   114  
   115  func (prebuilt *AARImport) AndroidMk() android.AndroidMkData {
   116  	return android.AndroidMkData{
   117  		Class:      "JAVA_LIBRARIES",
   118  		OutputFile: android.OptionalPathForPath(prebuilt.classpathFile),
   119  		Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
   120  		Extra: []android.AndroidMkExtraFunc{
   121  			func(w io.Writer, outputFile android.Path) {
   122  				fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
   123  				fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
   124  				fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.classpathFile.String())
   125  				fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", prebuilt.exportPackage.String())
   126  				fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", prebuilt.proguardFlags.String())
   127  				fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", prebuilt.extraAaptPackagesFile.String())
   128  				fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(prebuilt.properties.Sdk_version))
   129  			},
   130  		},
   131  	}
   132  }
   133  
   134  func (binary *Binary) AndroidMk() android.AndroidMkData {
   135  
   136  	if !binary.isWrapperVariant {
   137  		return android.AndroidMkData{
   138  			Class:      "JAVA_LIBRARIES",
   139  			OutputFile: android.OptionalPathForPath(binary.implementationJarFile),
   140  			Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
   141  			Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
   142  				android.WriteAndroidMkData(w, data)
   143  
   144  				fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
   145  			},
   146  		}
   147  	} else {
   148  		return android.AndroidMkData{
   149  			Class:      "EXECUTABLES",
   150  			OutputFile: android.OptionalPathForPath(binary.wrapperFile),
   151  			Extra: []android.AndroidMkExtraFunc{
   152  				func(w io.Writer, outputFile android.Path) {
   153  					fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
   154  				},
   155  			},
   156  			Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
   157  				android.WriteAndroidMkData(w, data)
   158  
   159  				// Ensure that the wrapper script timestamp is always updated when the jar is updated
   160  				fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
   161  				fmt.Fprintln(w, "jar_installed_module :=")
   162  			},
   163  		}
   164  	}
   165  }
   166  
   167  func (app *AndroidApp) AndroidMk() android.AndroidMkData {
   168  	return android.AndroidMkData{
   169  		Class:      "APPS",
   170  		OutputFile: android.OptionalPathForPath(app.outputFile),
   171  		Include:    "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
   172  		Extra: []android.AndroidMkExtraFunc{
   173  			func(w io.Writer, outputFile android.Path) {
   174  				fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", app.exportPackage.String())
   175  				if app.dexJarFile != nil {
   176  					fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", app.dexJarFile.String())
   177  				}
   178  				if app.implementationJarFile != nil {
   179  					fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", app.implementationJarFile)
   180  				}
   181  				if app.headerJarFile != nil {
   182  					fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", app.headerJarFile.String())
   183  				}
   184  				if app.jacocoReportClassesFile != nil {
   185  					fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", app.jacocoReportClassesFile.String())
   186  				}
   187  				if app.proguardDictionary != nil {
   188  					fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", app.proguardDictionary.String())
   189  				}
   190  
   191  				if app.Name() == "framework-res" {
   192  					fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
   193  					// Make base_rules.mk not put framework-res in a subdirectory called
   194  					// framework_res.
   195  					fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
   196  				}
   197  
   198  				if len(app.rroDirs) > 0 {
   199  					// Reverse the order, Soong stores rroDirs in aapt2 order (low to high priority), but Make
   200  					// expects it in LOCAL_RESOURCE_DIRS order (high to low priority).
   201  					fmt.Fprintln(w, "LOCAL_SOONG_RRO_DIRS :=", strings.Join(android.ReversePaths(app.rroDirs).Strings(), " "))
   202  				}
   203  
   204  				if Bool(app.appProperties.Export_package_resources) {
   205  					fmt.Fprintln(w, "LOCAL_EXPORT_PACKAGE_RESOURCES := true")
   206  				}
   207  
   208  				fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", app.manifestPath.String())
   209  
   210  				if Bool(app.appProperties.Privileged) {
   211  					fmt.Fprintln(w, "LOCAL_PRIVILEGED_MODULE := true")
   212  				}
   213  
   214  				fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", app.certificate.pem.String())
   215  			},
   216  		},
   217  	}
   218  }
   219  
   220  func (a *AndroidLibrary) AndroidMk() android.AndroidMkData {
   221  	data := a.Library.AndroidMk()
   222  
   223  	data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
   224  		if a.proguardDictionary != nil {
   225  			fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", a.proguardDictionary.String())
   226  		}
   227  
   228  		if a.Name() == "framework-res" {
   229  			fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
   230  			// Make base_rules.mk not put framework-res in a subdirectory called
   231  			// framework_res.
   232  			fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
   233  		}
   234  
   235  		fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", a.exportPackage.String())
   236  		fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", a.extraAaptPackagesFile.String())
   237  		fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", a.manifestPath.String())
   238  		fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=",
   239  			strings.Join(a.exportedProguardFlagFiles.Strings(), " "))
   240  		fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
   241  		fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
   242  	})
   243  
   244  	return data
   245  }
   246  
   247  func (jd *Javadoc) AndroidMk() android.AndroidMkData {
   248  	return android.AndroidMkData{
   249  		Class:      "JAVA_LIBRARIES",
   250  		OutputFile: android.OptionalPathForPath(jd.stubsJar),
   251  		Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
   252  		Extra: []android.AndroidMkExtraFunc{
   253  			func(w io.Writer, outputFile android.Path) {
   254  				if jd.properties.Installable == nil || *jd.properties.Installable == true {
   255  					fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", jd.docZip.String())
   256  				}
   257  				if jd.stubsJar != nil {
   258  					fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_JAR := ", jd.stubsJar.String())
   259  				}
   260  			},
   261  		},
   262  	}
   263  }
   264  
   265  func (ddoc *Droiddoc) AndroidMk() android.AndroidMkData {
   266  	return android.AndroidMkData{
   267  		Class:      "JAVA_LIBRARIES",
   268  		OutputFile: android.OptionalPathForPath(ddoc.stubsJar),
   269  		Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
   270  		Extra: []android.AndroidMkExtraFunc{
   271  			func(w io.Writer, outputFile android.Path) {
   272  				if ddoc.Javadoc.properties.Installable == nil || *ddoc.Javadoc.properties.Installable == true {
   273  					fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", ddoc.Javadoc.docZip.String())
   274  				}
   275  				if ddoc.Javadoc.stubsJar != nil {
   276  					fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_JAR := ", ddoc.Javadoc.stubsJar.String())
   277  				}
   278  			},
   279  		},
   280  	}
   281  }