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

Commit 128800f2 authored by Colin Cross's avatar Colin Cross
Browse files

Sort files in directories passed to jar

jar -C <dir> . produces a jar containing files in filesystem order,
which can vary between builds.  Manually find and sort the list of
files, and convert them into a list of -C <dir> <file> pairs.

Fixes: 64634025
Test: m -j checkbuild
Test: m -j out/target/product/sailfish/system/framework/ext.jar, check
      that entries are sorted
Test: m -j out/target/product/generic_arm64/system/framework/ext.jar on mac
Change-Id: I7dced6acbe621a60cd49daf17872941485602732
parent 05ecd665
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -2187,6 +2187,17 @@ define call-jack
 JACK_VERSION=$(PRIVATE_JACK_VERSION) $(JACK) $(DEFAULT_JACK_EXTRA_ARGS)
endef

# Return jar arguments to compress files in a given directory
# $(1): directory
#
# Returns an @-file argument that contains the output of a subshell
# that looks like -C $(1) path/to/file1 -C $(1) path/to/file2
# Also adds "-C out/empty ." which avoids errors in jar when
# there are no files in the directory.
define jar-args-sorted-files-in-directory
    @<(find $(1) -type f | sort | $(JAR_ARGS) $(1); echo "-C $(EMPTY_DIRECTORY) .")
endef

# Common definition to invoke javac on the host and target.
#
# Some historical notes:
@@ -2244,9 +2255,9 @@ $(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) rm -rf \
$(if $(PRIVATE_JAR_MANIFEST), \
    $(hide) sed -e "s/%BUILD_NUMBER%/$(BUILD_NUMBER_FROM_FILE)/" \
            $(PRIVATE_JAR_MANIFEST) > $(dir $@)/manifest.mf && \
        $(JAR) -cfm $@ $(dir $@)/manifest.mf \
            -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) ., \
    $(hide) $(JAR) -cf $@ -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .)
        $(JAR) -cfm $@ $(dir $@)/manifest.mf, \
    $(hide) $(JAR) -cf $@) \
        $(call jar-args-sorted-files-in-directory,$(PRIVATE_CLASS_INTERMEDIATES_DIR))
$(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@))
endef

@@ -2693,7 +2704,7 @@ define add-jar-resources-to-package
  rm -rf $(3)
  mkdir -p $(3)
  unzip -qo $(2) -d $(3) $$(zipinfo -1 $(2) | grep -v -E "\.class$$")
  $(JAR) uf $(1) -C $(3) .
  $(JAR) uf $(1) $(call jar-args-sorted-files-in-directory,$(3))
endef

# Sign a package using the specified key/cert.
+1 −0
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ $(full_classes_compiled_jar): \
        $(proto_java_sources_file_stamp) \
        $(annotation_processor_deps) \
        $(NORMALIZE_PATH) \
        $(JAR_ARGS) \
        $(LOCAL_ADDITIONAL_DEPENDENCIES) \
        | $(SOONG_JAVAC_WRAPPER)
	$(transform-host-java-to-package)
+1 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ $(full_classes_compiled_jar): \
        $(proto_java_sources_file_stamp) \
        $(annotation_processor_deps) \
        $(NORMALIZE_PATH) \
        $(JAR_ARGS) \
        $(ZIPTIME) \
        $(LOCAL_ADDITIONAL_DEPENDENCIES) \
        | $(SOONG_JAVAC_WRAPPER)
+2 −1
Original line number Diff line number Diff line
@@ -120,12 +120,13 @@ $(my_instrumented_timestamp_path): $(my_unzipped_timestamp_path) $(JACOCO_CLI_JA
$(LOCAL_FULL_CLASSES_JACOCO_JAR): PRIVATE_TEMP_JAR_PATH := $(my_temp_jar_path)
$(LOCAL_FULL_CLASSES_JACOCO_JAR): PRIVATE_INSTRUMENTED_PATH := $(my_instrumented_path)
$(LOCAL_FULL_CLASSES_JACOCO_JAR): PRIVATE_FULL_CLASSES_PRE_JACOCO_JAR := $(LOCAL_FULL_CLASSES_PRE_JACOCO_JAR)
$(LOCAL_FULL_CLASSES_JACOCO_JAR): $(JAR_ARGS)
$(LOCAL_FULL_CLASSES_JACOCO_JAR): $(my_instrumented_timestamp_path) $(LOCAL_FULL_CLASSES_PRE_JACOCO_JAR)
	rm -f $@ $(PRIVATE_TEMP_JAR_PATH)
	# copy the pre-jacoco jar (containing files excluded from instrumentation)
	cp $(PRIVATE_FULL_CLASSES_PRE_JACOCO_JAR) $(PRIVATE_TEMP_JAR_PATH)
	# copy instrumented files back into the resultant jar
	$(JAR) -uf $(PRIVATE_TEMP_JAR_PATH) -C $(PRIVATE_INSTRUMENTED_PATH) .
	$(JAR) -uf $(PRIVATE_TEMP_JAR_PATH) $(call jar-args-sorted-files-in-directory,$(PRIVATE_INSTRUMENTED_PATH))
	mv $(PRIVATE_TEMP_JAR_PATH) $@

  # this is used to trigger $(my_classes_to_report_on_path) to build
+1 −0
Original line number Diff line number Diff line
@@ -445,6 +445,7 @@ $(full_classes_compiled_jar): \
        $(proto_java_sources_file_stamp) \
        $(annotation_processor_deps) \
        $(NORMALIZE_PATH) \
        $(JAR_ARGS) \
        $(LOCAL_ADDITIONAL_DEPENDENCIES) \
        | $(SOONG_JAVAC_WRAPPER)
	$(transform-java-to-classes.jar)
Loading