Stubs/api check for legacy-test and android.test.runner
Adds stub generation for legacy-test classes and android.test.runner
classes. Changes name of android.test.mock.sdk to
android.test.mock.stubs for consistency and clarity, adds new
temporary android.test.mock.sdk target to prevent build breakage.
Adds api check and update targets for legacy.test.stubs,
android.test.runner.stubs and android.test.mock.stubs to prevent
accidental changes to the API.
Bug: 30188076
Test: make checkapi and make update-api
Change-Id: I40cc7b967f1ab1c7e148407d6965526550ee2f9b
diff --git a/test-runner/Android.mk b/test-runner/Android.mk
index 0752661..b41dadb 100644
--- a/test-runner/Android.mk
+++ b/test-runner/Android.mk
@@ -16,6 +16,8 @@
LOCAL_PATH:= $(call my-dir)
+android_test_mock_source_files := $(call all-java-files-under, src/android/test/mock)
+
# Build the android.test.runner library
# =====================================
include $(CLEAR_VARS)
@@ -28,11 +30,109 @@
include $(BUILD_JAVA_LIBRARY)
+# Generate the stub source files for android.test.runner.stubs
+# ============================================================
+include $(CLEAR_VARS)
+
+# Exclude android.test.mock classes as stubs for them are created in the
+# android.test.mock.stubs target
+LOCAL_SRC_FILES := \
+ $(filter-out $(android_test_mock_source_files), $(call all-java-files-under, src))
+
+LOCAL_JAVA_LIBRARIES := \
+ core-oj \
+ core-libart \
+ framework \
+ legacy-test \
+ android.test.mock \
+
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+LOCAL_DROIDDOC_SOURCE_PATH := $(LOCAL_PATH)/src
+
+ANDROID_TEST_RUNNER_OUTPUT_API_FILE := $(TARGET_OUT_COMMON_INTERMEDIATES)/JAVA_LIBRARIES/android.test.runner.stubs_intermediates/api.txt
+ANDROID_TEST_RUNNER_OUTPUT_REMOVED_API_FILE := $(TARGET_OUT_COMMON_INTERMEDIATES)/JAVA_LIBRARIES/android.test.runner.stubs_intermediates/removed.txt
+
+ANDROID_TEST_RUNNER_API_FILE := $(LOCAL_PATH)/api/android-test-runner-current.txt
+ANDROID_TEST_RUNNER_REMOVED_API_FILE := $(LOCAL_PATH)/api/android-test-runner-removed.txt
+
+LOCAL_DROIDDOC_OPTIONS:= \
+ -stubpackages android.test:android.test.suitebuilder:junit.runner:junit.textui \
+ -stubsourceonly \
+ -stubs $(TARGET_OUT_COMMON_INTERMEDIATES)/JAVA_LIBRARIES/android.test.runner.stubs_intermediates/src \
+ -nodocs \
+ -api $(ANDROID_TEST_RUNNER_OUTPUT_API_FILE) \
+ -removedApi $(ANDROID_TEST_RUNNER_OUTPUT_REMOVED_API_FILE) \
+
+LOCAL_UNINSTALLABLE_MODULE := true
+LOCAL_MODULE := android-test-runner-api-stubs-gen
+
+include $(BUILD_DROIDDOC)
+
+# Remember the target that will trigger the code generation.
+android_test_runner_api_gen_stamp := $(full_target)
+
+# Add some additional dependencies
+$(ANDROID_TEST_RUNNER_OUTPUT_API_FILE): $(full_target)
+$(ANDROID_TEST_RUNNER_OUTPUT_REMOVED_API_FILE): $(full_target)
+
+# Build the android.test.runner.stubs library
+# ===========================================
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := android.test.runner.stubs
+
+LOCAL_JAVA_LIBRARIES := \
+ legacy.test.stubs \
+ android.test.mock.stubs \
+
+LOCAL_SOURCE_FILES_ALL_GENERATED := true
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
+
+# Make sure to run droiddoc first to generate the stub source files.
+$(full_classes_compiled_jar) : $(android_test_runner_api_gen_stamp)
+$(full_classes_jack) : $(android_test_runner_api_gen_stamp)
+
+# Archive a copy of the classes.jar in SDK build.
+$(call dist-for-goals,sdk win_sdk,$(full_classes_jar):android.test.runner.stubs.jar)
+
+# Check that the android.test.runner.stubs library has not changed
+# ================================================================
+
+# Check that the API we're building hasn't changed from the not-yet-released
+# SDK version.
+$(eval $(call check-api, \
+ check-android-test-runner-api-current, \
+ $(ANDROID_TEST_RUNNER_API_FILE), \
+ $(ANDROID_TEST_RUNNER_OUTPUT_API_FILE), \
+ $(ANDROID_TEST_RUNNER_REMOVED_API_FILE), \
+ $(ANDROID_TEST_RUNNER_OUTPUT_REMOVED_API_FILE), \
+ -error 2 -error 3 -error 4 -error 5 -error 6 \
+ -error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 -error 14 -error 15 \
+ -error 16 -error 17 -error 18 -error 19 -error 20 -error 21 -error 23 -error 24 \
+ -error 25 -error 26 -error 27, \
+ cat $(LOCAL_PATH)/api/apicheck_msg_android_test_runner.txt, \
+ check-android-test-runner-api, \
+ $(call doc-timestamp-for,android-test-runner-api-stubs-gen) \
+ ))
+
+.PHONY: check-android-test-runner-api
+checkapi: check-android-test-runner-api
+
+.PHONY: update-android-test-runner-api
+update-api: update-android-test-runner-api
+
+update-android-test-runner-api: $(ANDROID_TEST_RUNNER_OUTPUT_API_FILE) | $(ACP)
+ @echo Copying current.txt
+ $(hide) $(ACP) $(ANDROID_TEST_RUNNER_OUTPUT_API_FILE) $(ANDROID_TEST_RUNNER_API_FILE)
+ @echo Copying removed.txt
+ $(hide) $(ACP) $(ANDROID_TEST_RUNNER_OUTPUT_REMOVED_API_FILE) $(ANDROID_TEST_RUNNER_REMOVED_API_FILE)
+
# Build the android.test.mock library
# ===================================
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := $(call all-java-files-under, src/android/test/mock)
+LOCAL_SRC_FILES := $(android_test_mock_source_files)
LOCAL_JAVA_LIBRARIES := core-oj core-libart framework
@@ -40,33 +140,45 @@
include $(BUILD_JAVA_LIBRARY)
-# Generate the stub source files for android.test.mock.sdk
-# ========================================================
+# Generate the stub source files for android.test.mock.stubs
+# ==========================================================
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := $(call all-java-files-under, src/android/test/mock)
+LOCAL_SRC_FILES := $(android_test_mock_source_files)
LOCAL_JAVA_LIBRARIES := core-oj core-libart framework
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
LOCAL_DROIDDOC_SOURCE_PATH := $(LOCAL_PATH)/src/android/test/mock
+ANDROID_TEST_MOCK_OUTPUT_API_FILE := $(TARGET_OUT_COMMON_INTERMEDIATES)/JAVA_LIBRARIES/android.test.mock.stubs_intermediates/api.txt
+ANDROID_TEST_MOCK_OUTPUT_REMOVED_API_FILE := $(TARGET_OUT_COMMON_INTERMEDIATES)/JAVA_LIBRARIES/android.test.mock.stubs_intermediates/removed.txt
+
+ANDROID_TEST_MOCK_API_FILE := $(LOCAL_PATH)/api/android-test-mock-current.txt
+ANDROID_TEST_MOCK_REMOVED_API_FILE := $(LOCAL_PATH)/api/android-test-mock-removed.txt
+
LOCAL_DROIDDOC_OPTIONS:= \
-stubpackages android.test.mock \
- -stubs $(TARGET_OUT_COMMON_INTERMEDIATES)/JAVA_LIBRARIES/android.test.mock.sdk_intermediates/src \
- -nodocs
+ -stubs $(TARGET_OUT_COMMON_INTERMEDIATES)/JAVA_LIBRARIES/android.test.mock.stubs_intermediates/src \
+ -nodocs \
+ -api $(ANDROID_TEST_MOCK_OUTPUT_API_FILE) \
+ -removedApi $(ANDROID_TEST_MOCK_OUTPUT_REMOVED_API_FILE) \
LOCAL_UNINSTALLABLE_MODULE := true
-LOCAL_MODULE := android-test-mock-stubs-gen
+LOCAL_MODULE := android-test-mock-api-stubs-gen
include $(BUILD_DROIDDOC)
# Remember the target that will trigger the code generation.
android_test_mock_gen_stamp := $(full_target)
-# Build the android.test.mock.sdk library
-# =======================================
+# Add some additional dependencies
+$(ANDROID_TEST_MOCK_OUTPUT_API_FILE): $(full_target)
+$(ANDROID_TEST_MOCK_OUTPUT_REMOVED_API_FILE): $(full_target)
+
+# Build the android.test.mock.stubs library
+# =========================================
include $(CLEAR_VARS)
-LOCAL_MODULE := android.test.mock.sdk
+LOCAL_MODULE := android.test.mock.stubs
LOCAL_SOURCE_FILES_ALL_GENERATED := true
@@ -77,7 +189,49 @@
$(full_classes_jack) : $(android_test_mock_gen_stamp)
# Archive a copy of the classes.jar in SDK build.
-$(call dist-for-goals,sdk win_sdk,$(full_classes_jar):android.test.mock.jar)
+$(call dist-for-goals,sdk win_sdk,$(full_classes_jar):android.test.mock.stubs.jar)
+
+# Check that the android.test.mock.stubs library has not changed
+# ==============================================================
+
+# Check that the API we're building hasn't changed from the not-yet-released
+# SDK version.
+$(eval $(call check-api, \
+ check-android-test-mock-api-current, \
+ $(ANDROID_TEST_MOCK_API_FILE), \
+ $(ANDROID_TEST_MOCK_OUTPUT_API_FILE), \
+ $(ANDROID_TEST_MOCK_REMOVED_API_FILE), \
+ $(ANDROID_TEST_MOCK_OUTPUT_REMOVED_API_FILE), \
+ -error 2 -error 3 -error 4 -error 5 -error 6 \
+ -error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 -error 14 -error 15 \
+ -error 16 -error 17 -error 18 -error 19 -error 20 -error 21 -error 23 -error 24 \
+ -error 25 -error 26 -error 27, \
+ cat $(LOCAL_PATH)/api/apicheck_msg_android_test_mock.txt, \
+ check-android-test-mock-api, \
+ $(call doc-timestamp-for,android-test-mock-api-stubs-gen) \
+ ))
+
+.PHONY: check-android-test-mock-api
+checkapi: check-android-test-mock-api
+
+.PHONY: update-android-test-mock-api
+update-api: update-android-test-mock-api
+
+update-android-test-mock-api: $(ANDROID_TEST_MOCK_OUTPUT_API_FILE) | $(ACP)
+ @echo Copying current.txt
+ $(hide) $(ACP) $(ANDROID_TEST_MOCK_OUTPUT_API_FILE) $(ANDROID_TEST_MOCK_API_FILE)
+ @echo Copying removed.txt
+ $(hide) $(ACP) $(ANDROID_TEST_MOCK_OUTPUT_REMOVED_API_FILE) $(ANDROID_TEST_MOCK_REMOVED_API_FILE)
+
+# Build the android.test.mock.sdk library
+# =======================================
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := android.test.mock.sdk
+
+LOCAL_STATIC_JAVA_LIBRARIES := android.test.mock.stubs
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
# additionally, build unit tests in a separate .apk
include $(call all-makefiles-under,$(LOCAL_PATH))