Commit 53753410 authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

add a create_fetcher() method to ManifestLoader

Summary:
The ManifestLoader contains all of the state needed to create a fetcher
object, so define a helper method on this object to create a fetcher.

Reviewed By: strager

Differential Revision: D16477395

fbshipit-source-id: 6de0942fe6b8de26c18c82bf99343f5467dc006a
parent b2c3257c
...@@ -91,7 +91,7 @@ class FetchCmd(SubCmd): ...@@ -91,7 +91,7 @@ class FetchCmd(SubCmd):
else: else:
projects = [manifest] projects = [manifest]
for m in projects: for m in projects:
fetcher = m.create_fetcher(opts, loader.ctx_gen.get_context(m.name)) fetcher = loader.create_fetcher(m)
fetcher.update() fetcher.update()
...@@ -153,11 +153,8 @@ class ShowInstDirCmd(SubCmd): ...@@ -153,11 +153,8 @@ class ShowInstDirCmd(SubCmd):
manifests = [manifest] manifests = [manifest]
for m in manifests: for m in manifests:
ctx = loader.ctx_gen.get_context(m.name) fetcher = loader.create_fetcher(m)
fetcher = m.create_fetcher(opts, ctx) dirs = opts.compute_dirs(m, fetcher, loader)
dirs = opts.compute_dirs(
m, fetcher, loader.manifests_by_name, loader.ctx_gen
)
inst_dir = dirs["inst_dir"] inst_dir = dirs["inst_dir"]
print(inst_dir) print(inst_dir)
...@@ -191,7 +188,7 @@ class ShowSourceDirCmd(SubCmd): ...@@ -191,7 +188,7 @@ class ShowSourceDirCmd(SubCmd):
manifests = [manifest] manifests = [manifest]
for m in manifests: for m in manifests:
fetcher = m.create_fetcher(opts, loader.ctx_gen.get_context(m.name)) fetcher = loader.create_fetcher(m)
print(fetcher.get_src_dir()) print(fetcher.get_src_dir())
def setup_parser(self, parser): def setup_parser(self, parser):
...@@ -232,13 +229,12 @@ class BuildCmd(SubCmd): ...@@ -232,13 +229,12 @@ class BuildCmd(SubCmd):
install_dirs = [] install_dirs = []
for m in projects: for m in projects:
ctx = ctx_gen.get_context(m.name) fetcher = loader.create_fetcher(m)
fetcher = m.create_fetcher(opts, ctx)
if args.clean: if args.clean:
fetcher.clean() fetcher.clean()
dirs = opts.compute_dirs(m, fetcher, loader.manifests_by_name, ctx_gen) dirs = opts.compute_dirs(m, fetcher, loader)
build_dir = dirs["build_dir"] build_dir = dirs["build_dir"]
inst_dir = dirs["inst_dir"] inst_dir = dirs["inst_dir"]
...@@ -262,6 +258,7 @@ class BuildCmd(SubCmd): ...@@ -262,6 +258,7 @@ class BuildCmd(SubCmd):
if os.path.exists(built_marker): if os.path.exists(built_marker):
os.unlink(built_marker) os.unlink(built_marker)
src_dir = fetcher.get_src_dir() src_dir = fetcher.get_src_dir()
ctx = ctx_gen.get_context(m.name)
builder = m.create_builder(opts, src_dir, build_dir, inst_dir, ctx) builder = m.create_builder(opts, src_dir, build_dir, inst_dir, ctx)
builder.build(install_dirs, reconfigure=reconfigure) builder.build(install_dirs, reconfigure=reconfigure)
...@@ -330,10 +327,9 @@ class FixupDeps(SubCmd): ...@@ -330,10 +327,9 @@ class FixupDeps(SubCmd):
install_dirs = [] install_dirs = []
for m in projects: for m in projects:
ctx = ctx_gen.get_context(m.name) fetcher = loader.create_fetcher(m)
fetcher = m.create_fetcher(opts, ctx)
dirs = opts.compute_dirs(m, fetcher, loader.manifests_by_name, ctx_gen) dirs = opts.compute_dirs(m, fetcher, loader)
inst_dir = dirs["inst_dir"] inst_dir = dirs["inst_dir"]
install_dirs.append(inst_dir) install_dirs.append(inst_dir)
...@@ -387,10 +383,9 @@ class TestCmd(SubCmd): ...@@ -387,10 +383,9 @@ class TestCmd(SubCmd):
install_dirs = [] install_dirs = []
for m in projects: for m in projects:
ctx = ctx_gen.get_context(m.name) fetcher = loader.create_fetcher(m)
fetcher = m.create_fetcher(opts, ctx)
dirs = opts.compute_dirs(m, fetcher, loader.manifests_by_name, ctx_gen) dirs = opts.compute_dirs(m, fetcher, loader)
build_dir = dirs["build_dir"] build_dir = dirs["build_dir"]
inst_dir = dirs["inst_dir"] inst_dir = dirs["inst_dir"]
...@@ -403,6 +398,7 @@ class TestCmd(SubCmd): ...@@ -403,6 +398,7 @@ class TestCmd(SubCmd):
# support. # support.
return 1 return 1
src_dir = fetcher.get_src_dir() src_dir = fetcher.get_src_dir()
ctx = ctx_gen.get_context(m.name)
builder = m.create_builder(opts, src_dir, build_dir, inst_dir, ctx) builder = m.create_builder(opts, src_dir, build_dir, inst_dir, ctx)
builder.run_tests(install_dirs, schedule_type=args.schedule_type) builder.run_tests(install_dirs, schedule_type=args.schedule_type)
......
...@@ -148,7 +148,7 @@ class BuildOptions(object): ...@@ -148,7 +148,7 @@ class BuildOptions(object):
} }
) )
def _compute_hash(self, hash_by_name, manifest, manifests_by_name, ctx_gen): def _compute_hash(self, hash_by_name, manifest, loader):
""" This recursive function computes a hash for a given manifest. """ This recursive function computes a hash for a given manifest.
The hash takes into account some environmental factors on the The hash takes into account some environmental factors on the
host machine and includes the hashes of its dependencies. host machine and includes the hashes of its dependencies.
...@@ -173,8 +173,7 @@ class BuildOptions(object): ...@@ -173,8 +173,7 @@ class BuildOptions(object):
for tool in ["cc", "c++", "gcc", "g++", "clang", "clang++"]: for tool in ["cc", "c++", "gcc", "g++", "clang", "clang++"]:
env["tool-%s" % tool] = path_search(os.environ, tool) env["tool-%s" % tool] = path_search(os.environ, tool)
ctx = ctx_gen.get_context(manifest.name) fetcher = loader.create_fetcher(manifest)
fetcher = manifest.create_fetcher(self, ctx)
env["fetcher.hash"] = fetcher.hash() env["fetcher.hash"] = fetcher.hash()
for name in sorted(env.keys()): for name in sorted(env.keys()):
...@@ -183,12 +182,13 @@ class BuildOptions(object): ...@@ -183,12 +182,13 @@ class BuildOptions(object):
if value is not None: if value is not None:
hasher.update(value.encode("utf-8")) hasher.update(value.encode("utf-8"))
ctx = loader.ctx_gen.get_context(manifest.name)
manifest.update_hash(hasher, ctx) manifest.update_hash(hasher, ctx)
dep_list = sorted(manifest.get_section_as_dict("dependencies", ctx).keys()) dep_list = sorted(manifest.get_section_as_dict("dependencies", ctx).keys())
for dep in dep_list: for dep in dep_list:
dep_hash = self._compute_hash( dep_hash = self._compute_hash(
hash_by_name, manifests_by_name[dep], manifests_by_name, ctx_gen hash_by_name, loader.load_manifest(dep), loader
) )
hasher.update(dep_hash.encode("utf-8")) hasher.update(dep_hash.encode("utf-8"))
...@@ -204,9 +204,9 @@ class BuildOptions(object): ...@@ -204,9 +204,9 @@ class BuildOptions(object):
return h return h
def compute_dirs(self, manifest, fetcher, manifests_by_name, ctx_gen): def compute_dirs(self, manifest, fetcher, loader):
hash_by_name = {} hash_by_name = {}
hash = self._compute_hash(hash_by_name, manifest, manifests_by_name, ctx_gen) hash = self._compute_hash(hash_by_name, manifest, loader)
if manifest.is_first_party_project(): if manifest.is_first_party_project():
directory = manifest.name directory = manifest.name
......
...@@ -187,3 +187,7 @@ class ManifestLoader(object): ...@@ -187,3 +187,7 @@ class ManifestLoader(object):
dep_order.append(m) dep_order.append(m)
return dep_order return dep_order
def create_fetcher(self, manifest):
ctx = self.ctx_gen.get_context(manifest.name)
return manifest.create_fetcher(self.build_opts, ctx)
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