Changeset 19086

Show
Ignore:
Timestamp:
07/22/06 08:21:12 (2 years ago)
Author:
allenb
Message:

- Added a smartCopy() method that is more intelligent about copying files.

The primary additions to this method are:

  • Only copy the file if it has actually changed
  • Delete the dest file if it exists and a copy is going to happen

This fixes some problems with read-only files and makes the installation process go much faster.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/trunk/build_windows.py

    r19039 r19086  
    2828 
    2929import glob 
    30 import os 
     30import os, os.path 
    3131import re 
    3232import shutil 
     
    3535import traceback 
    3636import getopt 
     37pj = os.path.join 
    3738 
    3839EXIT_STATUS_SUCCESS           = 0 
     
    829830   mkinstalldirs(os.path.join(prefix, 'share')) 
    830831 
     832def smartCopy(srcfile, dst): 
     833   """ Only copy file if it has changed, and delete it first. 
     834       Drop in replacement for shutil.copy2. 
     835       srcfile - Full path to source file to copy. 
     836       dst - Destination filename or directory. 
     837   """    
     838   if os.path.isdir(dst): 
     839      dst = os.path.join(dst, os.path.basename(srcfile)) 
     840         
     841   # Verify we need to copy and make sure to delete if needed 
     842   if os.path.isfile(dst): 
     843      stat_src = os.stat(srcfile) 
     844      stat_dst = os.stat(dst) 
     845      if (stat_src.st_size == stat_dst.st_size) and \ 
     846         (stat_src.st_mtime == stat_dst.st_mtime): 
     847         #print "skipping: ", dst 
     848         return   # File doesn't need to be copied 
     849      #print "removing: ", dst 
     850      os.remove(dst) 
     851    
     852   # Copy it 
     853   shutil.copy2(srcfile, dst) 
     854    
     855    
    831856def installDir(startDir, destDir, allowedExts = None, disallowedExts = None, 
    832857               disallowedFiles = None): 
     858   #print "   %s ==> %s"%(startDir, destDir) 
    833859   cwd = os.getcwd() 
    834860 
     
    866892                    disallowedFiles) 
    867893      else: 
    868          (root, f_ext) = os.path.splitext(f) 
    869          if allowedExts is None: 
    870             if f_ext not in disallowedExts: 
    871                shutil.copy2(f, destDir) 
    872          elif f_ext in allowedExts: 
    873             if f not in disallowedFiles: 
    874                shutil.copy2(f, destDir) 
     894         try: 
     895            (root, f_ext) = os.path.splitext(f) 
     896            if allowedExts is None: 
     897               if f_ext not in disallowedExts: 
     898                  smartCopy(f, pj(destDir,f)) 
     899            elif f_ext in allowedExts: 
     900               if f not in disallowedFiles: 
     901                  smartCopy(f, pj(destDir,f)) 
     902         except (IOError, os.error), why: 
     903            print "Can't copy %s to %s: %s" % (f, destDir, str(why)) 
    875904 
    876905   os.chdir(cwd) 
     
    915944   srcroot = os.path.join(gJugglerDir, 'modules', 'vapor') 
    916945 
    917    shutil.copy2(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
     946   smartCopy(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
    918947   extra_files = ['ChangeLog', 'README.txt', 'RELEASE_NOTES.txt'] 
    919948   for f in extra_files: 
    920       shutil.copy2(os.path.join(srcroot, f), destdir) 
     949      smartCopy(os.path.join(srcroot, f), destdir) 
    921950 
    922951def installTweek(prefix, buildDir): 
     
    946975   srcroot = os.path.join(gJugglerDir, 'modules', 'tweek') 
    947976 
    948    shutil.copy2(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
     977   smartCopy(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
    949978   extra_files = ['ChangeLog', 'RELEASE_NOTES.txt'] 
    950979   for f in extra_files: 
    951       shutil.copy2(os.path.join(srcroot, f), destdir) 
     980      smartCopy(os.path.join(srcroot, f), destdir) 
    952981 
    953982def installTweekJava(prefix, buildDir): 
     
    9771006      # Install the base JAR files that make up the Tweek Java API. 
    9781007      for j in jars: 
    979          shutil.copy2(os.path.join(srcdir, j), destdir) 
     1008         smartCopy(os.path.join(srcdir, j), destdir) 
    9801009 
    9811010      # Install the tweek_jni DLL. 
     
    9871016            destdir = os.path.join(destdir, arch) 
    9881017            mkinstalldirs(destdir) 
    989             shutil.copy2(dll, destdir) 
     1018            smartCopy(dll, destdir) 
    9901019 
    9911020      destdir = os.path.join(prefix, 'share', 'tweek', 'beans') 
     
    9991028         jar = b + '.jar' 
    10001029         xml = b + '.xml' 
    1001          shutil.copy2(os.path.join(bean_srcdir, jar), destdir) 
    1002          shutil.copy2(os.path.join(xml_srcdir, xml), destdir) 
     1030         smartCopy(os.path.join(bean_srcdir, jar), destdir) 
     1031         smartCopy(os.path.join(xml_srcdir, xml), destdir) 
    10031032 
    10041033      xml_srcdir  = os.path.join(gJugglerDir, 'modules', 'tweek', 'extensions', 
     
    10091038         jar = b + '.jar' 
    10101039         xml = b + '.xml' 
    1011          shutil.copy2(os.path.join(bean_srcdir, jar), destdir) 
    1012          shutil.copy2(os.path.join(xml_srcdir, xml), destdir) 
     1040         smartCopy(os.path.join(bean_srcdir, jar), destdir) 
     1041         smartCopy(os.path.join(xml_srcdir, xml), destdir) 
    10131042 
    10141043      # Install tweek.bat. 
    10151044      srcdir = os.path.join(gJugglerDir, 'modules', 'tweek', 'java') 
    10161045      destdir = os.path.join(prefix, 'bin') 
    1017       shutil.copy2(os.path.join(srcdir, 'tweek.bat'), destdir) 
     1046      smartCopy(os.path.join(srcdir, 'tweek.bat'), destdir) 
    10181047 
    10191048      # Install JacORB IDL compiler. 
    10201049      srcdir = os.path.join(gJugglerDir, 'external', 'JacORB') 
    10211050      installDir(srcdir, destdir, ['.jar']) 
    1022       shutil.copy2(os.path.join(srcdir, 'idl.bat'), destdir) 
     1051      smartCopy(os.path.join(srcdir, 'idl.bat'), destdir) 
    10231052 
    10241053      # Destination for all remaining .jar files. 
     
    10401069      srcroot = os.path.join(gJugglerDir, 'external', 'swing-laf') 
    10411070      for j in laf_jars: 
    1042          shutil.copy2(os.path.join(srcroot, j), destdir) 
     1071         smartCopy(os.path.join(srcroot, j), destdir) 
    10431072   else: 
    10441073      printStatus("Tweek Java API not built.  Skipping.") 
     
    10781107                          '3.0') 
    10791108   mkinstalldirs(destdir) 
    1080    shutil.copy2(os.path.join(srcdir, 'configuration.xsd'), destdir) 
     1109   smartCopy(os.path.join(srcdir, 'configuration.xsd'), destdir) 
    10811110 
    10821111   destdir = os.path.join(schema_root, 'www.vrjuggler.org', 'jccl', 'xsd', 
    10831112                          '3.1') 
    10841113   mkinstalldirs(destdir) 
    1085    shutil.copy2(os.path.join(srcdir, 'definition.xsd'), destdir) 
     1114   smartCopy(os.path.join(srcdir, 'definition.xsd'), destdir) 
    10861115 
    10871116   destdir = schema_root 
     
    10941123   srcroot = os.path.join(gJugglerDir, 'modules', 'jackal') 
    10951124 
    1096    shutil.copy2(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
     1125   smartCopy(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
    10971126   extra_files = ['ChangeLog', 'RELEASE_NOTES.txt'] 
    10981127   for f in extra_files: 
    1099       shutil.copy2(os.path.join(srcroot, f), destdir) 
     1128      smartCopy(os.path.join(srcroot, f), destdir) 
    11001129 
    11011130def installJCCLPlugins(prefix, buildDir): 
     
    11211150 
    11221151      for j in jars: 
    1123          shutil.copy2(os.path.join(srcdir, j), destdir) 
     1152         smartCopy(os.path.join(srcdir, j), destdir) 
    11241153 
    11251154      srcdir = os.path.join(gJugglerDir, 'modules', 'jackal', 'config') 
    1126       shutil.copy2(os.path.join(srcdir, 'jccl_config.xml'), destdir) 
     1155      smartCopy(os.path.join(srcdir, 'jccl_config.xml'), destdir) 
    11271156 
    11281157      # Install dependencies. 
     
    11361165      mkinstalldirs(destdir) 
    11371166      for j in dep_jars: 
    1138          shutil.copy2(os.path.join(srcroot, j), destdir) 
     1167         smartCopy(os.path.join(srcroot, j), destdir) 
    11391168   else: 
    11401169      printStatus("JCCL Java API not built.  Skipping.") 
     
    11471176 
    11481177      destdir = os.path.join(prefix, 'share', 'jccl', 'beans') 
    1149       shutil.copy2(os.path.join(srcdir, 'jccl_rtrc.jar'), destdir) 
     1178      smartCopy(os.path.join(srcdir, 'jccl_rtrc.jar'), destdir) 
    11501179 
    11511180      srcdir = os.path.join(gJugglerDir, 'modules', 'jackal', 'plugins', 
    11521181                            'corba_rtrc') 
    1153       shutil.copy2(os.path.join(srcdir, 'jccl_rtrc.xml'), destdir) 
     1182      smartCopy(os.path.join(srcdir, 'jccl_rtrc.xml'), destdir) 
    11541183   else: 
    11551184      printStatus("JCCL Java plug-ins not built.  Skipping.") 
     
    11811210   srcroot = os.path.join(gJugglerDir, 'modules', 'sonix') 
    11821211 
    1183    shutil.copy2(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
     1212   smartCopy(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
    11841213   extra_files = ['ChangeLog', 'README.txt'] 
    11851214   for f in extra_files: 
    1186       shutil.copy2(os.path.join(srcroot, f), destdir) 
     1215      smartCopy(os.path.join(srcroot, f), destdir) 
    11871216 
    11881217def installSonixPlugins(prefix, buildDir): 
     
    12421271   srcroot = os.path.join(gJugglerDir, 'modules', 'gadgeteer') 
    12431272 
    1244    shutil.copy2(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
     1273   smartCopy(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
    12451274   extra_files = ['ChangeLog', 'RELEASE_NOTES.txt'] 
    12461275   for f in extra_files: 
    1247       shutil.copy2(os.path.join(srcroot, f), destdir) 
     1276      smartCopy(os.path.join(srcroot, f), destdir) 
    12481277 
    12491278def installGadgeteerDrivers(prefix, buildDir): 
     
    13211350   srcroot = os.path.join(gJugglerDir, 'modules', 'vrjuggler') 
    13221351 
    1323    shutil.copy2(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
     1352   smartCopy(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
    13241353   extra_files = ['ChangeLog', 'RELEASE_NOTES.txt'] 
    13251354   for f in extra_files: 
    1326       shutil.copy2(os.path.join(srcroot, f), destdir) 
     1355      smartCopy(os.path.join(srcroot, f), destdir) 
    13271356 
    13281357def installVRJConfig(prefix, buildDir): 
     
    13651394         jar_file = os.path.join(jardir, j) 
    13661395         if os.path.exists(jar_file): 
    1367             shutil.copy2(jar_file, destdir) 
     1396            smartCopy(jar_file, destdir) 
    13681397 
    13691398      # Install the base set of VRJConfig JavaBeans. 
     
    13731402         jar_file = os.path.join(jardir, j) 
    13741403         if os.path.exists(jar_file): 
    1375             shutil.copy2(jar_file, destdir) 
    1376  
    1377       shutil.copy2(os.path.join(vrjconfig_src, 'VRJConfig.xml'), destdir) 
     1404            smartCopy(jar_file, destdir) 
     1405 
     1406      smartCopy(os.path.join(vrjconfig_src, 'VRJConfig.xml'), destdir) 
    13781407 
    13791408      # Install any custom editors that were compiled. 
     
    13851414         xml_file = os.path.join(custom_editor_src, e[0], e[1] + '.xml') 
    13861415         if os.path.exists(jar_file): 
    1387             shutil.copy2(xml_file, destdir) 
    1388             shutil.copy2(jar_file, destdir) 
     1416            smartCopy(xml_file, destdir) 
     1417            smartCopy(jar_file, destdir) 
    13891418 
    13901419      # Install any wizards that were compiled. 
     
    13941423         jar_file = os.path.join(jardir, e[1] + '.jar') 
    13951424         if os.path.exists(jar_file): 
    1396             shutil.copy2(jar_file, destdir) 
     1425            smartCopy(jar_file, destdir) 
    13971426 
    13981427      # Install vrjconfig.bat. 
    13991428      destdir = os.path.join(prefix, 'bin') 
    1400       shutil.copy2(os.path.join(vrjconfig_src, 'vrjconfig.bat'), destdir) 
     1429      smartCopy(os.path.join(vrjconfig_src, 'vrjconfig.bat'), destdir) 
    14011430 
    14021431      # Install dependencies. 
     
    14091438      destdir = os.path.join(prefix, 'share', 'vrjuggler', 'java') 
    14101439      for j in dep_jars: 
    1411          shutil.copy2(os.path.join(srcroot, j), destdir) 
     1440         smartCopy(os.path.join(srcroot, j), destdir) 
    14121441   else: 
    14131442      printStatus("VRJConfig not built.  Skipping.") 
     
    14331462         destdir = os.path.join(prefix, 'share', 'vrjuggler', 'beans') 
    14341463         mkinstalldirs(destdir) 
    1435          shutil.copy2(os.path.join(srcdir, name + '.jar'), destdir) 
     1464         smartCopy(os.path.join(srcdir, name + '.jar'), destdir) 
    14361465 
    14371466         srcdir = os.path.join(gJugglerDir, 'modules', 'vrjuggler', 'plugins', 
    14381467                               dir) 
    1439          shutil.copy2(os.path.join(srcdir, name + '.xml'), destdir) 
     1468         smartCopy(os.path.join(srcdir, name + '.xml'), destdir) 
    14401469      else: 
    14411470         printStatus("VR Juggler %s Java plug-ins not built.  Skipping." % name) 
     
    14591488 
    14601489      for d in dlls: 
    1461          shutil.copy2(d, destdir) 
    1462  
    1463       shutil.copy2(os.path.join(sys_dir, 'dbghelp.dll'), destdir) 
     1490         smartCopy(d, pj(destdir,d))          
     1491 
     1492      #smartCopy(d, pj(destdir,d)) 
     1493      smartCopy(os.path.join(sys_dir, 'dbghelp.dll'), destdir) 
    14641494   except KeyError, ex: 
    14651495      printStatus("WARNING: Could not install MSVC runtime DLLs") 
     
    15131543def installBoost(prefix): 
    15141544   printStatus("Installing Boost headers and libraries") 
     1545   print "Installing Boost headers and libraries" 
    15151546 
    15161547   srcroot = os.environ['BOOST_ROOT'] 
     
    15271558 
    15281559   for f in lib_list: 
    1529       shutil.copy2(f, destdir) 
     1560      #print "  ==> ", f 
     1561      smartCopy(f, destdir) 
    15301562 
    15311563def installGMTL(prefix): 
     
    15501582         dll = os.path.join(d, 'OpenAL32.dll') 
    15511583         if os.path.exists(dll): 
    1552             shutil.copy2(dll, destdir) 
     1584            smartCopy(dll, destdir) 
    15531585 
    15541586   srcdir = os.environ['ALUT_ROOT'] 
     
    15591591      alut_dll = os.path.join(srcdir, 'lib', 'alut.dll') 
    15601592      if os.path.exists(alut_dll): 
    1561          shutil.copy2(dll, destdir) 
     1593         smartCopy(dll, destdir) 
    15621594 
    15631595def installOmniORB(prefix):