Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: third_party/mojo/src/mojo/public/tools/mojom_fetcher/pylib/fetcher/dependency.py

Issue 1058033002: NOT TO COMMITTED: Update mojo sdk to rev 0018e6a91b75bcb941c867f8a7aa1753c3b53a13 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/mojo/src/mojo/public/tools/mojom_fetcher/pylib/fetcher/dependency.py
diff --git a/third_party/mojo/src/mojo/public/tools/mojom_fetcher/pylib/fetcher/dependency.py b/third_party/mojo/src/mojo/public/tools/mojom_fetcher/pylib/fetcher/dependency.py
new file mode 100644
index 0000000000000000000000000000000000000000..a4716e4e86ac2b4f085823c529a8eb0dca0cccf1
--- /dev/null
+++ b/third_party/mojo/src/mojo/public/tools/mojom_fetcher/pylib/fetcher/dependency.py
@@ -0,0 +1,97 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+
+
+class Dependency(object):
+ """Dependency represents an import request from one mojom file to another.
+ """
+ def __init__(self, repository, importer, imported):
+ self._repository = repository
+ self._importer_filename = os.path.normpath(importer)
+ self._imported_filename = os.path.normpath(imported)
+
+ def __str__(self):
+ return str(self.__dict__)
+
+ def __eq__(self, other):
+ return self.__dict__ == other.__dict__
+
+ def get_importer(self):
+ """Returns the name and full path of the file doing the import."""
+ return self._importer_filename
+
+ def get_imported(self):
+ """Returns the imported file (filename and path)."""
+ return self._imported_filename
+
+ def is_sdk_dep(self):
+ """Returns whether this dependency is from the mojo SDK."""
+ return (self._imported_filename.startswith("mojo/public/") or
+ self._imported_filename.startswith("//mojo/public/"))
+
+ def _is_in_external(self):
+ """Returns whether this dependency is under the external directory."""
+ common = os.path.commonprefix((self._repository.get_external_directory(),
+ self._importer_filename))
+ return common == self._repository.get_external_directory()
+
+ def maybe_is_a_url(self):
+ """Returns whether this dependency may be pointing to a downloadable
+ ressource."""
+ if self._is_in_external() and not self.is_sdk_dep():
+ # External dependencies may refer to other dependencies by relative path,
+ # so they can always be URLs.
+ return True
+
+ base, _ = self._imported_filename.split(os.path.sep, 1)
+ if not '.' in base:
+ # There is no dot separator in the first part of the path; it cannot be a
+ # URL.
+ return False
+ return True
+
+ def generate_candidate_urls(self):
+ """Generates possible paths where to download this dependency. It is
+ expected that at most one of them should work."""
+ candidates = []
+
+ base, _ = self._imported_filename.split(os.path.sep, 1)
+ if '.' in base and not base.startswith('.'):
+ # This import may be an absolute URL path (without scheme).
+ candidates.append(self._imported_filename)
+
+ # External dependencies may refer to other dependencies by relative path.
+ if self._is_in_external():
+ directory = os.path.relpath(os.path.dirname(self._importer_filename),
+ self._repository.get_external_directory())
+
+ # This is to handle the case where external dependencies use
+ # imports relative to a directory upper in the directory structure. As we
+ # don't know which directory, we need to go through all of them.
+ while len(directory) > 0:
+ candidates.append(os.path.join(directory, self._imported_filename))
+ directory = os.path.dirname(directory)
+ return candidates
+
+ def get_search_path_for_dependency(self):
+ """Return all possible search paths for this dependency."""
+
+ # Root directory and external directory are always included.
+ search_paths = set([self._repository.get_repo_root_directory(),
+ self._repository.get_external_directory()])
+ # Local import paths
+ search_paths.add(os.path.dirname(self._importer_filename))
+
+ if self._is_in_external():
+ directory = os.path.dirname(self._importer_filename)
+
+ # This is to handle the case where external dependencies use
+ # imports relative to a directory upper in the directory structure. As we
+ # don't know which directory, we need to go through all of them.
+ while self._repository.get_external_directory() in directory:
+ search_paths.add(directory)
+ directory = os.path.dirname(directory)
+ return search_paths

Powered by Google App Engine
This is Rietveld 408576698