Skip to content

Commit 77c6728

Browse files
authored
Add package_framework.py from the Chromium buildroot to setup Mac framework symlinks. (flutter#111)
1 parent fcb277b commit 77c6728

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2016 The Chromium Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
import argparse
6+
import errno
7+
import os
8+
import shutil
9+
import sys
10+
11+
def Main():
12+
parser = argparse.ArgumentParser(description='Create Mac Framework symlinks')
13+
parser.add_argument('--framework', action='store', type=str, required=True)
14+
parser.add_argument('--version', action='store', type=str)
15+
parser.add_argument('--contents', action='store', type=str, nargs='+')
16+
parser.add_argument('--stamp', action='store', type=str, required=True)
17+
args = parser.parse_args()
18+
19+
VERSIONS = 'Versions'
20+
CURRENT = 'Current'
21+
22+
# Ensure the Foo.framework/Versions/A/ directory exists and create the
23+
# Foo.framework/Versions/Current symlink to it.
24+
if args.version:
25+
try:
26+
os.makedirs(os.path.join(args.framework, VERSIONS, args.version), 0744)
27+
except OSError as e:
28+
if e.errno != errno.EEXIST:
29+
raise e
30+
_Relink(os.path.join(args.version),
31+
os.path.join(args.framework, VERSIONS, CURRENT))
32+
33+
# Establish the top-level symlinks in the framework bundle. The dest of
34+
# the symlinks may not exist yet.
35+
if args.contents:
36+
for item in args.contents:
37+
_Relink(os.path.join(VERSIONS, CURRENT, item),
38+
os.path.join(args.framework, item))
39+
40+
# Write out a stamp file.
41+
if args.stamp:
42+
with open(args.stamp, 'w') as f:
43+
f.write(str(args))
44+
45+
return 0
46+
47+
48+
def _Relink(dest, link):
49+
"""Creates a symlink to |dest| named |link|. If |link| already exists,
50+
it is overwritten."""
51+
try:
52+
os.remove(link)
53+
except OSError as e:
54+
if e.errno != errno.ENOENT:
55+
shutil.rmtree(link)
56+
os.symlink(dest, link)
57+
58+
59+
if __name__ == '__main__':
60+
sys.exit(Main())

0 commit comments

Comments
 (0)