Example #1
0
  def _fetch_from_cache(self, package_name):
    result = False

    #
    # We still need to use Nuget to figure out where the
    # "global-packages" cache is on this machine.
    #
    if NugetDependency.global_cache_path is None:
      cmd = ["nuget.exe", "locals", "global-packages", "-list"]
      cmd_string = " ".join(cmd)
      return_buffer = StringIO()
      if (RunCmd(cmd_string, outstream=return_buffer) == 0):
        # Seek to the beginning of the output buffer and capture the output.
        return_buffer.seek(0)
        return_string = return_buffer.read()
        NugetDependency.global_cache_path = return_string.strip().strip("global-packages: ")

    #
    # If the path couldn't be found, we can't do anything else.
    #
    if not os.path.isdir(NugetDependency.global_cache_path):
      logging.info("Could not determine Nuget global packages cache location.")
      return False

    #
    # Now, try to locate our actual cache path
    nuget_version = NugetDependency.normalize_version(self.version)
    cache_search_path = os.path.join(NugetDependency.global_cache_path, package_name.lower(), nuget_version, package_name)
    if os.path.isdir(cache_search_path):
      logging.info("Local Cache found for Nuget package '%s'. Skipping fetch." % package_name)
      shutil.copytree(cache_search_path, self.contents_dir)
      self.update_state_file()
      result = True

    return result
Example #2
0
 def PackageFmpCapsuleHeader(InputBin, OutputBin, FmpGuid):
     logging.debug("CapsulePackage: Fmp Capsule Header")
     cmd = "genfmpcap.exe -o " + OutputBin
     cmd = cmd + " -p " + InputBin + " " + FmpGuid + " 1 0 -V"
     ret = RunCmd(cmd)
     if(ret != 0):
         raise Exception("GenFmpCap Failed with errorcode" % ret)
     return ret
Example #3
0
  def fetch(self):
    package_name = self.name

    #
    # Before trying anything with Nuget feeds,
    # check to see whether the package is already in
    # our local cache. If it is, we avoid a lot of
    # time and network cost by copying it directly.
    #
    if self._fetch_from_cache(package_name):
      # We successfully found the package in the cache.
      # Bail.
      return

    #
    # If we are still here, the package wasn't in the cache.
    # We need to ask Nuget to find it.
    #

    #
    # First, fetch the contents of the package.
    #
    temp_directory = self.get_temp_dir()
    cmd = ["nuget.exe", "install", package_name]
    cmd += ["-Source", self.source]
    cmd += ["-ExcludeVersion"]
    cmd += ["-Version", self.version]
    # cmd += ["-DirectDownload", "-NoCache"]  #avoid cache -- not sure this is good
    #cmd += ["-NonInteractive"]
    cmd += ["-Verbosity", "detailed"]
    cmd += ["-OutputDirectory", '"'+temp_directory+'"']
    cmd_string = " ".join(cmd)
    RunCmd(cmd_string)

    #
    # Next, copy the contents of the package to the
    # final resting place.
    #
    # Depending on packaging, the package content will be in one of two
    # possible locations:
    # 1. temp_directory\package_name\package_name\
    # 2. temp_directory\package_name\
    #
    source_dir = os.path.join(temp_directory, package_name, package_name)
    if not os.path.isdir(source_dir):
      source_dir = os.path.join(temp_directory, package_name)
    shutil.move(source_dir, self.contents_dir)

    #
    # Add a file to track the state of the dependency.
    #
    self.update_state_file()

    #
    # Finally, delete the temp directory.
    #
    self._clean_directory(temp_directory)
Example #4
0
 def PackageCapsuleHeader(InputBin, OutputBin, FmpDeviceGuid=None):
     logging.debug("CapsulePackage: Final Capsule Header")
     if(FmpDeviceGuid == None):
         logging.debug("CapsulePackage: Using default industry standard FMP guid")
         FmpDeviceGuid = "6dcbd5ed-e82d-4c44-bda1-7194199ad92a"
         
     cmd = "genfv -o " + OutputBin
     cmd = cmd + " -g " + FmpDeviceGuid
     cmd = cmd + " --capsule -v -f " + InputBin
     cmd = cmd + " --capFlag PersistAcrossReset --capFlag InitiateReset"
     ret = RunCmd(cmd)
     if(ret != 0):
         raise Exception("GenFv Failed with errorcode" % ret)
     return ret 
