Commit cfed36bd authored by Shrikrishna Khare's avatar Shrikrishna Khare Committed by Facebook Github Bot

fbcode_builder: getdeps: fboss: add iproute2 fetcher

Summary:
This is towards getting open source FBOSS to build using fbcode_builder.
iproute2 is one of the dependencies for FBOSS. This patch adds a manifest file
to build the specific version of iproute2 needed for FBOSS.

Additionally, the default git clone depth of 100 is insufficient for the
version of iproute2 FBOSS depends on. Thus, this patch extends the git SCHEMA
to add optional argument depth. The default remains 100.

The usual /configure --prefix does not work for iproute2. Thus, we need to add
a custom builder that:
  - copies sources to build directory, builds, and
  - installs to installed directory using DEST_DIR.
  - it must also explicitly copy include from build dir to install dir

Reviewed By: wez

Differential Revision: D15588809

fbshipit-source-id: ac5eab24134e078d88b85b4be433c78b05ef8ce5
parent d4774463
......@@ -192,6 +192,48 @@ class AutoconfBuilder(BuilderBase):
self._run_cmd(["make", "install"], env=env)
class Iproute2Builder(BuilderBase):
# ./configure --prefix does not work for iproute2.
# Thus, explicitly copy sources from src_dir to build_dir, bulid,
# and then install to inst_dir using DESTDIR
# lastly, also copy include from build_dir to inst_dir
def __init__(self, build_opts, ctx, manifest, src_dir, build_dir, inst_dir):
super(Iproute2Builder, self).__init__(
build_opts, ctx, manifest, src_dir, build_dir, inst_dir
)
def _patch(self):
# FBOSS build currently depends on an old version of iproute2 (commit
# 7ca63aef7d1b0c808da0040c6b366ef7a61f38c1). This is missing a commit
# (ae717baf15fb4d30749ada3948d9445892bac239) needed to build iproute2
# successfully. Apply it viz.: include stdint.h
# Reference: https://fburl.com/ilx9g5xm
with open(self.build_dir + "/tc/tc_core.c", "r") as f:
data = f.read()
with open(self.build_dir + "/tc/tc_core.c", "w") as f:
f.write("#include <stdint.h>\n")
f.write(data)
def _build(self, install_dirs, reconfigure):
configure_path = os.path.join(self.src_dir, "configure")
env = self.env.copy()
self._run_cmd([configure_path], env=env)
shutil.rmtree(self.build_dir)
shutil.copytree(self.src_dir, self.build_dir)
self._patch()
self._run_cmd(["make", "-j%s" % self.build_opts.num_jobs], env=env)
install_cmd = ["make", "install", "DESTDIR=" + self.inst_dir]
if not os.path.isdir(os.path.join(self.inst_dir, "include")):
shutil.copytree(
os.path.join(self.build_dir, "include"),
os.path.join(self.inst_dir, "include"),
)
self._run_cmd(install_cmd, env=env)
class CMakeBuilder(BuilderBase):
def __init__(
self, build_opts, ctx, manifest, src_dir, build_dir, inst_dir, defines
......
......@@ -131,7 +131,9 @@ class Fetcher(object):
class GitFetcher(Fetcher):
def __init__(self, build_options, manifest, repo_url, rev):
DEFAULT_DEPTH = 100
def __init__(self, build_options, manifest, repo_url, rev, depth):
# Extract the host/path portions of the URL and generate a flattened
# directory name. eg:
# github.com/facebook/folly.git -> github.com-facebook-folly.git
......@@ -163,6 +165,7 @@ class GitFetcher(Fetcher):
self.rev = rev or "master"
self.origin_repo = repo_url
self.manifest = manifest
self.depth = depth if depth else GitFetcher.DEFAULT_DEPTH
def _update(self):
current_hash = (
......@@ -209,7 +212,7 @@ class GitFetcher(Fetcher):
[
"git",
"clone",
"--depth=100",
"--depth=" + str(self.depth),
"--",
self.origin_repo,
os.path.basename(self.repo_dir),
......
......@@ -14,6 +14,7 @@ from .builder import (
AutoconfBuilder,
Boost,
CMakeBuilder,
Iproute2Builder,
MakeBuilder,
NinjaBootstrap,
NopBuilder,
......@@ -50,7 +51,7 @@ SCHEMA = {
"dependencies": {"optional_section": True, "allow_values": False},
"git": {
"optional_section": True,
"fields": {"repo_url": REQUIRED, "rev": OPTIONAL},
"fields": {"repo_url": REQUIRED, "rev": OPTIONAL, "depth": OPTIONAL},
},
"download": {
"optional_section": True,
......@@ -326,7 +327,8 @@ class ManifestParser(object):
repo_url = self.get("git", "repo_url", ctx=ctx)
if repo_url:
rev = self.get("git", "rev")
return GitFetcher(build_options, self, repo_url, rev)
depth = self.get("git", "depth")
return GitFetcher(build_options, self, repo_url, rev, depth)
url = self.get("download", "url", ctx=ctx)
if url:
......@@ -393,4 +395,9 @@ class ManifestParser(object):
build_options, ctx, self, build_dir, src_dir, inst_dir
)
if builder == "iproute2":
return Iproute2Builder(
build_options, ctx, self, src_dir, build_dir, inst_dir
)
raise KeyError("project %s has no known builder" % (self.name))
[manifest]
name = iproute2
[git]
repo_url = https://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git
rev = 7ca63aef7d1b0c808da0040c6b366ef7a61f38c1
depth = 1500
[build.os=linux]
builder = iproute2
[build.not(os=linux)]
builder = nop
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment