AMBuild.dist
author David Anderson <dvander@alliedmods.net>
Sat Jul 28 17:12:42 2012 -0700 (2012-07-28)
changeset 111 0a0c37ddad13
parent 106 8534dbfb8c1a
child 128 6eed87ebc5ce
permissions -rw-r--r--
Trigger build.
     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.fromPath = os.path.join(fromPath, filename)
    32 		self.toPath = toPath
    33 
    34 	def run(self, runner, job):
    35 		runner.PrintOut('copy {0} to {1}'.format(self.fromPath, self.toPath))
    36 		shutil.copy(self.fromPath, self.toPath)
    37 
    38 # Create a folder
    39 class CreateFolder(Command):
    40 	def __init__(self, folder):
    41 		Command.__init__(self)
    42 		self.folder = folder
    43 
    44 	def run(self, runner, job):
    45 		runner.PrintOut('mkdir {0}'.format(self.folder))
    46 		os.makedirs(self.folder)
    47 
    48 
    49 def ShouldCopy(filename, fromPath, toPath):
    50 	fromfile = os.path.join(fromPath, filename)
    51 	tofile = os.path.join(AMBuild.outputFolder, 'dist', toPath, filename)
    52 	if not osutil.FileExists(tofile):
    53 		return True
    54 	return osutil.IsFileNewer(fromfile, tofile)
    55 
    56 def AddCopy(job, filename, fromPath, toPath):
    57 	if not ShouldCopy(filename, fromPath, toPath):
    58 		return
    59 	job.AddCommand(CopyFile(filename, fromPath, toPath))
    60 
    61 def AddFolder(job, folder):
    62 	if not os.path.exists(os.path.join(AMBuild.outputFolder, 'dist', folder)):
    63 		job.AddCommand(CreateFolder(folder))
    64 
    65 libkeima = osutil.StaticLibPrefix() + 'keima' + osutil.StaticLibSuffix()
    66 spshell = 'spshell' + osutil.ExecutableSuffix()
    67 
    68 AddFolder(job, 'include')
    69 AddFolder(job, 'lib')
    70 AddFolder(job, 'bin')
    71 
    72 AddCopy(job,
    73         'keima.h',
    74         os.path.join(AMBuild.sourceFolder, 'include'),
    75         'include')
    76 AddCopy(job,
    77         'keima_util.h',
    78         os.path.join(AMBuild.sourceFolder, 'include'),
    79         'include')
    80 AddCopy(job,
    81         libkeima,
    82         os.path.join(AMBuild.outputFolder, 'keima'),
    83         'lib')
    84 AddCopy(job,
    85         spshell,
    86         os.path.join(AMBuild.outputFolder, 'spshell'),
    87         'bin')
    88