예제 #1
0
def rmvolsnap(volsnapname, which):
    """Remove an existing btrfs snapshot or subvolume."""

    # Determine /ssd root
    ssdroot = u.determine_btrfs_ssdroot(os.getcwd())
    u.verbose(1, "ssdroot=%s" % ssdroot)

    # Normalize snap name
    volsnapname = normalize(ssdroot, volsnapname)

    # Check for existence
    oldvolsnap = "%s/%s" % (ssdroot, volsnapname)
    if not os.path.exists(oldvolsnap):
        u.error("unable to locate existing %s %s" % (which, oldvolsnap))

    # Determine whether there is a parent uuid
    isvol = -1
    showlines = u.docmdlines("sudo btrfs subvolume show %s" % oldvolsnap)
    if not showlines:
        u.error("unable to get subvolume info for %s" % oldvolsnap)
    matcher = re.compile(r"^\s*Parent uuid\:\s+(\S+).*$")
    for line in showlines:
        m = matcher.match(line)
        if m:
            puid = m.group(1)
            if puid == "-":
                isvol = 1
            else:
                isvol = 0

    u.verbose(2, "isvol=%d for %s" % (isvol, oldvolsnap))

    if isvol == -1:
        u.warning("unable to determine snapshot/subvolume status for %s" %
                  oldvolsnap)
    elif isvol == 0:
        if which == "volume":
            u.warning("%s appears to be snapshot, not subvolume" % oldvolsnap)
    else:
        if which == "snapshot":
            u.warning("%s appears to be subvolume, not snapshot" % oldvolsnap)

    # Here goes
    rc = u.docmdnf("sudo btrfs subvolume delete %s" % oldvolsnap)
    if rc != 0:
        # Couldn't delete the subvolume. Suggest running lsof
        sys.stderr.write(
            "** deletion failed -- trying to determine open file:\n")
        sys.stderr.write("  lsof +D %s\n" % oldvolsnap)
        u.docmdnf("lsof +D %s\n" % oldvolsnap)
        exit(1)

    sys.stderr.write("... %s %s deleted\n" % (which, oldvolsnap))
예제 #2
0
def rmvolsnap(volsnapname, which):
  """Remove an existing btrfs snapshot or subvolume."""

  # Determine /ssd root
  ssdroot = u.determine_btrfs_ssdroot(os.getcwd())
  u.verbose(1, "ssdroot=%s" % ssdroot)

  # Normalize snap name
  volsnapname = normalize(ssdroot, volsnapname)

  # Check for existence
  oldvolsnap = "%s/%s" % (ssdroot, volsnapname)
  if not os.path.exists(oldvolsnap):
    u.error("unable to locate existing %s %s" % (which, oldvolsnap))

  # Determine whether there is a parent uuid
  isvol = -1
  showlines = u.docmdlines("sudo btrfs subvolume show %s" % oldvolsnap)
  if not showlines:
    u.error("unable to get subvolume info for %s" % oldvolsnap)
  matcher = re.compile(r"^\s*Parent uuid\:\s+(\S+).*$")
  for line in showlines:
    m = matcher.match(line)
    if m:
      puid = m.group(1)
      if puid == "-":
        isvol = 1
      else:
        isvol = 0

  u.verbose(2, "isvol=%d for %s" % (isvol, oldvolsnap))

  if isvol == -1:
    u.warning("unable to determine snapshot/subvolume status for %s" %
              oldvolsnap)
  elif isvol == 0:
    if which == "volume":
      u.warning("%s appears to be snapshot, not subvolume" % oldvolsnap)
  else:
    if which == "snapshot":
      u.warning("%s appears to be subvolume, not snapshot" % oldvolsnap)

  # Here goes
  rc = u.docmdnf("sudo btrfs subvolume delete %s" % oldvolsnap)
  if rc != 0:
    # Couldn't delete the subvolume. Suggest running lsof
    sys.stderr.write("** deletion failed -- trying to determine open file:\n")
    sys.stderr.write("  lsof +D %s\n"% oldvolsnap)
    u.docmdnf("lsof +D %s\n" % oldvolsnap)
    exit(1)

  sys.stderr.write("... %s %s deleted\n" % (which, oldvolsnap))
