in src/TulsiGenerator/Scripts/install_genfiles.py [0:0]
def InstallForData(self, output_data):
"""Symlinks generated sources present in the output_data."""
bazel_exec_root = self.bazel_exec_root
tulsi_root = self.tulsi_root
for gs in output_data['generated_sources']:
real_path, link_path = gs
src = os.path.join(bazel_exec_root, real_path)
# Bazel outputs are not guaranteed to be created if nothing references
# them. This check skips the processing if an output was declared
# but not created.
if not os.path.exists(src):
continue
# The /x/x/ part is here to match the number of directory components
# between tulsi root and bazel root. See tulsi_aspects.bzl for futher
# explanation.
dst = os.path.join(tulsi_root, 'x/x/', link_path)
dst_dir = os.path.dirname(dst)
if not os.path.exists(dst_dir):
os.makedirs(dst_dir)
# It's important to use lexists() here in case dst is a broken symlink
# (in which case exists() would return False).
if os.path.lexists(dst):
# Don't need to do anything if the link hasn't changed.
if os.readlink(dst) == src:
continue
# Link changed; must remove it otherwise os.symlink will fail.
os.unlink(dst)
os.symlink(src, dst)