Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1448b0b7 authored by Ying Wang's avatar Ying Wang
Browse files

Remove emulator-based dexpreopt code

Now dexpreopt is done on the host side.

Change-Id: I1ea1a5d1fac2531028e017364ef870abb7420be7
parent d56d69b6
Loading
Loading
Loading
Loading

tools/dexpreopt/Android.mk

deleted100644 → 0
+0 −38
Original line number Diff line number Diff line
#
# Copyright (C) 2008 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.
#
ifneq ($(TARGET_SIMULATOR),true)
ifneq ($(DISABLE_DEXPREOPT),true)

LOCAL_PATH := $(my-dir)
include $(CLEAR_VARS)
LOCAL_PREBUILT_EXECUTABLES := dexpreopt.py
include $(BUILD_SYSTEM)/host_prebuilt.mk
DEXPREOPT := $(LOCAL_INSTALLED_MODULE)

# The script uses some other tools; make sure that they're
# installed along with it.
tools := \
	emulator$(HOST_EXECUTABLE_SUFFIX)

$(DEXPREOPT): | $(addprefix $(HOST_OUT_EXECUTABLES)/,$(tools))

subdir_makefiles := \
		$(LOCAL_PATH)/dexopt-wrapper/Android.mk \
		$(LOCAL_PATH)/afar/Android.mk
include $(subdir_makefiles)

endif # !disable_dexpreopt
endif # !sim

tools/dexpreopt/Config.mk

deleted100644 → 0
+0 −153
Original line number Diff line number Diff line
#
# Copyright (C) 2008 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.
#

#
# Included by config/Makefile.
# Defines the pieces necessary for the dexpreopt process.
#
# inputs: INSTALLED_RAMDISK_TARGET, BUILT_SYSTEMIMAGE_UNOPT
# outputs: BUILT_SYSTEMIMAGE, SYSTEMIMAGE_SOURCE_DIR
#
LOCAL_PATH := $(my-dir)

# TODO: see if we can make the .odex files not be product-specific.
# They can't be completely common, though, because their format
# depends on the architecture of the target system; ARM and x86
# would have different versions.
intermediates := \
	$(call intermediates-dir-for,PACKAGING,dexpreopt)
dexpreopt_system_dir := $(intermediates)/system
built_afar := $(call intermediates-dir-for,EXECUTABLES,afar)/afar
built_dowrapper := \
	$(call intermediates-dir-for,EXECUTABLES,dexopt-wrapper)/dexopt-wrapper

# Generate a stripped-down init.rc based on the real one.
dexpreopt_initrc := $(intermediates)/etc/init.rc
geninitrc_script := $(LOCAL_PATH)/geninitrc.awk
$(dexpreopt_initrc): script := $(geninitrc_script)
$(dexpreopt_initrc): system/core/rootdir/init.rc $(geninitrc_script)
	@echo "Dexpreopt init.rc: $@"
	@mkdir -p $(dir $@)
	$(hide) awk -f $(script) < $< > $@

BUILT_DEXPREOPT_RAMDISK := $(intermediates)/ramdisk.img
$(BUILT_DEXPREOPT_RAMDISK): intermediates := $(intermediates)
$(BUILT_DEXPREOPT_RAMDISK): dexpreopt_root_out := $(intermediates)/root
$(BUILT_DEXPREOPT_RAMDISK): dexpreopt_initrc := $(dexpreopt_initrc)
$(BUILT_DEXPREOPT_RAMDISK): built_afar := $(built_afar)
$(BUILT_DEXPREOPT_RAMDISK): built_dowrapper := $(built_dowrapper)
$(BUILT_DEXPREOPT_RAMDISK): \
	$(INSTALLED_RAMDISK_TARGET) \
	$(dexpreopt_initrc) \
	$(built_afar) \
	$(built_dowrapper) \
	| $(MKBOOTFS) $(ACP)
