File size: 2,160 Bytes
5cdf637
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
import os


def swap_prefix(file, old, new):
    with open(file, "r") as f:
        lines = f.read()
    lines = lines.replace(old, new)
    with open(file, "wt") as f:
        f.write(lines)


# modify ../include/ord/OpenROAD.hh
swap_prefix(
    "../include/ord/OpenRoad.hh",
    "namespace dft {\nclass Dft;\n}",
    "namespace dft {\nclass Dft;\n}\n\nnamespace tool{\nclass Tool;\n}",
)

swap_prefix(
    "../include/ord/OpenRoad.hh",
    "dft::Dft* getDft() { return dft_; }",
    "dft::Dft* getDft() { return dft_; }\n  tool::Tool* getTool() { return tool_; }",
)

swap_prefix(
    "../include/ord/OpenRoad.hh",
    "dft::Dft* dft_ = nullptr;",
    "dft::Dft* dft_ = nullptr;\n  tool::Tool* tool_ = nullptr;",
)

# modify ../src/CMakeLists.txt
swap_prefix(
    "../src/CMakeLists.txt",
    "add_subdirectory(dft)",
    "add_subdirectory(dft)\nadd_subdirectory(tool)",
)

swap_prefix("../src/CMakeLists.txt", "pdn\n  dft", "pdn\n  dft\n  tool")

# modify ../src/OpenROAD.cc
swap_prefix(
    "../src/OpenRoad.cc",
    '#include "utl/MakeLogger.h"',
    '#include "utl/MakeLogger.h"\n#include "tool/MakeTool.hh"',
)

swap_prefix(
    "../src/OpenRoad.cc",
    "dft_ = dft::makeDft();",
    "dft_ = dft::makeDft();\n  tool_ = makeTool();",
)

swap_prefix(
    "../src/OpenRoad.cc",
    "dft::deleteDft(dft_);",
    "dft::deleteDft(dft_);\n  deleteTool(tool_);",
)

swap_prefix(
    "../src/OpenRoad.cc",
    "dft::initDft(this);",
    "dft::initDft(this);\n  initTool(this);",
)

# create a patch file
os.makedirs("misc", exist_ok=True)
_ = os.popen("git add ../include/ord/OpenRoad.hh").read()
_ = os.popen("git add ../src/CMakeLists.txt").read()
_ = os.popen("git add ../src/OpenRoad.cc").read()
_ = os.popen("git diff --cached > misc/AddTool.patch").read()

# restore all changes except patch
_ = os.popen("git reset ../include/ord/OpenRoad.hh").read()
_ = os.popen("git reset ../src/CMakeLists.txt").read()
_ = os.popen("git reset ../src/OpenRoad.cc").read()
_ = os.popen("git restore ../include/ord/OpenRoad.hh").read()
_ = os.popen("git restore ../src/CMakeLists.txt").read()
_ = os.popen("git restore ../src/OpenRoad.cc").read()