Example #5
0
 def FindWithVsWhere(self, products=None):
     cmd = "VsWhere -latest -nologo -all -property installationPath"
     if (products is not None):
         cmd += " -products " + products
     a = StringIO()
     ret = RunCmd(cmd, outstream=a)
     if (ret != 0):
         self.Logger.error("Failed in VsWhere %d to get install dir" % ret)
         a.close()
         return (ret, None)
     p1 = a.getvalue().strip()
     a.close()
     if (len(p1.strip()) > 0):
         return (0, p1)
     return (ret, None)
Example #6
0
 def PackageMsFmpHeader(InputBin, OutputBin, VersionInt, LsvInt, DepList = []):
     logging.debug("CapsulePackage: Fmp Header")
     cmd = "genmspayloadheader.exe -o " + OutputBin
     cmd = cmd + " --version " + hex(VersionInt).rstrip("L")
     cmd = cmd + " --lsv " + hex(LsvInt)
     cmd = cmd + " -p " + InputBin + " -v"
     #append depedency if supplied
     for dep in DepList:
         depGuid = dep[0]
         depIndex = int(dep[1])
         depMinVer = hex(dep[2])
         depFlag = hex(dep[3])
         logging.debug("Adding a Dependency:\n\tFMP Guid: %s \nt\tFmp Descriptor Index: %d \n\tFmp DepVersion: %s \n\tFmp Flags: %s\n" % (depGuid, depIndex, depMinVer, depFlag))
         cmd += " --dep " + depGuid + " " + str(depIndex) + " " + depMinVer + " " + depFlag
     ret = RunCmd(cmd)
     if(ret != 0):
         raise Exception("GenMsPayloadHeader Failed with errorcode %d" % ret)
     return ret
  def MakeCat(self, OutputCatFile, PathToInf2CatTool=None):
    #Find Inf2Cat tool
    if(PathToInf2CatTool is None):
      PathToInf2CatTool = os.path.join(os.getenv("ProgramFiles(x86)"), "Windows Kits", "10", "bin", "x86", "Inf2Cat.exe")
      if not os.path.exists(PathToInf2CatTool):
        logging.debug("Windows Kit 10 not Found....trying 8.1")
        #Try 8.1 kit
        PathToInf2CatTool.replace("10", "8.1")

    #check if exists
    if not os.path.exists(PathToInf2CatTool):
        raise Exception("Can't find Inf2Cat on this machine.  Please install the Windows 10 WDK - https://developer.microsoft.com/en-us/windows/hardware/windows-driver-kit")
    
    OutputFolder = os.path.dirname(OutputCatFile)
    #Make Cat file
    cmd = PathToInf2CatTool + " /driver:. /os:" + self.OperatingSystem + "_" + self.Arch + " /verbose"
    ret = RunCmd(cmd, workingdir=OutputFolder)
    if(ret != 0):
        raise Exception("Creating Cat file Failed with errorcode %d" % ret)
    if(not os.path.isfile(OutputCatFile)):
        raise Exception("CAT file (%s) not created" % OutputCatFile)

    return 0
    import CommonBuildEntry

    # Make sure that we can get some logging out.
    CommonBuildEntry.configure_base_logging('verbose')

    # Bring up the common minimum environment.
    CommonBuildEntry.update_process(WORKSPACE_PATH, PROJECT_SCOPE)

    # Tear down logging so the following script doesn't trample it.
    # NOTE: This uses some non-standard calls.
    default_logger = logging.getLogger('')
    while default_logger.handlers:
        default_logger.removeHandler(default_logger.handlers[0])

    #actual code for python unit tests
    from UtilityFunctions import RunCmd
    overall_success = 0
    failed = {}
    matches = []
    for root, dirnames, filenames in os.walk(WORKSPACE_PATH):
        for filename in fnmatch.filter(filenames, '*_test.py'):
            matches.append(os.path.join(root))
            break
    cmd = 'python -m unittest discover -s {} -p "*_test.py" -v'
    for a in set(matches):
        ret = RunCmd(cmd.format(a))
        if (ret != 0):
            overall_success = ret

    sys.exit(overall_success)