예제 #3
0
def examine(afile):
    """Dump go exports for specified file."""

    objfile = afile
    arcmd = "ar t %s" % afile

    # Run 'ar' command, suppressing error output. If
    # if succeeds, then continue on the ar path, otherwise
    # treat input as an object.
    if u.doscmd(arcmd, True, True):
        # Handle archives
        lines = u.docmdlines(arcmd, True)
        if not lines:
            u.warning("skipping %s, can't index archive %s", afile)
            return
        # Extract elem from archive
        elem = lines[0].strip()
        u.verbose(1, "%s contains %s" % (afile, elem))
        rc = u.docmdnf("ar x %s %s" % (afile, elem))
        if rc:
            u.warning("skipping %s, can't extract object" % afile)
            return
        objfile = elem

    gexptemp = tempfile.NamedTemporaryFile(mode="w",
                                           prefix="go_export",
                                           delete=True)

    # Handle objects
    cmd = ("objcopy -O binary --only-section=.go_export "
           "--set-section-flags .go_export=alloc %s "
           "%s" % (objfile, gexptemp.name))
    rc = u.docmdnf(cmd)
    if rc:
        u.warning("skipping %s, can't extract export "
                  "data (cmd failed: %s)" % (objfile, cmd))
        return
    try:
        inf = open(gexptemp.name, "rb")
    except IOError as e:
        u.error("unable to open tempfile %s: "
                "%s" % (gexptemp.name, e.strerror))
    print "== %s ==" % afile
    lines = inf.readlines()
    if not lines:
        u.warning("skipping %s, no .go_export section present" % objfile)
    for line in lines:
        print line.strip()
    inf.close()
    if objfile != afile:
        os.unlink(objfile)
def examine(afile):
  """Dump go exports for specified file."""

  objfile = afile
  arcmd = "ar t %s" % afile

  # Run 'ar' command, suppressing error output. If
  # if succeeds, then continue on the ar path, otherwise
  # treat input as an object.
  if u.doscmd(arcmd, True, True):
    # Handle archives
    lines = u.docmdlines(arcmd, True)
    if not lines:
      u.warning("skipping %s, can't index archive %s", afile)
      return
    # Extract elem from archive
    elem = lines[0].strip()
    u.verbose(1, "%s contains %s" % (afile, elem))
    rc = u.docmdnf("ar x %s %s" % (afile, elem))
    if rc:
      u.warning("skipping %s, can't extract object" % afile)
      return
    objfile = elem

  gexptemp = tempfile.NamedTemporaryFile(mode="w",
                                         prefix="go_export",
                                         delete=True)

  # Handle objects
  cmd = ("objcopy -O binary --only-section=.go_export "
         "--set-section-flags .go_export=alloc %s "
         "%s" % (objfile, gexptemp.name))
  rc = u.docmdnf(cmd)
  if rc:
    u.warning("skipping %s, can't extract export "
              "data (cmd failed: %s)" % (objfile, cmd))
    return
  try:
    inf = open(gexptemp.name, "rb")
  except IOError as e:
    u.error("unable to open tempfile %s: "
            "%s" % (gexptemp.name, e.strerror))
  print "== %s ==" % afile
  lines = inf.readlines()
  if not lines:
    u.warning("skipping %s, no .go_export section present" % objfile)
  for line in lines:
    print line.strip()
  inf.close()
  if objfile != afile:
    os.unlink(objfile)
예제 #5
0
def docmdnf(cmd):
    """Execute a command allowing for failure."""
    if flag_echo:
        sys.stderr.write("executing: " + cmd + "\n")
    if flag_dryrun:
        return 0
    return u.docmdnf(cmd)
def capture_env_from_cmds(cmds, cachefile, errfile):
  """Capture the environment resulting from executing bash cmds."""
  # Emit small bash script to execute
  cmdfile = ".bashcmd"
  with open(cmdfile, "w") as wf:
    first = True
    for c in cmds:
      if first:
        first = False
        wf.write("%s 1> %s 2>&1\n" % (c, errfile))
      else:
        wf.write("%s 1>> %s 2>&1\n" % (c, errfile))
      wf.write("if [ $? != 0 ]; then\n")
      wf.write("  exit 1\n")
      wf.write("fi\n")
    wf.write("printenv > %s\n" % cachefile)
    wf.write("exit 0\n")
    wf.close()
    rc = u.docmdnf("bash %s" % cmdfile)
    if rc != 0:
      u.warning("bash cmd failed")
      u.warning("cmd script was:")
      u.docmd("cat %s" % cmdfile)
      u.warning("bash error output was:")
      u.docmd("cat %s" % errfile)
      raise Exception("command failed")
예제 #7
0
def docmdnf(cmd):
  """Execute a command allowing for failure."""
  if flag_echo:
    sys.stderr.write("executing: " + cmd + "\n")
  if flag_dryrun:
    return 0
  return u.docmdnf(cmd)
