David Brazdil | 39fb866 | 2020-01-09 10:20:37 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright 2019 The Hafnium Authors. |
| 4 | # |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 5 | # 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 Brazdil | 39fb866 | 2020-01-09 10:20:37 +0000 | [diff] [blame] | 8 | |
| 9 | """Parse Repo manifest and symlink files specified in <linkfile> tags. |
| 10 | |
| 11 | This is a workaround for Kokoro which does not support <linkfile>. |
| 12 | """ |
| 13 | |
| 14 | import argparse |
| 15 | import os |
| 16 | import sys |
| 17 | import xml.etree.ElementTree as ET |
| 18 | |
| 19 | def 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 | |
| 48 | if __name__ == "__main__": |
| 49 | sys.exit(main()) |