1# Data files for layoutlib 2 3FONT_TEMP := $(call intermediates-dir-for,PACKAGING,fonts,HOST,COMMON) 4 5# The font configuration files - system_fonts.xml, fallback_fonts.xml etc. 6font_config := $(sort $(wildcard frameworks/base/data/fonts/*.xml)) 7font_config := $(addprefix $(FONT_TEMP)/, $(notdir $(font_config))) 8 9$(font_config): $(FONT_TEMP)/%.xml: \ 10 frameworks/base/data/fonts/%.xml 11 $(hide) mkdir -p $(dir $@) 12 $(hide) cp -vf $< $@ 13 14# List of fonts on the device that we want to ship. This is all .ttf, .ttc and .otf fonts. 15fonts_device := $(filter $(TARGET_OUT)/fonts/%.ttf $(TARGET_OUT)/fonts/%.ttc $(TARGET_OUT)/fonts/%.otf, $(INTERNAL_SYSTEMIMAGE_FILES)) 16fonts_device := $(addprefix $(FONT_TEMP)/, $(notdir $(fonts_device))) 17 18# TODO: If the font file is a symlink, reuse the font renamed from the symlink 19# target. 20$(fonts_device): $(FONT_TEMP)/%: $(TARGET_OUT)/fonts/% 21 $(hide) mkdir -p $(dir $@) 22 $(hide) cp -vf $< $@ 23 24KEYBOARD_TEMP := $(call intermediates-dir-for,PACKAGING,keyboards,HOST,COMMON) 25 26# The key character map files needed for supporting KeyEvent 27keyboards := $(sort $(wildcard frameworks/base/data/keyboards/*.kcm)) 28keyboards := $(addprefix $(KEYBOARD_TEMP)/, $(notdir $(keyboards))) 29 30$(keyboards): $(KEYBOARD_TEMP)/%.kcm: frameworks/base/data/keyboards/%.kcm 31 $(hide) mkdir -p $(dir $@) 32 $(hide) cp -vf $< $@ 33 34# List of all data files - font files, font configuration files, key character map files 35LAYOUTLIB_FILES := $(fonts_device) $(font_config) $(keyboards) 36 37.PHONY: layoutlib layoutlib-tests 38layoutlib layoutlib-tests: $(LAYOUTLIB_FILES) 39 40$(call dist-for-goals, layoutlib, $(foreach m,$(fonts_device), $(m):layoutlib_native/fonts/$(notdir $(m)))) 41$(call dist-for-goals, layoutlib, $(foreach m,$(font_config), $(m):layoutlib_native/fonts/$(notdir $(m)))) 42$(call dist-for-goals, layoutlib, $(foreach m,$(keyboards), $(m):layoutlib_native/keyboards/$(notdir $(m)))) 43 44FONT_TEMP := 45font_config := 46fonts_device := 47FONT_FILES := 48 49# The following build process of build.prop, layoutlib-res.zip is moved here from release_layoutlib.sh 50# so the SBOM of all platform neutral artifacts and Linux/Windows artifacts of layoutlib can be built in Make/Soong. 51# See go/layoutlib-sbom. 52 53# build.prop shipped with layoutlib 54LAYOUTLIB_BUILD_PROP := $(call intermediates-dir-for,PACKAGING,layoutlib-build-prop,HOST,COMMON) 55$(LAYOUTLIB_BUILD_PROP)/layoutlib-build.prop: $(INSTALLED_SDK_BUILD_PROP_TARGET) 56 rm -rf $@ 57 cp $< $@ 58 # Remove all the uncommon build properties 59 sed -i '/^ro\.\(build\|product\|config\|system\)/!d' $@ 60 # Mark the build as layoutlib. This can be read at runtime by apps 61 sed -i 's|ro.product.brand=generic|ro.product.brand=studio|' $@ 62 sed -i 's|ro.product.device=generic|ro.product.device=layoutlib|' $@ 63 64$(call dist-for-goals,layoutlib,$(LAYOUTLIB_BUILD_PROP)/layoutlib-build.prop:layoutlib_native/build.prop) 65 66# Resource files from frameworks/base/core/res/res 67LAYOUTLIB_RES := $(call intermediates-dir-for,PACKAGING,layoutlib-res,HOST,COMMON) 68LAYOUTLIB_RES_FILES := $(shell find frameworks/base/core/res/res -type f -not -path 'frameworks/base/core/res/res/values-m[nc]c*' | sort) 69$(LAYOUTLIB_RES)/layoutlib-res.zip: $(SOONG_ZIP) $(HOST_OUT_EXECUTABLES)/aapt2 $(LAYOUTLIB_RES_FILES) 70 rm -rf $@ 71 echo $(LAYOUTLIB_RES_FILES) > $(LAYOUTLIB_RES)/filelist.txt 72 $(SOONG_ZIP) -C frameworks/base/core/res -l $(LAYOUTLIB_RES)/filelist.txt -o $(LAYOUTLIB_RES)/temp.zip 73 rm -rf $(LAYOUTLIB_RES)/data && unzip -q -d $(LAYOUTLIB_RES)/data $(LAYOUTLIB_RES)/temp.zip 74 rm -rf $(LAYOUTLIB_RES)/compiled && mkdir $(LAYOUTLIB_RES)/compiled && $(HOST_OUT_EXECUTABLES)/aapt2 compile $(LAYOUTLIB_RES)/data/res/**/*.9.png -o $(LAYOUTLIB_RES)/compiled 75 printf '<?xml version="1.0" encoding="utf-8"?>\n<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.android.layoutlib" />' > $(LAYOUTLIB_RES)/AndroidManifest.xml 76 $(HOST_OUT_EXECUTABLES)/aapt2 link -R $(LAYOUTLIB_RES)/compiled/* -o $(LAYOUTLIB_RES)/compiled.apk --manifest $(LAYOUTLIB_RES)/AndroidManifest.xml 77 rm -rf $(LAYOUTLIB_RES)/compiled_apk && unzip -q -d $(LAYOUTLIB_RES)/compiled_apk $(LAYOUTLIB_RES)/compiled.apk 78 for f in $(LAYOUTLIB_RES)/compiled_apk/res/*; do mv "$$f" "$${f/-v4/}";done 79 for f in $(LAYOUTLIB_RES)/compiled_apk/res/**/*.9.png; do mv "$$f" "$${f/.9.png/.compiled.9.png}";done 80 cp -r $(LAYOUTLIB_RES)/compiled_apk/res $(LAYOUTLIB_RES)/data 81 $(SOONG_ZIP) -C $(LAYOUTLIB_RES)/data -D $(LAYOUTLIB_RES)/data/res -o $@ 82 83$(call dist-for-goals,layoutlib,$(LAYOUTLIB_RES)/layoutlib-res.zip:layoutlib_native/res.zip) 84 85# SBOM of layoutlib artifacts 86LAYOUTLIB_SBOM := $(call intermediates-dir-for,PACKAGING,layoutlib-sbom,HOST) 87_layoutlib_font_config_files := $(sort $(wildcard frameworks/base/data/fonts/*.xml)) 88_layoutlib_fonts_files := $(filter $(TARGET_OUT)/fonts/%.ttf $(TARGET_OUT)/fonts/%.ttc $(TARGET_OUT)/fonts/%.otf, $(INTERNAL_SYSTEMIMAGE_FILES)) 89_layoutlib_keyboard_files := $(sort $(wildcard frameworks/base/data/keyboards/*.kcm)) 90 91# Find out files disted with layoutlib in Soong. 92### Filter out static libraries for Windows and files already handled in make. 93_layoutlib_filter_out_disted := $(addprefix layoutlib_native/,fonts/% keyboards/% build.prop res.zip windows/%.a) 94_layoutlib_files_disted_by_soong := \ 95 $(strip \ 96 $(foreach p,$(_all_dist_src_dst_pairs), \ 97 $(if $(filter-out $(_layoutlib_filter_out_disted),$(filter layoutlib_native/% layoutlib.jar,$(call word-colon,2,$p))),$p))) 98 99$(LAYOUTLIB_SBOM)/sbom-metadata.csv: 100 rm -rf $@ 101 echo installed_file,module_path,soong_module_type,is_prebuilt_make_module,product_copy_files,kernel_module_copy_files,is_platform_generated,build_output_path,static_libraries,whole_static_libraries,is_static_lib >> $@ 102 echo build.prop,,,,,,Y,$(LAYOUTLIB_BUILD_PROP)/layoutlib-build.prop,,, >> $@ 103 104 $(foreach f,$(_layoutlib_font_config_files),\ 105 echo data/fonts/$(notdir $f),frameworks/base/data/fonts,prebuilt_etc,,,,,$f,,, >> $@; \ 106 ) 107 108 $(foreach f,$(_layoutlib_fonts_files), \ 109 $(eval _module_name := $(ALL_INSTALLED_FILES.$f)) \ 110 $(eval _module_path := $(strip $(sort $(ALL_MODULES.$(_module_name).PATH)))) \ 111 $(eval _soong_module_type := $(strip $(sort $(ALL_MODULES.$(_module_name).SOONG_MODULE_TYPE)))) \ 112 echo data/fonts/$(notdir $f),$(_module_path),$(_soong_module_type),,,,,$f,,, >> $@; \ 113 ) 114 115 $(foreach f,$(_layoutlib_keyboard_files), \ 116 echo data/keyboards/$(notdir $f),frameworks/base/data/keyboards,prebuilt_etc,,,,,$f,,, >> $@; \ 117 ) 118 119 $(foreach f,$(_layoutlib_files_disted_by_soong), \ 120 $(eval _prebuilt_module_file := $(call word-colon,1,$f)) \ 121 $(eval _dist_file := $(call word-colon,2,$f)) \ 122 $(eval _dist_file := $(patsubst data/windows/%,data/win/lib64/%,$(patsubst layoutlib_native/%,data/%,$(_dist_file)))) \ 123 $(eval _dist_file := $(subst layoutlib.jar,data/layoutlib.jar,$(_dist_file))) \ 124 $(eval _module_name := $(strip $(foreach m,$(ALL_MODULES),$(if $(filter $(_prebuilt_module_file),$(ALL_MODULES.$m.CHECKED)),$m)))) \ 125 $(eval _module_path := $(strip $(sort $(ALL_MODULES.$(_module_name).PATH)))) \ 126 $(eval _soong_module_type := $(strip $(sort $(ALL_MODULES.$(_module_name).SOONG_MODULE_TYPE)))) \ 127 echo $(patsubst layoutlib_native/%,%,$(_dist_file)),$(_module_path),$(_soong_module_type),,,,,$(_prebuilt_module_file),,, >> $@; \ 128 ) 129 130 $(foreach f,$(LAYOUTLIB_RES_FILES), \ 131 $(eval _path := $(subst frameworks/base/core/res,data,$f)) \ 132 echo $(_path),,,,,,Y,$f,,, >> $@; \ 133 ) 134 135.PHONY: layoutlib-sbom 136layoutlib-sbom: $(LAYOUTLIB_SBOM)/layoutlib.spdx.json 137$(LAYOUTLIB_SBOM)/layoutlib.spdx.json: $(PRODUCT_OUT)/always_dirty_file.txt $(GEN_SBOM) $(LAYOUTLIB_SBOM)/sbom-metadata.csv $(_layoutlib_font_config_files) $(_layoutlib_fonts_files) $(LAYOUTLIB_BUILD_PROP)/layoutlib-build.prop $(_layoutlib_keyboard_files) $(LAYOUTLIB_RES_FILES) 138 rm -rf $@ 139 $(GEN_SBOM) --output_file $@ --metadata $(LAYOUTLIB_SBOM)/sbom-metadata.csv --build_version $(BUILD_FINGERPRINT_FROM_FILE) --product_mfr "$(PRODUCT_MANUFACTURER)" --module_name "layoutlib" --json 140 141$(call dist-for-goals,layoutlib,$(LAYOUTLIB_SBOM)/layoutlib.spdx.json:layoutlib_native/sbom/layoutlib.spdx.json) 142 143# Generate SBOM of framework_res.jar that is created in release_layoutlib.sh. 144# The generated SBOM contains placeholders for release_layotlib.sh to substitute, and the placeholders include: 145# document name, document namespace, document creation info, organization and SHA1 value of framework_res.jar. 146GEN_SBOM_FRAMEWORK_RES := $(HOST_OUT_EXECUTABLES)/generate-sbom-framework_res 147.PHONY: layoutlib-framework_res-sbom 148layoutlib-framework_res-sbom: $(LAYOUTLIB_SBOM)/framework_res.jar.spdx.json 149$(LAYOUTLIB_SBOM)/framework_res.jar.spdx.json: $(LAYOUTLIB_SBOM)/layoutlib.spdx.json $(GEN_SBOM_FRAMEWORK_RES) 150 rm -rf $@ 151 $(GEN_SBOM_FRAMEWORK_RES) --output_file $(LAYOUTLIB_SBOM)/framework_res.jar.spdx.json --layoutlib_sbom $(LAYOUTLIB_SBOM)/layoutlib.spdx.json 152 153$(call dist-for-goals,layoutlib,$(LAYOUTLIB_SBOM)/framework_res.jar.spdx.json:layoutlib_native/sbom/framework_res.jar.spdx.json)