예제 #8
0
def collectem():
  """Locate and upload tombstones."""

  # Need root access to get at /data/tombstones
  u.doscmd("adb root")

  # See what's available
  lines = u.docmdlines("adb shell ls -l /data/tombstones")

  # Things we found
  fnames = []

  # -rw------- system   system      56656 2015-05-25 03:01 tombstone_09
  matcher = re.compile(r"^\S+\s+\S+\s+\S+\s+\d+\s+(\S+)\s+(\S+)\s+(tomb\S+)\s*$")
  for line in lines:
    u.verbose(3, "line is: %s" % line)
    m = matcher.match(line)
    if m:
      datestr = m.group(1)
      timestr = m.group(2)
      fname = m.group(3)
      fnames.append(fname)
      u.verbose(1, ("found tombstone %s date %s time %s" %
                    (fname, datestr, timestr)))
      u.docmd("mkdir -p /tmp/tombstones/%s" % whichdev)
      newname = ("/tmp/tombstones/%s/%s_%s_%s" %
                 (whichdev, fname, datestr, timestr))
      u.docmd("adb pull /data/tombstones/%s %s_tmp" % (fname, newname))
      if os.path.exists(newname):
        # already there?
        rc = u.docmdnf("cmp -s %s %s_tmp" % (newname, newname))
        if rc == 0:
          print "file %s already uploaded, skipping..." % fname
        else:
          print "overwriting existing %s with new version" % fname
      else:
        u.docmdnf("mv %s_tmp %s" % (newname, newname))
        print "uploaded new tombstone to %s" % newname

  # Anything there?
  if not fnames:
    print "No tombstones found... terminating."
def setup():
  """Perform assorted setups prior to main part of run."""
  global abt, apo, whichdev, cpu_arch, dxpath

  # Check to make sure we can run adb, etc
  u.doscmd("which adb")
  rc = u.docmdnf("which dx")
  if rc != 0:
    u.doscmd("which prebuilts/sdk/tools/dx")
    dxpath = "prebuilts/sdk/tools/dx"
  u.doscmd("which javac")

  # Collect device flavor
  lines = u.docmdlines("whichdevice.sh")
  if len(lines) != 1:
    u.error("unexpected output from whichdevice.sh")
  whichdev = lines[0].strip()
  u.verbose(1, "device: %s" % whichdev)

  bitness = 32
  cpu_tup_idx = 0
  if flag_64bit:
    bitness = 64
    cpu_tup_idx = 1

  # Figure out what architecture we're working with,
  # and make sure it supports the requested mode (32 or 64 bit)
  output = u.docmdlines("adb shell uname -m")
  tag = output[0].strip()
  if tag not in uname_to_cpu_arch:
    u.error("internal error: unsupported output %s from "
            "from uname -m -- please update script" % tag)
  tup = uname_to_cpu_arch[tag]
  cpu_arch = tup[cpu_tup_idx]
  if not cpu_arch:
    u.error("%d-bit support not available on "
            "this arch (uname -m: %s)" % (bitness, tag))

  # Did we run lunch?
  abt = os.getenv("ANDROID_BUILD_TOP")
  if abt is None:
    u.error("ANDROID_BUILD_TOP not set (did you run lunch?)")
  apo = os.getenv("ANDROID_PRODUCT_OUT")
  if apo is None:
    u.error("ANDROID_PRODUCT_OUT not set (did you run lunch?)")
  u.verbose(1, "ANDROID_PRODUCT_OUT: %s" % apo)
예제 #10
0
def setup():
    """Perform assorted setups prior to main part of run."""
    global abt, apo, whichdev, cpu_arch, dxpath

    # Check to make sure we can run adb, etc
    u.doscmd("which adb")
    rc = u.docmdnf("which dx")
    if rc != 0:
        u.doscmd("which prebuilts/sdk/tools/dx")
        dxpath = "prebuilts/sdk/tools/dx"
    u.doscmd("which javac")

    # Collect device flavor
    lines = u.docmdlines("whichdevice.sh")
    if len(lines) != 1:
        u.error("unexpected output from whichdevice.sh")
    whichdev = lines[0].strip()
    u.verbose(1, "device: %s" % whichdev)

    bitness = 32
    cpu_tup_idx = 0
    if flag_64bit:
        bitness = 64
        cpu_tup_idx = 1

    # Figure out what architecture we're working with,
    # and make sure it supports the requested mode (32 or 64 bit)
    output = u.docmdlines("adb shell uname -m")
    tag = output[0].strip()
    if tag not in uname_to_cpu_arch:
        u.error("internal error: unsupported output %s from "
                "from uname -m -- please update script" % tag)
    tup = uname_to_cpu_arch[tag]
    cpu_arch = tup[cpu_tup_idx]
    if not cpu_arch:
        u.error("%d-bit support not available on "
                "this arch (uname -m: %s)" % (bitness, tag))

    # Did we run lunch?
    abt = os.getenv("ANDROID_BUILD_TOP")
    if abt is None:
        u.error("ANDROID_BUILD_TOP not set (did you run lunch?)")
    apo = os.getenv("ANDROID_PRODUCT_OUT")
    if apo is None:
        u.error("ANDROID_PRODUCT_OUT not set (did you run lunch?)")
    u.verbose(1, "ANDROID_PRODUCT_OUT: %s" % apo)
