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 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | """Parse Repo manifest and symlink files specified in <linkfile> tags. |
| 18 | |
| 19 | This is a workaround for Kokoro which does not support <linkfile>. |
| 20 | """ |
| 21 | |
| 22 | import argparse |
| 23 | import os |
| 24 | import sys |
| 25 | import xml.etree.ElementTree as ET |
| 26 | |
| 27 | def main(): |
| 28 | parser = argparse.ArgumentParser() |
| 29 | parser.add_argument("root_dir", help="root directory") |
| 30 | args = parser.parse_args() |
| 31 | |
| 32 | manifest = os.path.join(args.root_dir, ".repo", "manifest.xml") |
| 33 | tree = ET.parse(manifest) |
| 34 | root = tree.getroot() |
| 35 | assert(root.tag == "manifest"); |
| 36 | |
| 37 | for proj in root: |
| 38 | if proj.tag != "project": |
| 39 | continue |
| 40 | |
| 41 | proj_name = proj.attrib["name"] |
| 42 | proj_path = proj.attrib["path"] |
| 43 | |
| 44 | for linkfile in proj: |
| 45 | if linkfile.tag != "linkfile": |
| 46 | continue |
| 47 | |
| 48 | linkfile_src = linkfile.attrib["src"] |
| 49 | linkfile_dest = linkfile.attrib["dest"] |
| 50 | src_path = os.path.join( |
| 51 | args.root_dir, proj_path, linkfile_src) |
| 52 | dest_path = os.path.join(args.root_dir, linkfile_dest) |
| 53 | |
| 54 | os.symlink(src_path, dest_path) |
| 55 | |
| 56 | if __name__ == "__main__": |
| 57 | sys.exit(main()) |