#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

NO_JS_MANIFEST = 1
MOZ_CHROME_FILE_FORMAT = jar
DIST_FILES = install.rdf

# Used in install.rdf
USE_EXTENSION_MANIFEST = 1

_DEST_DIR = $(DEPTH)/_tests/$(relativesrcdir)

include $(topsrcdir)/config/rules.mk
# We're installing to _tests/testing/mochitest, so this is the depth
# necessary for relative objdir paths.
TARGET_DEPTH = ../../..
include $(topsrcdir)/build/automation-build.mk

libs:: 
	(cd $(DIST)/xpi-stage && tar $(TAR_CREATE_FLAGS) - mochijar) | (cd $(_DEST_DIR) && tar -xf -)

# Binaries and scripts that don't get packaged with the build,
# but that we need for the test harness
TEST_HARNESS_BINS := \
  xpcshell$(BIN_SUFFIX) \
  ssltunnel$(BIN_SUFFIX) \
  certutil$(BIN_SUFFIX) \
  pk12util$(BIN_SUFFIX) \
  BadCertServer$(BIN_SUFFIX) \
  ClientAuthServer$(BIN_SUFFIX) \
  OCSPStaplingServer$(BIN_SUFFIX) \
  GenerateOCSPResponse$(BIN_SUFFIX) \
  fix_stack_using_bpsyms.py \
  $(NULL)

ifeq ($(OS_ARCH),WINNT)
TEST_HARNESS_BINS += \
  crashinject$(BIN_SUFFIX) \
  crashinjectdll$(DLL_SUFFIX) \
  vmwarerecordinghelper$(DLL_SUFFIX) \
  $(NULL)
endif

ifeq ($(OS_ARCH),Darwin)
TEST_HARNESS_BINS += fix_macosx_stack.py
endif

ifeq ($(OS_ARCH),Linux)
TEST_HARNESS_BINS += fix_linux_stack.py
endif

ifeq (gtk2_1,$(MOZ_WIDGET_TOOLKIT)_$(MOZ_X11))
TEST_HARNESS_BINS += screentopng
endif

ifeq (windows,$(MOZ_WIDGET_TOOLKIT))
TEST_HARNESS_BINS += screenshot$(BIN_SUFFIX)
ifdef MOZ_METRO
TEST_HARNESS_BINS += metrotestharness$(BIN_SUFFIX)
endif
endif

ifdef MOZ_DMD
TEST_HARNESS_BINS += dmd.py
endif

# Components / typelibs that don't get packaged with
# the build, but that we need for the test harness.
TEST_HARNESS_COMPONENTS := \
  test_necko.xpt \
  $(NULL)

# We need the test plugin as some tests rely on it
ifeq (Darwin,$(OS_TARGET))
TEST_HARNESS_PLUGINS := \
  Test.plugin/ \
  SecondTest.plugin/ \
  JavaTest.plugin/
else
TEST_HARNESS_PLUGINS := \
  $(DLL_PREFIX)nptest$(DLL_SUFFIX) \
  $(DLL_PREFIX)npsecondtest$(DLL_SUFFIX) \
  $(DLL_PREFIX)nptestjava$(DLL_SUFFIX)
endif

# Rules for staging the necessary harness bits for a test package
PKG_STAGE = $(DIST)/test-stage
DIST_BIN = $(DIST)/bin

GMP_TEST_PLUGIN_DIRS := \
  $(DIST_BIN)/gmp-fake \
  $(DIST_BIN)/gmp-clearkey \
  $(NULL)

$(_DEST_DIR):
	$(NSINSTALL) -D $@

# On Android only, include a release signed Robocop APK in the test package.
ifeq ($(MOZ_BUILD_APP),mobile/android)
JAVA_CLASSPATH = $(ANDROID_SDK)/android.jar
include $(topsrcdir)/config/android-common.mk

stage-package-android:
	$(NSINSTALL) -D $(_DEST_DIR)
	$(call RELEASE_SIGN_ANDROID_APK,\
		$(DEPTH)/build/mobile/robocop/robocop-debug-unsigned-unaligned.apk,\
		$(_DEST_DIR)/robocop.apk)

stage-package: stage-package-android
endif

stage-package:
	$(NSINSTALL) -D $(PKG_STAGE)/mochitest && $(NSINSTALL) -D $(PKG_STAGE)/bin/plugins && $(NSINSTALL) -D $(DIST)/plugins
	cp $(DEPTH)/mozinfo.json $(PKG_STAGE)/mochitest
	(cd $(DEPTH)/_tests/testing && tar $(TAR_CREATE_FLAGS) - mochitest) | (cd $(PKG_STAGE) && tar -xf -)
	@cp $(DEPTH)/mozinfo.json $(PKG_STAGE)/mochitest
	@(cd $(DIST_BIN) && tar $(TAR_CREATE_FLAGS) - $(TEST_HARNESS_BINS)) | (cd $(PKG_STAGE)/bin && tar -xf -)
	@(cd $(DIST_BIN)/components && tar $(TAR_CREATE_FLAGS) - $(TEST_HARNESS_COMPONENTS)) | (cd $(PKG_STAGE)/bin/components && tar -xf -)
	(cd $(topsrcdir)/build/pgo && tar $(TAR_CREATE_FLAGS) - certs) | (cd $(PKG_STAGE) && tar -xf -)
	@(cd $(DIST)/plugins && tar $(TAR_CREATE_FLAGS) - $(TEST_HARNESS_PLUGINS)) | (cd $(PKG_STAGE)/bin/plugins && tar -xf -)
	$(foreach x,$(GMP_TEST_PLUGIN_DIRS),cp -RL $(x) $(PKG_STAGE)/bin/plugins;)