def perform(repo, flags):
    """Patch specified repo."""
    u.verbose(1, "repo: %s flags: '%s'" % (repo, flags))
    rc = u.docmdnf("grep -q gccgoflags %s/src/cmd/dist/buildtool.go" % repo)
    if rc == 0:
        u.verbose(1, "src/cmd/dist/buildtool.go already patched")
        return
    # Remove any version file if it exists.
    vfile = os.path.join(repo, "VERSION")
    if os.path.exists(vfile):
        os.unlink(vfile)
    # Mangle build flags.
    regex = re.compile(r"^.+gcflags=.+$")
    oldf = "%s/src/cmd/dist/buildtool.go" % repo
    newf = "%s/src/cmd/dist/buildtool.go.patched" % repo
    try:
        with open(newf, "w") as wf:
            try:
                with open(oldf, "r") as rf:
                    lines = rf.readlines()
                    for line in lines:
                        if regex.match(line):
                            comps = line.split()
                            newcomps = []
                            for c in comps:
                                if c == "\"-gcflags=-l\",":
                                    u.verbose(0, "patching gcflags line\n")
                                    newcomps.append("\"-gccgoflags=%s\", " %
                                                    flags)
                                    newcomps.append("\"-p=8\", ")
                                    if flag_addmx:
                                        newcomps.append("\"-x\", ")
                                newcomps.append(c)
                            line = " ".join(newcomps)
                            line += "\n"
                        wf.write(line)
            except IOError:
                u.verbose(0, "open failed for %s" % oldf)
    except IOError:
        u.verbose(0, "open failed for %s" % newf)
    u.verbose(1, "mv %s %s" % (newf, oldf))
    u.docmd("mv %s %s" % (newf, oldf))
def perform(repo, flags):
  """Patch specified repo."""
  u.verbose(1, "repo: %s flags: '%s'" % (repo, flags))
  rc = u.docmdnf("grep -q gccgoflags %s/src/cmd/dist/buildtool.go" % repo)
  if rc == 0:
    u.verbose(1, "src/cmd/dist/buildtool.go already patched")
    return
  # Remove any version file if it exists.
  vfile = os.path.join(repo, "VERSION")
  if os.path.exists(vfile):
    os.unlink(vfile)
  # Mangle build flags.
  regex = re.compile(r"^.+gcflags=.+$")
  oldf = "%s/src/cmd/dist/buildtool.go" % repo
  newf = "%s/src/cmd/dist/buildtool.go.patched" % repo
  try:
    with open(newf, "w") as wf:
      try:
        with open(oldf, "r") as rf:
          lines = rf.readlines()
          for line in lines:
            if regex.match(line):
              comps = line.split()
              newcomps = []
              for c in comps:
                if c == "\"-gcflags=-l\",":
                  u.verbose(0, "patching gcflags line\n")
                  newcomps.append("\"-gccgoflags=%s\", " % flags)
                  newcomps.append("\"-p=8\", ")
                  if flag_addmx:
                    newcomps.append("\"-x\", ")
                newcomps.append(c)
              line = " ".join(newcomps)
              line += "\n"
            wf.write(line)
      except IOError:
        u.verbose(0, "open failed for %s" % oldf)
  except IOError:
    u.verbose(0, "open failed for %s" % newf)
  u.verbose(1, "mv %s %s" % (newf, oldf))
  u.docmd("mv %s %s" % (newf, oldf))
