Makes it possible to find files used by some unit tests when running them as Chrome native tests.
BUG=N/A
R=andrew@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/1749004
git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@4298 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/test/test.gyp b/test/test.gyp
index 7f12a71..1fdc609 100644
--- a/test/test.gyp
+++ b/test/test.gyp
@@ -62,6 +62,8 @@
'sources': [
'test_suite.cc',
'test_suite.h',
+ 'testsupport/android/root_path_android.cc',
+ 'testsupport/android/root_path_android_chromium.cc',
'testsupport/fileutils.cc',
'testsupport/fileutils.h',
'testsupport/frame_reader.cc',
@@ -79,6 +81,36 @@
'testsupport/trace_to_stderr.cc',
'testsupport/trace_to_stderr.h',
],
+ 'conditions': [
+ # TODO(henrike): remove build_with_chromium==1 when the bots are using
+ # Chromium's buildbots.
+ ['build_with_chromium==1 and OS=="android" and gtest_target_type=="shared_library"', {
+ 'dependencies': [
+ '<(DEPTH)/base/base.gyp:base',
+ ],
+ 'sources!': [
+ 'testsupport/android/root_path_android.cc',
+ ],
+ # WebRTC tests use resource files for testing. These files are not
+ # hosted in WebRTC. The script ensures that the needed resources
+ # are downloaded. In stand alone WebRTC the script is called by
+ # the DEPS file. In Chromium, i.e. here, the files are pulled down
+ # only if tests requiring the resources are being built.
+ 'actions': [
+ {
+ 'action_name': 'get_resources',
+ 'inputs': ['<(webrtc_root)/tools/update_resources.py'],
+ 'outputs': ['../../resources'],
+ 'action': ['python',
+ '<(webrtc_root)/tools/update_resources.py',
+ '-p ../../../'],
+ }],
+ }, {
+ 'sources!': [
+ 'testsupport/android/root_path_android_chromium.cc',
+ ],
+ }],
+ ],
},
{
# Depend on this target when you want to have test_support but also the
diff --git a/test/testsupport/android/root_path_android.cc b/test/testsupport/android/root_path_android.cc
new file mode 100644
index 0000000..d93552e
--- /dev/null
+++ b/test/testsupport/android/root_path_android.cc
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+namespace webrtc {
+namespace test {
+
+static const char* kRootDirName = "/sdcard/";
+std::string ProjectRoothPathAndroid() {
+ return kRootDirName;
+}
+
+std::string OutputPathAndroid() {
+ return kRootDirName;
+}
+
+} // namespace test
+} // namespace webrtc
diff --git a/test/testsupport/android/root_path_android_chromium.cc b/test/testsupport/android/root_path_android_chromium.cc
new file mode 100644
index 0000000..1db73ae
--- /dev/null
+++ b/test/testsupport/android/root_path_android_chromium.cc
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "base/android/path_utils.h"
+#include "base/files/file_path.h"
+
+namespace webrtc {
+namespace test {
+
+std::string OutputPathImpl();
+
+// This file is only compiled when running WebRTC tests in a Chromium workspace.
+// The Android testing framework will push files relative to the root path of
+// the Chromium workspace. The root path for webrtc is one directory up from
+// trunk/webrtc (in standalone) or src/third_party/webrtc (in Chromium).
+std::string ProjectRoothPathAndroid() {
+ base::FilePath root_path;
+ base::android::GetExternalStorageDirectory(&root_path);
+ return root_path.value() + "/";
+}
+
+std::string OutputPathAndroid() {
+ return OutputPathImpl();
+}
+
+} // namespace test
+} // namespace webrtc
diff --git a/test/testsupport/fileutils.cc b/test/testsupport/fileutils.cc
index 61e4bcf..84945ff 100644
--- a/test/testsupport/fileutils.cc
+++ b/test/testsupport/fileutils.cc
@@ -31,28 +31,33 @@
namespace webrtc {
namespace test {
+namespace {
+
#ifdef WIN32
-static const char* kPathDelimiter = "\\";
+const char* kPathDelimiter = "\\";
#else
-static const char* kPathDelimiter = "/";
+const char* kPathDelimiter = "/";
#endif
#ifdef WEBRTC_ANDROID
-static const char* kRootDirName = "/sdcard/";
-static const char* kResourcesDirName = "resources";
+const char* kResourcesDirName = "resources";
#else
// The file we're looking for to identify the project root dir.
-static const char* kProjectRootFileName = "DEPS";
-static const char* kOutputDirName = "out";
-static const char* kFallbackPath = "./";
-static const char* kResourcesDirName = "resources";
+const char* kProjectRootFileName = "DEPS";
+const char* kResourcesDirName = "resources";
#endif
-const char* kCannotFindProjectRootDir = "ERROR_CANNOT_FIND_PROJECT_ROOT_DIR";
-namespace {
+const char* kFallbackPath = "./";
+const char* kOutputDirName = "out";
char relative_dir_path[FILENAME_MAX];
bool relative_dir_path_set = false;
-}
+
+} // namespace
+
+const char* kCannotFindProjectRootDir = "ERROR_CANNOT_FIND_PROJECT_ROOT_DIR";
+
+std::string OutputPathAndroid();
+std::string ProjectRoothPathAndroid();
void SetExecutablePath(const std::string& path) {
std::string working_dir = WorkingDir();
@@ -73,18 +78,30 @@
return stat(file_name.c_str(), &file_info) == 0;
}
+std::string OutputPathImpl() {
+ std::string path = ProjectRootPath();
+ if (path == kCannotFindProjectRootDir) {
+ return kFallbackPath;
+ }
+ path += kOutputDirName;
+ if (!CreateDirectory(path)) {
+ return kFallbackPath;
+ }
+ return path + kPathDelimiter;
+}
+
#ifdef WEBRTC_ANDROID
std::string ProjectRootPath() {
- return kRootDirName;
+ return ProjectRoothPathAndroid();
}
std::string OutputPath() {
- return kRootDirName;
+ return OutputPathAndroid();
}
std::string WorkingDir() {
- return kRootDirName;
+ return ProjectRootPath();
}
#else // WEBRTC_ANDROID
@@ -114,15 +131,7 @@
}
std::string OutputPath() {
- std::string path = ProjectRootPath();
- if (path == kCannotFindProjectRootDir) {
- return kFallbackPath;
- }
- path += kOutputDirName;
- if (!CreateDirectory(path)) {
- return kFallbackPath;
- }
- return path + kPathDelimiter;
+ return OutputPathImpl();
}
std::string WorkingDir() {
diff --git a/tools/update.py b/tools/update_resources.py
similarity index 94%
rename from tools/update.py
rename to tools/update_resources.py
index a1ac085..f68d7c6 100755
--- a/tools/update.py
+++ b/tools/update_resources.py
@@ -23,6 +23,7 @@
VERSION_FILENAME = 'webrtc-resources-version'
FILENAME_PREFIX = 'webrtc-resources-'
EXTENSION = '.tgz'
+RELATIVE_OUTPUT_PATH = '../../'
def main():
@@ -41,14 +42,6 @@
print 'Skipping resources download since WEBRTC_SKIP_RESOURCES_DOWNLOAD set'
return
- project_root_dir = os.path.normpath(sys.path[0] + '/../../')
- downloads_dir = os.path.join(project_root_dir, 'resources')
- current_version_file = os.path.join(downloads_dir, VERSION_FILENAME)
-
- # Ensure the downloads dir is created.
- if not os.path.isdir(downloads_dir):
- os.mkdir(downloads_dir)
-
# Define and parse arguments.
parser = OptionParser()
parser.add_option('-f', '--force', action='store_true', dest='force',
@@ -56,7 +49,17 @@
parser.add_option('-b', '--base_url', dest='base_url',
help= 'Overrides the default Base URL (%s) and uses the '
'supplied URL instead.' % REMOTE_URL_BASE)
- (options, unused_args) = parser.parse_args()
+ parser.add_option('-p', dest='path', help= 'path of resources directory'
+ 'relative to this script', default=RELATIVE_OUTPUT_PATH)
+ options = parser.parse_args()[0]
+
+ project_root_dir = os.path.normpath(sys.path[0] + '/' + options.path)
+ downloads_dir = os.path.join(project_root_dir, 'resources')
+ current_version_file = os.path.join(downloads_dir, VERSION_FILENAME)
+
+ # Ensure the downloads dir is created.
+ if not os.path.isdir(downloads_dir):
+ os.mkdir(downloads_dir)
# Download archive if forced or DEPS version is different than our current.
current_version = _get_current_version(current_version_file)