addon-sdk/copy_source.py
author Ed Morley <emorley@mozilla.com>
Thu, 25 Apr 2013 13:41:17 +0100
changeset 129860 b49b5f42be79bf9290a0beca397e4ec7fbe054f4
parent 124016 0887088eee1a3f8303f1afa26a15074cc081e554
child 150696 7c03811dad30e02fa4f0118ff5159246c0c129ef
permissions -rw-r--r--
Bug 863091 - Make auto clobbering opt-in rather than opt-out; r=glandium To avoid surprises for devs building locally, auto clobbering is now opt-in, via the use of |mk_add_options AUTOCLOBBER=1| in the mozconfig. Our automation uses build/mozconfig.common which specifies this, so auto clobber will remain enabled for our buildbot machines.

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import os
import posixpath
import sys


def normpath(path):
    """Ensure UNIX style paths are used with GNU make on Windows.

    This can be removed once we no longer support GNU make on Windows (bug
    828317).
    """
    if os.environ.get('PYMAKE') or os.name not in ('nt', 'ce'):
        return path

    if len(path) > 2 and path[1] == ':':
        path = '/' + path[0] + path[2:]

    return posixpath.normpath(path)


if len(sys.argv) != 4:
    print >> sys.stderr, "Usage: copy_source.py " \
                         "<topsrcdir> <source directory> <target directory>"
    sys.exit(1)

topsrcdir = normpath(sys.argv[1])
source_dir = sys.argv[2]
target_dir = sys.argv[3]

print """
DEPTH     = ..
topsrcdir = %(topsrcdir)s
srcdir    = %(topsrcdir)s/addon-sdk
VPATH     = %(topsrcdir)s/addon-sdk

include $(topsrcdir)/config/config.mk
""" % {'topsrcdir': topsrcdir}

real_source = source_dir.replace('/', os.sep)
if not os.path.exists(real_source):
    print >> sys.stderr, "Error: Missing source file %s" % real_source
    sys.exit(1)
elif not os.path.isdir(real_source):
    print >> sys.stderr, "Error: Source %s is not a directory" % real_source
    sys.exit(1)
for dirpath, dirnames, filenames in os.walk(real_source):
    if not filenames:
        continue
    dirpath = dirpath.replace(os.sep, '/')
    relative = dirpath[len(source_dir):]
    varname = "COMMONJS%s" % relative.replace('/', '_')
    print "%s_FILES = \\" % varname
    for name in filenames:
        print "  %s/%s \\" % (dirpath, name)
    print "  $(NULL)"
    print "%s_DEST = %s%s" % (varname, target_dir, relative)
    print "INSTALL_TARGETS += %s\n" % varname

print "include $(topsrcdir)/config/rules.mk"