예제 #13
0
def perform():
    """Main driver routine."""

    u.verbose(1, "argv: %s" % " ".join(sys.argv))

    # llvm-goparse should be available somewhere in PATH, error if not
    lines = u.docmdlines("which llvm-goparse", True)
    if not lines:
        u.error("no 'llvm-goparse' in PATH -- can't proceed")

    # Perform a walk of the command line arguments looking for Go files.
    reg = re.compile(r"^\S+\.go$")
    foundgo = False
    for clarg in sys.argv[1:]:
        m = reg.match(clarg)
        if m:
            foundgo = True
            break

    if not foundgo or flag_nollvm:
        # No go files. Invoke real gccgo.
        bd = os.path.dirname(sys.argv[0])
        driver = "%s/gccgo.real" % bd
        u.verbose(1, "driver path is %s" % driver)
        args = [sys.argv[0]] + sys.argv[1:]
        u.verbose(1, "args: '%s'" % " ".join(args))
        if not os.path.exists(driver):
            u.warning("internal error: %s does not exist" % driver)
            u.warning("[most likely this script was not installed correctly]")
            usage()
        os.execv(driver, args)
        u.error("exec failed: %s" % driver)

    # Create a set of massaged args.
    nargs = []
    skipc = 0
    outfile = None
    asmfile = None
    for ii in range(1, len(sys.argv)):
        clarg = sys.argv[ii]
        if skipc != 0:
            skipc -= 1
            continue
        if clarg == "-o":
            skipc = 1
            outfile = sys.argv[ii + 1]
            asmfile = "%s.s" % outfile
            nargs.append("-o")
            nargs.append(asmfile)
            continue
        nargs.append(clarg)

    if not asmfile or not outfile:
        u.error("fatal error: unable to find -o "
                "option in clargs: %s" % " ".join(sys.argv))
    golibargs = form_golibargs(sys.argv[0])
    nargs += golibargs
    u.verbose(1, "revised args: %s" % " ".join(nargs))

    # Invoke gollvm.
    driver = "llvm-goparse"
    u.verbose(1, "driver path is %s" % driver)
    nargs = ["llvm-goparse"] + nargs
    if flag_trace_llinvoc:
        u.verbose(0, "+ %s" % " ".join(nargs))
    rc = subprocess.call(nargs)
    if rc != 0:
        u.verbose(1, "return code %d from %s" % (rc, " ".join(nargs)))
        return 1

    # Invoke the assembler
    ascmd = "as %s -o %s" % (asmfile, outfile)
    u.verbose(1, "asm command is: %s" % ascmd)
    rc = u.docmdnf(ascmd)
    if rc != 0:
        u.verbose(1, "return code %d from %s" % (rc, ascmd))
        return 1

    return 0
예제 #14
0
def perform():
  """Main driver routine."""

  u.verbose(1, "argv: %s" % " ".join(sys.argv))

  # llvm-goparse should be available somewhere in PATH, error if not
  lines = u.docmdlines("which llvm-goparse", True)
  if not lines:
    u.error("no 'llvm-goparse' in PATH -- can't proceed")

  # Perform a walk of the command line arguments looking for Go files.
  reg = re.compile(r"^\S+\.go$")
  foundgo = False
  for clarg in sys.argv[1:]:
    m = reg.match(clarg)
    if m:
      foundgo = True
      break

  if not foundgo or flag_nollvm:
    # No go files. Invoke real gccgo.
    bd = os.path.dirname(sys.argv[0])
    driver = "%s/gccgo.real" % bd
    u.verbose(1, "driver path is %s" % driver)
    args = [sys.argv[0]] + sys.argv[1:]
    u.verbose(1, "args: '%s'" % " ".join(args))
    if not os.path.exists(driver):
      u.warning("internal error: %s does not exist" % driver)
      u.warning("[most likely this script was not installed correctly]")
      usage()
    os.execv(driver, args)
    u.error("exec failed: %s" % driver)

  # Create a set of massaged args.
  nargs = []
  skipc = 0
  outfile = None
  asmfile = None
  for ii in range(1, len(sys.argv)):
    clarg = sys.argv[ii]
    if skipc != 0:
      skipc -= 1
      continue
    if clarg == "-o":
      skipc = 1
      outfile = sys.argv[ii+1]
      asmfile = "%s.s" % outfile
      nargs.append("-o")
      nargs.append(asmfile)
      continue
    nargs.append(clarg)

  if not asmfile or not outfile:
    u.error("fatal error: unable to find -o "
            "option in clargs: %s" % " ".join(sys.argv))
  golibargs = form_golibargs(sys.argv[0])
  nargs += golibargs
  u.verbose(1, "revised args: %s" % " ".join(nargs))

  # Invoke gollvm.
  driver = "llvm-goparse"
  u.verbose(1, "driver path is %s" % driver)
  nargs = ["llvm-goparse"] + nargs
  if flag_trace_llinvoc:
    u.verbose(0, "+ %s" % " ".join(nargs))
  rc = subprocess.call(nargs)
  if rc != 0:
    u.verbose(1, "return code %d from %s" % (rc, " ".join(nargs)))
    return 1

  # Invoke the assembler
  ascmd = "as %s -o %s" % (asmfile, outfile)
  u.verbose(1, "asm command is: %s" % ascmd)
  rc = u.docmdnf(ascmd)
  if rc != 0:
    u.verbose(1, "return code %d from %s" % (rc, ascmd))
    return 1

  return 0
