Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
workaround
  • Loading branch information
mpcomplete committed Jul 17, 2015
commit f9e8d0092ea105bee04200338997fb2ad9145fa1
19 changes: 7 additions & 12 deletions build/symlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,38 @@
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Make a symlink and optionally touch a file (to handle dependencies)."""


import errno
import optparse
import os.path
import shutil
import sys


def Main(argv):
parser = optparse.OptionParser()
parser.add_option('-f', '--force', action='store_true')
parser.add_option('--touch')

options, args = parser.parse_args(argv[1:])
if len(args) < 2:
parser.error('at least two arguments required.')

target = args[-1]
sources = args[:-1]
for s in sources:
t = os.path.join(target, os.path.basename(s))
if len(sources) == 1 and not os.path.isdir(target):
t = target
try:
os.symlink(s, t)
except OSError, e:
if e.errno == errno.EEXIST and options.force:
os.remove(t)
if os.path.isdir(t):
shutil.rmtree(t, ignore_errors=True)
else:
os.remove(t)
os.symlink(s, t)
else:
raise


if options.touch:
with open(options.touch, 'w') as f:
pass


if __name__ == '__main__':
sys.exit(Main(sys.argv))