sapling/build/fbcode_builder/getdeps.py
Wez Furlong ac0e9c91c6 fbcode_builder: getdeps: add platform type tuple helper
Summary:
This will feed into the manifest context for system
dependent manifest sections.  This is essentially the same
code borrowed from the watchman and eden getdeps.py.

Reviewed By: simpkins

Differential Revision: D14690997

fbshipit-source-id: 3d3ae146237a2cd49609aaa2bd0e785ebe21f02c
2019-05-03 15:59:38 -07:00

79 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
from __future__ import absolute_import, division, print_function, unicode_literals
import argparse
import os
import subprocess
import sys
from getdeps.manifest import ManifestParser
from getdeps.platform import HostType
from getdeps.subcmd import SubCmd, add_subcommands, cmd
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "getdeps"))
@cmd("validate-manifest", "parse a manifest and validate that it is correct")
class ValidateManifest(SubCmd):
def run(self, args):
try:
ManifestParser(file_name=args.file_name)
print("OK", file=sys.stderr)
return 0
except Exception as exc:
print("ERROR: %s" % str(exc), file=sys.stderr)
return 1
def setup_parser(self, parser):
parser.add_argument("file_name", help="path to the manifest file")
@cmd("show-host-type", "outputs the host type tuple for the host machine")
class ShowHostType(SubCmd):
def run(self, args):
host = HostType()
print("%s" % host.as_tuple_string())
return 0
def build_argparser():
ap = argparse.ArgumentParser(description="Get and build dependencies and projects")
sub = ap.add_subparsers(
# metavar suppresses the long and ugly default list of subcommands on a
# single line. We still render the nicer list below where we would
# have shown the nasty one.
metavar="",
title="Available commands",
help="",
)
add_subcommands(sub)
return ap
def main():
ap = build_argparser()
args = ap.parse_args()
if getattr(args, "func", None) is None:
ap.print_help()
return 0
try:
return args.func(args)
except subprocess.CalledProcessError:
print("!! Failed", file=sys.stderr)
return 1
if __name__ == "__main__":
sys.exit(main())