AMBuild.dist
author David Anderson <dvander@alliedmods.net>
Sun Jan 27 17:34:30 2013 -0800 (2013-01-27)
changeset 261 219b49bf4a03
parent 106 8534dbfb8c1a
permissions -rw-r--r--
Add support for importing enum types and enum values (as constexprs).
     1 # vim: set ts=2 sw=2 tw=99 noet ft=python: 
     2 # 
     3 # Copyright (C) 2004-2012 David Anderson
     4 # 
     5 # This file is part of SourcePawn.
     6 # 
     7 # SourcePawn is free software: you can redistribute it and/or modify it under
     8 # the terms of the GNU General Public License as published by the Free
     9 # Software Foundation, either version 3 of the License, or (at your option)
    10 # any later version.
    11 # 
    12 # SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
    13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    15 # 
    16 # You should have received a copy of the GNU General Public License along with
    17 # SourcePawn. If not, see http://www.gnu.org/licenses/.
    18 #
    19 import os
    20 import os.path
    21 import shutil
    22 import ambuild.osutil as osutil
    23 from ambuild.command import Command
    24 
    25 job = AMBuild.AddJob('dist')
    26 
    27 # Single file copy
    28 class CopyFile(Command):
    29 	def __init__(self, filename, fromPath, toPath):
    30 		Command.__init__(self)
    31 		self.filename = filename
    32 		self.fromPath = os.path.join(fromPath, filename)
    33 		self.toPath = toPath
    34 
    35 	def shouldCopy(self):
    36 		tofile = os.path.join(self.toPath, self.filename)
    37 		if not osutil.FileExists(tofile):
    38 			return True
    39 		return osutil.IsFileNewer(self.fromPath, tofile)
    40 
    41 	def run(self, runner, job):
    42 		if not self.shouldCopy():
    43 			return
    44 		runner.PrintOut('copy {0} to {1}'.format(self.fromPath, self.toPath))
    45 		shutil.copy(self.fromPath, self.toPath)
    46 
    47 # Create a folder
    48 class CreateFolder(Command):
    49 	def __init__(self, folder):
    50 		Command.__init__(self)
    51 		self.folder = folder
    52 
    53 	def run(self, runner, job):
    54 		runner.PrintOut('mkdir {0}'.format(self.folder))
    55 		os.makedirs(self.folder)
    56 
    57 def AddCopy(job, filename, fromPath, toPath):
    58 	job.AddCommand(CopyFile(filename, fromPath, toPath))
    59 
    60 def AddFolder(job, folder):
    61 	if not os.path.exists(os.path.join(AMBuild.outputFolder, 'dist', folder)):
    62 		job.AddCommand(CreateFolder(folder))
    63 
    64 libkeima = osutil.StaticLibPrefix() + 'keima' + osutil.StaticLibSuffix()
    65 spshell = 'spshell' + osutil.ExecutableSuffix()
    66 
    67 AddFolder(job, 'include')
    68 AddFolder(job, 'lib')
    69 AddFolder(job, 'bin')
    70 
    71 AddCopy(job,
    72         'keima.h',
    73         os.path.join(AMBuild.sourceFolder, 'include'),
    74         'include')
    75 AddCopy(job,
    76         'keima_util.h',
    77         os.path.join(AMBuild.sourceFolder, 'include'),
    78         'include')
    79 AddCopy(job,
    80         libkeima,
    81         os.path.join(AMBuild.outputFolder, 'keima'),
    82         'lib')
    83 AddCopy(job,
    84         spshell,
    85         os.path.join(AMBuild.outputFolder, 'spshell'),
    86         'bin')
    87