예제 #15
0
def collect_modfiles():
    """Collect modified files."""
    if flag_oldsha:
        stcmd = ("git diff --name-status "
                 "%s..%s" % (flag_oldsha, flag_newsha))
    elif flag_branch_to_diff:
        # Check if any diffs
        mb = "master %s" % flag_branch_to_diff
        rc = u.docmdnf("git diff --quiet %s" % mb)
        if rc == 0:
            u.error("unable to proceed -- no diffs "
                    "between branches %s" % mb)
        stcmd = ("git diff --name-status %s" % mb)
    else:
        stcmd = "git status -s"
    u.verbose(1, "modfiles git cmd: %s" % stcmd)
    lines = u.docmdlines(stcmd)
    rs = re.compile(r"^\s*$")
    rb = re.compile(r"^\S+\.~\d+~$")
    r1 = re.compile(r"^(\S+)\s+(\S+)$")
    r2 = re.compile(r"^(\S+)\s+(\S+) \-\> (\S+)$")
    for line in lines:
        u.verbose(2, "git status line: +%s+" % line.strip())
        ms = rs.match(line)
        if ms:
            continue
        m1 = r1.match(line)
        if m1:
            op = m1.group(1)
            modfile = m1.group(2)
            if op == "AM" or op == "MM" or op == "??":
                if rb.match(modfile):
                    continue
                u.error("found modified or untracked "
                        "file %s -- please run git add ." % modfile)
            if op != "A" and op != "M" and op != "D":
                u.error("internal error: bad op %s in git "
                        "status line %s" % (op, line.strip()))
            if modfile in modifications:
                u.error("internal error: mod file %s "
                        "already in table" % modfile)
            modifications[modfile] = op
            continue
        m2 = r2.match(line)
        if m2:
            op = m2.group(1)
            oldfile = m2.group(2)
            newfile = m2.group(3)
            if op == "RM":
                u.error("found modified file %s -- please run git add ." %
                        newfile)
            if oldfile in modifications:
                u.error("internal error: src rename %s "
                        "already in modifications table" % oldfile)
            if oldfile in renames:
                u.error("internal error: src rename %s "
                        "already in modifications table" % oldfile)
            if op == "R":
                renames[oldfile] = newfile
                rev_renames[newfile] = oldfile
                if newfile in modifications:
                    u.error("internal error: dest of rename %s "
                            "already in modifications table" % newfile)
                renames[oldfile] = newfile
                rev_renames[newfile] = oldfile
                modifications[newfile] = "M"
            else:
                u.error("internal error: unknown op %s "
                        "in git status line %s" % (op, line))
            continue
        u.error("internal error: pattern match failed "
                "for git status line %s" % line)
예제 #16
0
파일: mmm.py 프로젝트: tuket/devel-scripts
  if flag_dryrun:
    u.verbose(0, "setting os.environ[\"ONE_"
              "SHOT_MAKEFILE\"] to %s" % mkfile)

if not flag_dryrun:
  rc = u.doscmd("which jack-admin", nf=True)
  if rc == 0:
    flag_use_jack = True
    u.doscmd("jack-admin start-server")

here = os.getcwd()
am = "all_modules"
if flag_toplevel:
  am = ""
  if flag_extra_make_args:
    am = " %s" % " ".join(flag_extra_make_args)
  if flag_checkbuild:
    am += " checkbuild"
elif flag_dependencies:
  am = "MODULES-IN-%s" % re.sub("/", "-", flag_subdir)
cmd = ("%smake %s -j%d -C %s -f build/core/main.mk "
       "%s%s" % (flag_strace, flag_dashk, flag_parfactor, here, am, flag_showcommands))
u.verbose(0, "cmd is: %s" % cmd)
rc = 0
if not flag_dryrun:
  rc = u.docmdnf(cmd)
if not flag_dryrun and flag_use_jack:
  u.doscmd("jack-admin stop-server")
if rc != 0:
  u.error("** build failed, command was: %s" % cmd)
예제 #17
0

# Setup
u.setdeflanglocale()
parse_args()
here = os.getcwd()
for link in flag_infiles:
  targ = os.readlink(link)
  os.chdir(here)
  dn = os.path.dirname(link)
  bn = os.path.basename(link)
  if dn:
    u.verbose(1, "changing to dir %s" % dn)
    os.chdir(dn)
  if os.path.isdir(targ):
    u.warning("target of link %s is a directory, skipping" % link)
    continue
  u.verbose(1, "copying %s to %s" % (targ, link))
  try:
    os.rename(bn, "%s.todel" % bn)
  except OSError as ose:
    u.warning("unable to process '%s' -- %s" % (link, ose))
    continue
  nf = u.docmdnf("cp %s %s" % (targ, bn))
  if nf != 0:
    u.warning("copy failed, link reverted")
    os.rename("%s.todel" % bn, bn)
    continue
  u.verbose(1, "removing intermediate %s.todel" % bn)
  os.unlink("%s.todel" % bn)
 def test_docmdnf_pass(self):
   rc = u.docmdnf("/bin/true")
   self.assertTrue(rc == 0)
 def test_docmdnf_fail(self):
   rc = u.docmdnf("/bin/false")
   self.assertTrue(rc != 0)
예제 #20
0
 def test_docmdnf_pass(self):
     rc = u.docmdnf("/bin/true")
     self.assertTrue(rc == 0)
