def RunGitCmd(directory, cmd, error_ok=False): cmd = ['git'] + cmd LogVerbose('%s' % ' '.join(cmd)) p = subprocess.Popen(cmd, cwd=directory, stderr=subprocess.PIPE, stdout=subprocess.PIPE) stdout, stderr = p.communicate() if not error_ok and p.returncode != 0: if stdout: Log(stdout) if stderr: Log(stderr) raise Error('git command failed: %s' % cmd) Trace('git exited with %d' % p.returncode) return p.returncode
def RunBuildSh(self): build_port = os.path.join(paths.TOOLS_DIR, 'build_port.sh') cmd = [build_port] env = os.environ.copy() env['TOOLCHAIN'] = self.config.toolchain env['NACL_ARCH'] = self.config.arch env['NACL_DEBUG'] = self.config.debug and '1' or '0' env['NACL_SDK_ROOT'] = util.GetSDKRoot() rtn = subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr, cwd=self.root, env=env) if rtn != 0: raise Error("Building %s: failed." % (self.NAME))
def CreatePackage(package_name, config=None): """Create a Package object given a package name or path. Returns: Package object """ if os.path.isdir(package_name): return SourcePackage(package_name, config) for subdir in DEFAULT_LOCATIONS: pkg_root = os.path.join(paths.NACLPORTS_ROOT, subdir, package_name) info = os.path.join(pkg_root, 'pkg_info') if os.path.exists(info): return SourcePackage(pkg_root, config) raise Error("Package not found: %s" % package_name)
def AddPackageDep(dep_dict, dep): dep_dict['origin'] = dep if os.path.isdir(dep): dep_dict['version'] = package.Package( info_file=os.path.join(dep, 'pkg_info')).VERSION return for subdir in DEFAULT_LOCATIONS: pkg_info_file = os.path.join(paths.NACLPORTS_ROOT, subdir, dep, 'pkg_info') if os.path.exists(pkg_info_file): dep_dict['version'] = package.Package( info_file=pkg_info_file).VERSION return raise Error("Package not found: %s" % dep)
def Validate(self): for libc in self.DISABLED_LIBC: if libc not in configuration.VALID_LIBC: raise Error('%s: invalid libc: %s' % (self.info, libc)) for toolchain in self.DISABLED_TOOLCHAIN: if '/' in toolchain: toolchain, arch = toolchain.split('/') if arch not in util.arch_to_pkgarch: raise Error('%s: invalid architecture: %s' % (self.info, arch)) if toolchain not in configuration.VALID_TOOLCHAINS: raise Error('%s: invalid toolchain: %s' % (self.info, toolchain)) for arch in self.DISABLED_ARCH: if arch not in util.arch_to_pkgarch: raise Error('%s: invalid architecture: %s' % (self.info, arch)) if '_' in self.NAME: raise Error('%s: package NAME cannot contain underscores' % self.info) if self.NAME != self.NAME.lower(): raise Error( '%s: package NAME cannot contain uppercase characters' % self.info) if '_' in self.VERSION: raise Error('%s: package VERSION cannot contain underscores' % self.info) if self.DISABLED_ARCH and self.ARCH is not None: raise Error('%s: contains both ARCH and DISABLED_ARCH' % self.info) if self.DISABLED_LIBC and self.LIBC is not None: raise Error('%s: contains both LIBC and DISABLED_LIBC' % self.info)
def GitClone(self): """Create a clone of the upstream repo in the build directory. This operation will only require a network connection if the local git mirror is out-of-date.""" stamp_file = self.GetExtractStamp() stamp_content = 'GITURL=%s' % self.URL patch_file = self.GetPatchFile() if os.path.exists(patch_file): patch_checksum = util.HashFile(patch_file) stamp_content += ' PATCH=%s' % patch_checksum stamp_content += '\n' dest = self.GetBuildLocation() if os.path.exists(self.GetBuildLocation()): if StampContentsMatch(stamp_file, stamp_content): return raise Error('Upstream archive or patch has changed.\n' + "Please remove existing checkout and try again: '%s'" % dest) util.LogHeading('Cloning') # Ensure local mirror is up-to-date git_mirror, git_commit = self.GitCloneToMirror() # Clone from the local mirror. RunGitCmd(None, ['clone', git_mirror, dest]) RunGitCmd(dest, ['reset', '--hard', git_commit]) # Set the origing to the original URL so it is possible to push directly # from the build tree. RunGitCmd(dest, ['remote', 'set-url', 'origin', self.URL.split('@')[0]]) self.RemoveStamps() WriteStamp(stamp_file, stamp_content)
def UpdatePatch(self): if self.URL is None: return git_dir = self.GetBuildLocation() if not os.path.exists(git_dir): raise Error('Source directory not found: %s' % git_dir) try: diff = subprocess.check_output( ['git', 'diff', 'upstream', '--no-ext-diff'], cwd=git_dir) except subprocess.CalledProcessError as e: raise Error('error running git in %s: %s' % (git_dir, str(e))) # Drop index lines for a more stable diff. diff = re.sub('\nindex [^\n]+\n', '\n', diff) # Drop binary files, as they don't work anyhow. diff = re.sub( 'diff [^\n]+\n' '(new file [^\n]+\n)?' '(deleted file mode [^\n]+\n)?' 'Binary files [^\n]+ differ\n', '', diff) # Filter out things from an optional per port skip list. diff_skip = os.path.join(self.root, 'diff_skip.txt') if os.path.exists(diff_skip): names = open(diff_skip).read().splitlines() new_diff = '' skipping = False for line in diff.splitlines(): if line.startswith('diff --git '): skipping = False for name in names: if line == 'diff --git a/%s b/%s' % (name, name): skipping = True if not skipping: new_diff += line + '\n' diff = new_diff # Write back out the diff. patch_path = self.GetPatchFile() preexisting = os.path.exists(patch_path) if not diff: if preexisting: Log('removing patch file: %s' % util.RelPath(patch_path)) os.remove(patch_path) else: Log('no patch required: %s' % util.RelPath(git_dir)) return if preexisting: with open(patch_path) as f: if diff == f.read(): Log('patch unchanged: %s' % util.RelPath(patch_path)) return with open(patch_path, 'w') as f: f.write(diff) if preexisting: Log('created patch: %s' % util.RelPath(patch_path)) else: Log('updated patch: %s' % util.RelPath(patch_path))
def CreateInstalledPackage(package_name, config=None): stamp_root = util.GetInstallStampRoot(config) info_file = os.path.join(stamp_root, package_name + '.info') if not os.path.exists(info_file): raise Error('package not installed: %s [%s]' % (package_name, config)) return InstalledPackage(info_file)