aboutsummaryrefslogtreecommitdiff
path: root/build-shadow-tree.py
blob: 378797f9549dec2e3f6d4a2abd69b54352ee7f56 (plain) (blame)
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
#!/usr/bin/env python

# Create a symlink build tree like the old X11 project "lndir" program.
#
# Reason for this is simple: synthesizing the Alpha RTL code takes a
# looong time, so we don't want to do it unnecessarily, but we also
# don't want to include all of the intermediate files from the
# synthesis in the source tarball.  So we symlink a shadow build tree
# off to the side, do the synthesis there.
#
# We could construct this symlink tree by hand, but that's fragile, so
# we'd probably write a script to do it anyway, so we might as well
# just use the script to build the shadow tree and have done with it.

import os

source_root = "source"
build_root  = "build"

if not os.path.isdir(build_root):
    os.mkdir(build_root)

for source_head, dirs, files in os.walk(source_root):
    build_head = build_root + source_head[len(source_root):]

    for dn in dirs:
        d = os.path.join(build_head, dn)
        if not os.path.isdir(d):
            os.mkdir(d)

    for fn in files:
        if fn == ".git":
            continue
        d = os.path.join(build_head,  fn)
        s = os.path.join(source_head, fn)
        s = os.path.abspath(s)
        s = os.path.relpath(s, build_head)
        if not os.path.islink(d):
            os.symlink(s, d)

    for extra in set(os.listdir(build_head)) - set(dirs) - set(files):
        d = os.path.join(build_head, extra)
        if os.path.islink(d):
            os.unlink(d)
        elif os.path.isdir(d) and not os.listdir(d):
            os.rmdir(d)