$(BUILT_DEXPREOPT_RAMDISK):
	@echo "Dexpreopt ramdisk: $@"
	$(hide) rm -f $@
	$(hide) rm -rf $(dexpreopt_root_out)
	$(hide) mkdir -p $(dexpreopt_root_out)
	$(hide) $(ACP) -rd $(TARGET_ROOT_OUT) $(intermediates)
	$(hide) $(ACP) -f $(dexpreopt_initrc) $(dexpreopt_root_out)/
	$(hide) $(ACP) $(built_afar) $(dexpreopt_root_out)/sbin/
	$(hide) $(ACP) $(built_dowrapper) $(dexpreopt_root_out)/sbin/
	$(MKBOOTFS) $(dexpreopt_root_out) | gzip > $@

sign_dexpreopt := true
ifdef sign_dexpreopt
  # Such a huge hack.  We need to re-sign the .apks with the
  # same certs that they were originally signed with.
  dexpreopt_package_certs_file := $(intermediates)/package-certs
  $(shell mkdir -p $(intermediates))
  $(shell rm -f $(dexpreopt_package_certs_file))
  $(foreach p,$(PACKAGES),\
    $(shell echo "$(p) $(PACKAGES.$(p).CERTIFICATE) $(PACKAGES.$(p).PRIVATE_KEY)" >> $(dexpreopt_package_certs_file)))
endif

# The kernel used for ARMv7 system images is different
ifeq ($(ARCH_ARM_HAVE_ARMV7A),true)
BUILD_DEXPREOPT_KERNEL := prebuilt/android-arm/kernel/kernel-qemu-armv7
else
BUILD_DEXPREOPT_KERNEL := prebuilt/android-arm/kernel/kernel-qemu
endif

# Build an optimized image from the unoptimized image
BUILT_DEXPREOPT_SYSTEMIMAGE := $(intermediates)/system.img
$(BUILT_DEXPREOPT_SYSTEMIMAGE): $(BUILT_SYSTEMIMAGE_UNOPT)
$(BUILT_DEXPREOPT_SYSTEMIMAGE): $(BUILT_DEXPREOPT_RAMDISK)
$(BUILT_DEXPREOPT_SYSTEMIMAGE): | $(DEXPREOPT) $(ACP) $(ZIPALIGN)
$(BUILT_DEXPREOPT_SYSTEMIMAGE): SYSTEM_DIR := $(dexpreopt_system_dir)
$(BUILT_DEXPREOPT_SYSTEMIMAGE): DEXPREOPT_TMP := $(intermediates)/emutmp
ifdef sign_dexpreopt
$(BUILT_DEXPREOPT_SYSTEMIMAGE): | $(SIGNAPK_JAR)
endif
$(BUILT_DEXPREOPT_SYSTEMIMAGE):
	@rm -f $@
	@echo "dexpreopt: copy system to $(SYSTEM_DIR)"
	@rm -rf $(SYSTEM_DIR)
	@mkdir -p $(dir $(SYSTEM_DIR))
	$(hide) $(ACP) -rd $(TARGET_OUT) $(SYSTEM_DIR)
	@echo "dexpreopt: optimize dex files"
	@rm -rf $(DEXPREOPT_TMP)
	@mkdir -p $(DEXPREOPT_TMP)
	$(hide) \
	    PATH=$(HOST_OUT_EXECUTABLES):$$PATH \
	    $(DEXPREOPT) \
		    --kernel $(BUILD_DEXPREOPT_KERNEL) \
		    --ramdisk $(BUILT_DEXPREOPT_RAMDISK) \
		    --image $(BUILT_SYSTEMIMAGE_UNOPT) \
		    --system $(PRODUCT_OUT) \
		    --tmpdir $(DEXPREOPT_TMP) \
		    --outsystemdir $(SYSTEM_DIR)
