Changeset 7326d96 in rtems-libbsd


Ignore:
Timestamp:
Mar 12, 2012, 12:58:24 PM (8 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.11, c1e05b9ea378b2971e3d7704779112b4bc4296da, freebsd-9.3, 4a77611a223ea883fb548679b516d326a020d447
Children:
e1da9dc
Parents:
560eccf
Message:

Add diff mode to freebsd-to-rtems.py

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • freebsd-to-rtems.py

    r560eccf r7326d96  
    4040import getopt
    4141import filecmp
     42import difflib
    4243
    4344RTEMS_DIR = "not_set"
     
    4647isForward = True
    4748isDryRun = False
     49isDiffMode = False
    4850isEarlyExit = False
    4951isOnlyMakefile = False
     
    5557  print "  -?|-h|--help     print this and exit"
    5658  print "  -d|--dry-run     run program but no modifications"
     59  print "  -D|--diff        provide diff of files between trees"
    5760  print "  -e|--early-exit  evaluate arguments, print results, and exit"
    5861  print "  -m|--makefile    just generate Makefile"
     
    6568def parseArguments():
    6669  global RTEMS_DIR, FreeBSD_DIR
    67   global isVerbose, isForward, isEarlyExit, isOnlyMakefile
     70  global isVerbose, isForward, isEarlyExit, isOnlyMakefile, isDiffMode
    6871  try:
    69     opts, args = getopt.getopt(sys.argv[1:], "?hdemRr:f:v",
     72    opts, args = getopt.getopt(sys.argv[1:], "?hdDemRr:f:v",
    7073                 ["help",
    7174                  "help",
    7275                  "dry-run"
     76                  "diff"
    7377                  "early-exit"
    7478                  "makefile"
     
    9296    elif o in ("-d", "--dry-run"):
    9397      isForward = False
     98    elif o in ("-D", "--diff"):
     99      isDiffMode = True
    94100    elif o in ("-e", "--early-exit"):
    95101      isEarlyExit = True
     
    110116print "Verbose:                " + ("no", "yes")[isVerbose]
    111117print "Dry Run:                " + ("no", "yes")[isDryRun]
     118print "Diff Mode Enabled:      " + ("no", "yes")[isDiffMode]
    112119print "Only Generate Makefile: " + ("no", "yes")[isOnlyMakefile]
    113120print "RTEMS Libbsd Directory: " + RTEMS_DIR
     
    131138# Are we generating or reverting?
    132139if isForward == True:
    133     print "Generating into", RTEMS_DIR
     140    print "Forward from FreeBSD SVN into ", RTEMS_DIR
    134141else:
    135     print "Reverting from", RTEMS_DIR
     142    print "Reverting from ", RTEMS_DIR
    136143    if isOnlyMakefile == True:
    137144        print "Only Makefile Mode and Reverse are contradictory"
     
    156163        return path.replace("include/", "include/freebsd/machine/")
    157164
    158 # compare and overwrite destination file only if different
    159 def copyIfDifferent(new, old, desc, src):
    160         global filesChanged
    161         # print new + " " + old + " X" + desc + "X "  + src
    162         if not os.path.exists(old) or \
    163            filecmp.cmp(new, old, shallow=False) == False:
    164                 filesChanged += 1
    165                 print "Install " + desc + src + " => " + dst
    166                 if isDryRun == False:
    167                         shutil.move(new, old)
    168                 # print "Move " + new + " to " + old
    169                 return True
    170         return False
     165# compare and process file only if different
     166#  + copy or diff depending on execution mode
     167def processIfDifferent(new, old, desc, src):
     168  global filesChanged
     169  # print new + " " + old + " X" + desc + "X "  + src
     170  if not os.path.exists(old) or \
     171     filecmp.cmp(new, old, shallow=False) == False:
     172    filesChanged += 1
     173    if isDiffMode == False:
     174      # print "Move " + new + " to " + old
     175      if isDryRun == False:
     176        shutil.move(new, old)
     177    else:
     178      #print "Diff " + src
     179      old_contents = open(old).readlines()
     180      new_contents = open(new).readlines()
     181      for line in difflib.unified_diff( \
     182          old_contents, new_contents, fromfile=src, tofile=new, n=5):
     183        sys.stdout.write(line)
    171184
    172185# generate an empty file as a place holder
     
    182195        out.write('/* EMPTY */\n')
    183196        out.close()
    184         copyIfDifferent(tempFile, dst, "empty file ", "" )
     197        processIfDifferent(tempFile, dst, "empty file ", "" )
    185198
    186199# fix include paths inside a C or .h file
     
    219232        out.write(data)
    220233        out.close()
    221         copyIfDifferent(tempFile, dst, "Header ", src)
     234        processIfDifferent(tempFile, dst, "Header ", src)
    222235
    223236
     
    240253        out.write(data)
    241254        out.close()
    242         copyIfDifferent(tempFile, dst, "Source ", src)
     255        processIfDifferent(tempFile, dst, "Source ", src)
    243256
    244257# Revert a header file from the RTEMS BSD tree to the FreeBSD tree
     
    261274        out.write(data)
    262275        out.close()
    263         copyIfDifferent(tempFile, dst, "Header ", src)
     276        processIfDifferent(tempFile, dst, "Header ", src)
    264277
    265278# Revert a source file from the RTEMS BSD tree to the FreeBSD tree
     
    282295        out.write(data)
    283296        out.close()
    284         copyIfDifferent(tempFile, dst, "Source ", src)
     297        processIfDifferent(tempFile, dst, "Source ", src)
    285298
    286299# Remove the output directory
     
    408421                out.close()
    409422                makefile = RTEMS_DIR + '/Makefile'
    410                 copyIfDifferent(tempFile, makefile, "Makefile ", "")
     423                processIfDifferent(tempFile, makefile, "Makefile ", "")
    411424
    412425# Module - logical group of related files we can perform actions on
     
    18581871# Perform the actual file manipulation
    18591872if isForward == True:
    1860     if isOnlyMakefile == False:
    1861         mm.copyFiles()
    1862     mm.createMakefile()
     1873  if isOnlyMakefile == False:
     1874    mm.copyFiles()
     1875  mm.createMakefile()
    18631876else:
    1864     mm.revertFiles()
    1865 
    1866 if filesChanged == 1:
     1877  mm.revertFiles()
     1878
     1879# Print a summary if changing files
     1880if isDiffMode == False:
     1881  if filesChanged == 1:
    18671882    print str(filesChanged) + " file was changed."
    1868 else:
     1883  else:
    18691884    print str(filesChanged) + " files were changed."
  • libbsd.txt

    r560eccf r7326d96  
    208208  -?|-h|--help     print this and exit
    209209  -d|--dry-run     run program but no modifications
     210  -D|--diff        provide diff of files between trees
    210211  -e|--early-exit  evaluate arguments, print results, and exit
    211212  -m|--makefile    just generate Makefile
     
    249250----
    250251
     252The script may also be used to generate a diff in either forward or reverse
     253direction.
     254
    251255== Initialization of RTEMS Libbsd
    252256
Note: See TracChangeset for help on using the changeset viewer.