blob: e57d896dfdc34599ecf24da885f47274a5108e0a [file] [log] [blame]
David Brazdil39fb8662020-01-09 10:20:37 +00001#!/usr/bin/env python3
2#
3# Copyright 2019 The Hafnium Authors.
4#
Andrew Walbrane959ec12020-06-17 15:01:09 +01005# Use of this source code is governed by a BSD-style
6# license that can be found in the LICENSE file or at
7# https://opensource.org/licenses/BSD-3-Clause.
David Brazdil39fb8662020-01-09 10:20:37 +00008
9"""Parse Repo manifest and symlink files specified in <linkfile> tags.
10
11This is a workaround for Kokoro which does not support <linkfile>.
12"""
13
14import argparse
15import os
16import sys
17import xml.etree.ElementTree as ET
18
19def main():
20 parser = argparse.ArgumentParser()
21 parser.add_argument("root_dir", help="root directory")
22 args = parser.parse_args()
23
24 manifest = os.path.join(args.root_dir, ".repo", "manifest.xml")
25 tree = ET.parse(manifest)
26 root = tree.getroot()
27 assert(root.tag == "manifest");
28
29 for proj in root:
30 if proj.tag != "project":
31 continue
32
33 proj_name = proj.attrib["name"]
34 proj_path = proj.attrib["path"]
35
36 for linkfile in proj:
37 if linkfile.tag != "linkfile":
38 continue
39
40 linkfile_src = linkfile.attrib["src"]
41 linkfile_dest = linkfile.attrib["dest"]
42 src_path = os.path.join(
43 args.root_dir, proj_path, linkfile_src)
44 dest_path = os.path.join(args.root_dir, linkfile_dest)
45
46 os.symlink(src_path, dest_path)
47
48if __name__ == "__main__":
49 sys.exit(main())