ifdef sign_dexpreopt
	@echo "dexpreopt: re-sign apk files"
	$(hide) \
	    export PATH=$(HOST_OUT_EXECUTABLES):$$PATH; \
	    for apk in $(SYSTEM_DIR)/app/*.apk; do \
		packageName=`basename $$apk`; \
		packageName=`echo $$packageName | sed -e 's/.apk$$//'`; \
		cert=`grep "^$$packageName " $(dexpreopt_package_certs_file) | \
		      awk '{print $$2}'`; \
		pkey=`grep "^$$packageName " $(dexpreopt_package_certs_file) | \
		      awk '{print $$3}'`; \
		if [ "$$cert" -a "$$pkey" ]; then \
		    echo "dexpreopt: re-sign app/"$$packageName".apk"; \
		    tmpApk=$$apk~; \
		    rm -f $$tmpApk; \
		    java -jar $(SIGNAPK_JAR) $$cert $$pkey $$apk $$tmpApk || \
			  exit 11; \
		    mv -f $$tmpApk $$apk; \
		else \
		    echo "dexpreopt: no keys for app/"$$packageName".apk"; \
		    rm $(SYSTEM_DIR)/app/$$packageName.* && \
			cp $(TARGET_OUT)/app/$$packageName.apk \
			   $(SYSTEM_DIR)/app || exit 12; \
		fi; \
		tmpApk=$$apk~; \
		rm -f $$tmpApk; \
		$(ZIPALIGN) -f 4 $$apk $$tmpApk || exit 13; \
		mv -f $$tmpApk $$apk; \
	    done
endif
	@echo "Dexpreopt system image: $@"
	$(hide) $(MKYAFFS2) -f $(SYSTEM_DIR) $@

.PHONY: dexpreoptimage
dexpreoptimage: $(BUILT_DEXPREOPT_SYSTEMIMAGE)

# Tell our caller to use the optimized systemimage
BUILT_SYSTEMIMAGE := $(BUILT_DEXPREOPT_SYSTEMIMAGE)
SYSTEMIMAGE_SOURCE_DIR := $(dexpreopt_system_dir)

tools/dexpreopt/afar/Android.mk

deleted100644 → 0
+0 −29
Original line number Diff line number Diff line
#
# Copyright (C) 2008 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.
#
LOCAL_PATH := $(my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
	main.c

# Just for adler32()
LOCAL_C_INCLUDES := external/zlib
LOCAL_SHARED_LIBRARIES := libz

LOCAL_MODULE := afar
LOCAL_MODULE_TAGS := optional

include $(BUILD_EXECUTABLE)

tools/dexpreopt/afar/main.c

deleted100644 → 0
+0 −247
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 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.
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>

#include <stdarg.h>
#include <fcntl.h>
#include <termios.h>

#include <zlib.h>   // for adler32()

static int verbose = 0;

/*
 * Android File Archive format:
 *
 * magic[5]: 'A' 'F' 'A' 'R' '\n'
 * version[4]: 0x00 0x00 0x00 0x01
 * for each file:
 *     file magic[4]: 'F' 'I' 'L' 'E'
 *     namelen[4]: Length of file name, including NUL byte (big-endian)
 *     name[*]: NUL-terminated file name
 *     datalen[4]: Length of file (big-endian)
 *     data[*]: Unencoded file data
 *     adler32[4]: adler32 of the unencoded file data (big-endian)
 *     file end magic[4]: 'f' 'i' 'l' 'e'
 * end magic[4]: 'E' 'N' 'D' 0x00
 *
 * This format is about as simple as possible;  it was designed to
 * make it easier to transfer multiple files over an stdin/stdout
 * pipe to another process, so word-alignment wasn't necessary.
 */

static void
die(const char *why, ...)
{
    va_list ap;
    
    va_start(ap, why);
    fprintf(stderr, "error: ");
    vfprintf(stderr, why, ap);
    fprintf(stderr, "\n");
    va_end(ap);
    exit(1);
}

static void
write_big_endian(size_t v)
{
    putchar((v >> 24) & 0xff);
    putchar((v >> 16) & 0xff);
    putchar((v >>  8) & 0xff);
    putchar( v        & 0xff);
}

