xref: /aosp_15_r20/external/mesa3d/src/nouveau/headers/update-from-open-gpu-doc.py (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1#!/usr/bin/env python3
2
3import argparse
4import git
5from git import Repo
6import glob
7import os
8import shutil
9import sys
10
11# where should files go
12dirs = {
13  '/classes/3d/': 'classes/',
14  '/classes/compute/': 'classes/',
15  '/classes/dma-copy/': 'classes/',
16  '/classes/host/': 'classes/',
17  '/classes/memory-to-memory-format/': 'classes/',
18  '/classes/inline-to-memory/': 'classes/',
19  '/classes/twod/': 'classes/',
20}
21branch = 'master'
22target = os.path.abspath(os.path.dirname(__file__)) + "/nvidia/"
23
24parser = argparse.ArgumentParser(description='Updates Nvidia header files from git.')
25parser.add_argument('git_path', type=str, help='Path to the open-gpu-doc repo')
26
27args = parser.parse_args()
28repo_path = os.path.abspath(args.git_path)
29
30# 1. create repo object
31try:
32    repo = Repo(repo_path)
33    assert not repo.bare
34except git.exc.NoSuchPathError:
35    print("{} doesn't point to a git repository".format(repo_path))
36    sys.exit(-1)
37
38# 2. update repo
39repo.remotes.origin.fetch()
40repo.git.checkout(branch)
41repo.git.rebase('origin/' + branch)
42
43# 3. check if all needed directories exist
44for dir in dirs.keys():
45    path = repo_path + dir
46    if not os.path.isdir(path):
47        print(dir + " does not exist in repository. Was the correct repository choosen?")
48        sys.exit(-1)
49
50# 4. copy over files
51for src, dest in dirs.items():
52    src = repo_path + src
53    dest = target + dest
54    for header in glob.glob(src + "*.h"):
55        print(header + " => " + dest)
56        shutil.copy(header, dest)
57