예제 #21
0
 def test_docmdnf_fail(self):
     rc = u.docmdnf("/bin/false")
     self.assertTrue(rc != 0)
예제 #22
0
def collect_modfiles():
  """Collect modified files."""
  if flag_oldsha:
    stcmd = ("git diff --name-status "
             "%s..%s" % (flag_oldsha, flag_newsha))
  elif flag_branch_to_diff:
    # Check if any diffs
    mb = "master %s" % flag_branch_to_diff
    rc = u.docmdnf("git diff --quiet %s" % mb)
    if rc == 0:
      u.error("unable to proceed -- no diffs "
              "between branches %s" % mb)
    stcmd = ("git diff --name-status %s" % mb)
  else:
    stcmd = "git status -s"
  u.verbose(1, "modfiles git cmd: %s" % stcmd)
  lines = u.docmdlines(stcmd)
  rs = re.compile(r"^\s*$")
  rb = re.compile(r"^\S+\.~\d+~$")
  r1 = re.compile(r"^(\S+)\s+(\S+)$")
  r2 = re.compile(r"^(\S+)\s+(\S+) \-\> (\S+)$")
  for line in lines:
    u.verbose(2, "git status line: +%s+" % line.strip())
    ms = rs.match(line)
    if ms:
      continue
    m1 = r1.match(line)
    if m1:
      op = m1.group(1)
      modfile = m1.group(2)
      if op == "AM" or op == "MM" or op == "??":
        if rb.match(modfile):
          continue
        u.error("found modified or untracked "
                "file %s -- please run git add ." % modfile)
      if op != "A" and op != "M" and op != "D":
        u.error("internal error: bad op %s in git "
                "status line %s" % (op, line.strip()))
      if modfile in modifications:
        u.error("internal error: mod file %s "
                "already in table" % modfile)
      modifications[modfile] = op
      continue
    m2 = r2.match(line)
    if m2:
      op = m2.group(1)
      oldfile = m2.group(2)
      newfile = m2.group(3)
      if op == "RM":
        u.error("found modified file %s -- please run git add ." % newfile)
      if oldfile in modifications:
        u.error("internal error: src rename %s "
                "already in modifications table" % oldfile)
      if oldfile in renames:
        u.error("internal error: src rename %s "
                "already in modifications table" % oldfile)
      if op == "R":
        renames[oldfile] = newfile
        rev_renames[newfile] = oldfile
        if newfile in modifications:
          u.error("internal error: dest of rename %s "
                  "already in modifications table" % newfile)
        renames[oldfile] = newfile
        rev_renames[newfile] = oldfile
        modifications[newfile] = "M"
      else:
        u.error("internal error: unknown op %s "
                "in git status line %s" % (op, line))
      continue
    u.error("internal error: pattern match failed "
            "for git status line %s" % line)
예제 #23
0

# Setup
u.setdeflanglocale()
parse_args()
here = os.getcwd()
for link in flag_infiles:
    targ = os.readlink(link)
    os.chdir(here)
    dn = os.path.dirname(link)
    bn = os.path.basename(link)
    if dn:
        u.verbose(1, "changing to dir %s" % dn)
        os.chdir(dn)
    if os.path.isdir(targ):
        u.warning("target of link %s is a directory, skipping" % link)
        continue
    u.verbose(1, "copying %s to %s" % (targ, link))
    try:
        os.rename(bn, "%s.todel" % bn)
    except OSError as ose:
        u.warning("unable to process '%s' -- %s" % (link, ose))
        continue
    nf = u.docmdnf("cp %s %s" % (targ, bn))
    if nf != 0:
        u.warning("copy failed, link reverted")
        os.rename("%s.todel" % bn, bn)
        continue
    u.verbose(1, "removing intermediate %s.todel" % bn)
    os.unlink("%s.todel" % bn)