static void
_eject(struct stat *s, char *out, int olen, char *data, size_t datasize)
{
    unsigned long adler;

    /* File magic.
     */
    printf("FILE");

    /* Name length includes the NUL byte.
     */
    write_big_endian(olen + 1);

    /* File name and terminating NUL.
     */
    printf("%s", out);
    putchar('\0');

    /* File length.
     */
    write_big_endian(datasize);

    /* File data.
     */
    if (fwrite(data, 1, datasize, stdout) != datasize) {
        die("Error writing file data");
    }

    /* Checksum.
     */
    adler = adler32(0, NULL, 0);
    adler = adler32(adler, (unsigned char *)data, datasize);
    write_big_endian(adler);

    /* File end magic.
     */
    printf("file");
}

static void _archive(char *in, int ilen);

static void
_archive_dir(char *in, int ilen)
{
    int t;
    DIR *d;
    struct dirent *de;

    if (verbose) {
        fprintf(stderr, "_archive_dir('%s', %d)\n", in, ilen);
    }
    
    d = opendir(in);
    if (d == 0) {
        die("cannot open directory '%s'", in);
    }
    
    while ((de = readdir(d)) != 0) {
            /* xxx: feature? maybe some dotfiles are okay */
        if (strcmp(de->d_name, ".") == 0 ||
            strcmp(de->d_name, "..") == 0)
        {
            continue;
        }

        t = strlen(de->d_name);
        in[ilen] = '/';
        memcpy(in + ilen + 1, de->d_name, t + 1);

        _archive(in, ilen + t + 1);

        in[ilen] = '\0';
    }
}

static void
_archive(char *in, int ilen)
{
    struct stat s;

    if (verbose) {
        fprintf(stderr, "_archive('%s', %d)\n", in, ilen);
    }
    
    if (lstat(in, &s)) {
        die("could not stat '%s'\n", in);
    }

    if (S_ISREG(s.st_mode)) {
        char *tmp;
        int fd;

        fd = open(in, O_RDONLY);
        if (fd < 0) {
            die("cannot open '%s' for read", in);
        }

        tmp = (char*) malloc(s.st_size);
        if (tmp == 0) {
            die("cannot allocate %d bytes", s.st_size);
        }

        if (read(fd, tmp, s.st_size) != s.st_size) {
            die("cannot read %d bytes", s.st_size);
        }

        _eject(&s, in, ilen, tmp, s.st_size);
        
        free(tmp);
        close(fd);
    } else if (S_ISDIR(s.st_mode)) {
        _archive_dir(in, ilen);
    } else {
        /* We don't handle links, etc. */
        die("Unknown '%s' (mode %d)?\n", in, s.st_mode);
    }
}

void archive(const char *start)
{
    char in[8192];

    strcpy(in, start);

    _archive_dir(in, strlen(in));
}

int
main(int argc, char *argv[])
{
    struct termios old_termios;

    if (argc == 1) {
        die("usage: %s <dir-list>", argv[0]);
    }
    argc--;
    argv++;

    /* Force stdout into raw mode.
     */
    struct termios s;
    if (tcgetattr(1, &s) < 0) {
        die("Could not get termios for stdout");
    }
    old_termios = s;
    cfmakeraw(&s);
    if (tcsetattr(1, TCSANOW, &s) < 0) {
        die("Could not set termios for stdout");
    }

    /* Print format magic and version.
     */
    printf("AFAR\n");
    write_big_endian(1);

    while (argc-- > 0) {
        archive(*argv++);
    }

    /* Print end magic.
     */
    printf("END");
    putchar('\0');

    /* Restore stdout.
     */
    if (tcsetattr(1, TCSANOW, &old_termios) < 0) {
        die("Could not restore termios for stdout");
    }

    return 0;
}
+0 −36
Original line number Diff line number Diff line
#
# Copyright (C) 2008 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.
#

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
       DexOptWrapper.cpp

LOCAL_C_INCLUDES += \
        dalvik

LOCAL_STATIC_LIBRARIES := \
        libdex

LOCAL_SHARED_LIBRARIES := \
        libcutils

LOCAL_MODULE := dexopt-wrapper

LOCAL_MODULE_TAGS := optional

include $(BUILD_EXECUTABLE)
Loading