From 2af4d1ad2cfbe3076a89afc9bf8bb375ef2cade1 Mon Sep 17 00:00:00 2001 From: Ying Wang Date: Thu, 22 Oct 2015 16:30:00 -0700 Subject: [PATCH] Normalize java source file paths before running "sort -u". We rely on "sort -u" to dedupe aidl/logtags generated java files added by both from $(all_java_sources) and from "find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java". But "sort -u" doesn't work if any of the aidl/logtags source file path has "../" in it. This change fixes this issue by normalizing the source file paths before passing them to "sort -u". Change-Id: I12d2c4e0397bed9f426a1ed9b13608d72d01e0df --- core/config.mk | 2 ++ core/definitions.mk | 6 +++--- tools/normalize_path.py | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100755 tools/normalize_path.py diff --git a/core/config.mk b/core/config.mk index 1ae2655e5..d19b34b60 100644 --- a/core/config.mk +++ b/core/config.mk @@ -556,6 +556,8 @@ else MD5SUM:=md5sum endif +NORMALIZE_PATH := build/tools/normalize_path.py + APICHECK_CLASSPATH := $(HOST_JDK_TOOLS_JAR) APICHECK_CLASSPATH := $(APICHECK_CLASSPATH):$(HOST_OUT_JAVA_LIBRARIES)/doclava$(COMMON_JAVA_PACKAGE_SUFFIX) APICHECK_CLASSPATH := $(APICHECK_CLASSPATH):$(HOST_OUT_JAVA_LIBRARIES)/jsilver$(COMMON_JAVA_PACKAGE_SUFFIX) diff --git a/core/definitions.mk b/core/definitions.mk index a036a2530..ecc72532d 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -1804,7 +1804,7 @@ $(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \ find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' -and -not -name '.*' >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \ fi $(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \ - | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq + | $(NORMALIZE_PATH) | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq $(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \ $(1) -encoding UTF-8 \ $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \ @@ -1867,7 +1867,7 @@ $(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \ find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list; \ fi $(hide) tr ' ' '\n' < $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list \ - | sort -u > $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq + | $(NORMALIZE_PATH) | sort -u > $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq $(if $(PRIVATE_JACK_PROGUARD_FLAGS), \ $(hide) echo -basedirectory $(CURDIR) > $@.flags; \ echo $(PRIVATE_JACK_PROGUARD_FLAGS) >> $@.flags; \ @@ -1946,7 +1946,7 @@ $(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \ find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list; \ fi $(hide) tr ' ' '\n' < $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list \ - | sort -u > $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq + | $(NORMALIZE_PATH) | sort -u > $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq $(if $(PRIVATE_JACK_PROGUARD_FLAGS), \ $(hide) echo -basedirectory $(CURDIR) > $@.flags; \ echo $(PRIVATE_JACK_PROGUARD_FLAGS) >> $@.flags; \ diff --git a/tools/normalize_path.py b/tools/normalize_path.py new file mode 100755 index 000000000..1b3d42e64 --- /dev/null +++ b/tools/normalize_path.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# +# Copyright (C) 2015 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. +""" +Normalize and output paths read from stdin. +""" + +import os.path +import sys + +for line in sys.stdin: + print os.path.normpath(line.strip()) -- 2.11.0