Skip to content
Snippets Groups Projects

De-hack the bazel plugins

Merged Tom Coldrick requested to merge coldtom/improve-plugins into master
1 file
+ 18
4
Compare changes
  • Side-by-side
  • Inline
  • 06c4e929
    sources/bazel.py: Make tracking work · 06c4e929
    Tom Coldrick authored
    Previously tracking was broken. Tracking works by taking the SHA256 of
    the repository resolved file. We can't ensure the sources once host
    bazel has been used, as it looks like the order of the sources is
    non-deterministic.
+ 18
4
@@ -35,7 +35,7 @@ class BazelSource(Source):
BST_REQUIRES_PREVIOUS_SOURCES_FETCH = True
BST_REQUIRES_PREVIOUS_SOURCES_TRACK = False
BST_REQUIRES_PREVIOUS_SOURCES_TRACK = True
def configure(self, node):
node.validate_keys(['workspace-dir', 'allow-host-bazel', 'repo-file', 'targets', 'ref'] + Source.COMMON_CONFIG_KEYS)
@@ -93,16 +93,27 @@ class BazelSource(Source):
assert os.path.isfile(repo_file)
with open(repo_file) as repo:
ref = hashlib.sha256(repo).hexdigest()
return ref
ref = hashlib.sha256()
for line in repo.readlines():
ref.update(line.encode('utf-8'))
return ref.hexdigest()
def fetch(self, previous_sources_dir):
workspace = os.path.join(previous_sources_dir, self.workspace_dir)
repo_file = os.path.join(workspace, self.repo_file)
self._ensure_repo_file(repo_file, workspace)
used_host = self._ensure_repo_file(repo_file, workspace)
assert os.path.isfile(repo_file)
with open(repo_file) as repo:
ref = hashlib.sha256()
for line in repo.readlines():
ref.update(line.encode('utf-8'))
if ref.hexdigest() != self.get_ref() and not used_host:
raise SourceError("{}: Ref {} does not match specified {}".format(self, ref.hexdigest(), self.get_ref()))
else:
self.warn("{}: Not checking ref, using host bazel affects repo file".format(self))
repo_contents = _import_repo_file(repo_file)
dist_dir = os.path.join(self._mirror, self._distdir)
@@ -144,6 +155,9 @@ class BazelSource(Source):
if exit_code != 0:
raise SourceError("{}: Failed to generate repository file with host bazel".format(self))
return True
return False
def _handle_single_source(self, source, directory):
if 'original_attributes' not in source.keys():
self.warn("{}: Bazel dependency has no 'original_attributes'".format(self))
Loading