예제 #24
0
def perform():
    """Main driver routine."""
    global flag_trace_llinvoc

    u.verbose(1, "argv: %s" % " ".join(sys.argv))

    # llvm-goc should be available somewhere in PATH, error if not
    lines = u.docmdlines("which llvm-goc", True)
    if not lines:
        u.error("no 'llvm-goc' in PATH -- can't proceed")

    # Bypass the whole mess if -A
    if flag_alwaysllvm:
        a = sys.argv
        a[0] = "llvm-goc"
        driver = "llvm-goc"
        rc = subprocess.call(a)
        if rc != 0:
            u.verbose(1, "return code %d from %s" % (rc, " ".join(a)))
            return 1
        return 0

    # Perform a walk of the command line arguments looking for Go files.
    reg = re.compile(r"^(\S+)\.go$")
    gofile = None
    basename = None
    for clarg in sys.argv[1:]:
        m = reg.match(clarg)
        if m:
            gofile = clarg
            basename = m.group(1)
            break

    if not gofile or flag_nollvm:
        # No go files. Invoke real gccgo.
        bd = os.path.dirname(sys.argv[0])
        driver = "%s/gccgo.real" % bd
        u.verbose(1, "driver path is %s" % driver)
        args = [sys.argv[0]] + sys.argv[1:]
        u.verbose(1, "args: '%s'" % " ".join(args))
        if not os.path.exists(driver):
            usage("internal error: %s does not exist [most likely this "
                  "script was not installed correctly]" % driver)
        os.execv(driver, args)
        u.error("exec failed: %s" % driver)

    # Create a set of massaged args.
    nargs = []
    skipc = 0
    outfile = None
    linkoutfile = None
    minus_s = False
    minus_v = False
    minus_c = False
    ofiles = []
    ldflags = []
    largsSeen = False
    for ii in range(1, len(sys.argv)):
        clarg = sys.argv[ii]
        if skipc != 0:
            skipc -= 1
            continue
        if clarg == "-S":
            minus_s = True
        if clarg == "-c":
            minus_c = True
        if clarg == "-o":
            outfile = sys.argv[ii + 1]
            skipc = 1
            continue
        if clarg.startswith("-L"):
            largsSeen = True
        if clarg == "-v":
            flag_trace_llinvoc = True
            minus_v = True

        # redirect some gcc flags to the ones gollvm uses
        if clarg == "-w":
            clarg = "-no-warn"

        # dummy flags that are not supported by gollvm
        if clarg == "-lm":
            continue  # TODO: if the linker is invoked, pass this to the linker?
        if clarg == "-fbounds-check":
            continue
        if clarg == "-finline-functions":
            continue
        if clarg == "-fno-diagnostics-show-caret":
            continue
        if clarg == "-fno-toplevel-reorder":
            continue
        if clarg == "-fno-var-tracking-assignments":
            continue
        if clarg == "-fomit-frame-pointer":
            continue
        if clarg == "-funroll-loops":
            continue
        if clarg == "-funsafe-math-optimizations":
            continue
        if clarg == "-gno-record-gcc-switches":
            continue
        if clarg == "-mfancy-math-387":
            continue
        if clarg == "-minline-all-stringops":
            continue
        if clarg == "-pedantic-errors":
            continue
        if clarg.startswith("-fdiagnostics-color"):
            continue
        if clarg.startswith("-fdebug-prefix-map"):
            continue

        # skip .o and .a files in compilation, but record
        # them for linker invocation.
        if clarg.endswith(".o"):
            ofiles.append(clarg)
            continue
        if clarg.endswith(".a"):
            ofiles.append(clarg)
            continue

        if clarg == "-static":
            ldflags.append(clarg)
            continue
        if clarg == "-static-libgo":
            ldflags.append(clarg)
            continue
        if clarg == "-static-libstdc++":
            ldflags.append(clarg)
            continue
        if clarg == "-static-libgcc":
            ldflags.append(clarg)
            continue

        nargs.append(clarg)
        u.verbose(2, "append arg %s" % clarg)

    tf = None
    if not minus_c and not minus_s:
        if not outfile:
            outfile = "a.out"
        linkoutfile = outfile
        tf = tempfile.NamedTemporaryFile(mode="w",
                                         prefix="%s" % basename,
                                         delete=True)
        outfile = tf.name

    if outfile:
        nargs.append("-o")
        nargs.append(outfile)

    if not largsSeen:
        nargs.append("-L")
        nargs.append(form_golibargs(sys.argv[0]))
        u.verbose(1, "revised args: %s" % " ".join(nargs))

    # Invoke gollvm.
    driver = "llvm-goc"
    u.verbose(1, "driver path is %s" % driver)
    nargs = ["llvm-goc"] + nargs
    if flag_trace_llinvoc or minus_v:
        u.verbose(0, "%s" % " ".join(nargs))
    rc = subprocess.call(nargs)
    if rc != 0:
        u.verbose(1, "return code %d from %s" % (rc, " ".join(nargs)))
        return 1

    # Invoke the linker
    # Right now we use the real gccgo as the linker
    if not minus_c and not minus_s:
        bd = os.path.dirname(sys.argv[0])
        driver = "%s/gccgo.real" % bd
        ldflags += ["-o", linkoutfile]
        ldcmd = "%s %s %s " % (driver, " ".join(ldflags), outfile)
        ldcmd += " ".join(ofiles)  # pass extra .o files to the linker
        u.verbose(1, "link command is: %s" % ldcmd)
        if minus_v:
            u.verbose(0, "%s" % ldcmd)
        rc = u.docmdnf(ldcmd)
        if rc != 0:
            u.verbose(1, "return code %d from %s" % (rc, ldcmd))
            return 1
        if tf:
            tf.close()

    return 0