2015-02-10 05:57:45 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
logging_format = '[%(levelname)s] %(message)s'
|
|
|
|
logging.basicConfig(level=logging.INFO, format=logging_format)
|
|
|
|
|
|
|
|
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
REPO_ROOT_DIR = os.path.realpath(os.path.join(SCRIPT_DIR, "../.."))
|
|
|
|
|
|
|
|
def get_files_to_compile(json_data):
|
|
|
|
files_to_compile = []
|
|
|
|
for element in json_data:
|
|
|
|
filename = element["file"]
|
2015-12-03 03:57:24 +00:00
|
|
|
if not filename.endswith("tests.cpp") and \
|
|
|
|
not filename.endswith("benchmarks.cpp") and \
|
2015-02-24 07:15:04 +00:00
|
|
|
"third-party" not in filename and \
|
|
|
|
"example" not in filename and \
|
2015-12-03 03:57:24 +00:00
|
|
|
"generated/gen" not in filename and \
|
|
|
|
"test_util" not in filename:
|
2015-02-24 07:15:04 +00:00
|
|
|
base = filename.rfind("osquery/")
|
|
|
|
filename = filename[base + len("osquery/"):]
|
|
|
|
base_generated = filename.rfind("generated/")
|
|
|
|
if base_generated >= 0:
|
2015-03-04 16:45:21 +00:00
|
|
|
filename = filename[base_generated:]
|
2015-02-10 05:57:45 +00:00
|
|
|
files_to_compile.append(filename)
|
|
|
|
return files_to_compile
|
|
|
|
|
|
|
|
TARGETS_PREAMBLE = """
|
2015-02-25 08:09:43 +00:00
|
|
|
# DO NOT EDIT
|
|
|
|
# Automatically generated: make sync
|
|
|
|
|
2015-02-10 05:57:45 +00:00
|
|
|
thrift_library(
|
|
|
|
name="if",
|
|
|
|
languages=[
|
|
|
|
"cpp",
|
2015-02-25 08:09:43 +00:00
|
|
|
"py",
|
2015-02-10 05:57:45 +00:00
|
|
|
],
|
|
|
|
thrift_srcs={
|
|
|
|
"extensions/osquery.thrift": ["Extension", "ExtensionManager"],
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
cpp_library(
|
|
|
|
name="osquery_sdk",
|
|
|
|
srcs=["""
|
|
|
|
|
|
|
|
TARGETS_POSTSCRIPT = """ ],
|
|
|
|
deps=[
|
2015-12-03 03:57:24 +00:00
|
|
|
"@/thrift/lib/cpp/concurrency:concurrency",
|
2015-02-10 05:57:45 +00:00
|
|
|
":if-cpp",
|
|
|
|
],
|
|
|
|
external_deps=[
|
|
|
|
"boost",
|
|
|
|
"glog",
|
|
|
|
"gflags",
|
|
|
|
"gtest",
|
|
|
|
"rocksdb",
|
|
|
|
"libuuid",
|
|
|
|
],
|
|
|
|
compiler_flags=[
|
|
|
|
"-Wno-unused-function",
|
|
|
|
"-Wno-non-virtual-dtor",
|
|
|
|
"-Wno-address",
|
|
|
|
"-Wno-overloaded-virtual",
|
2015-02-25 08:09:43 +00:00
|
|
|
"-DOSQUERY_BUILD_VERSION=%s",
|
|
|
|
"-DOSQUERY_BUILD_SDK_VERSION=%s",
|
2015-02-19 23:19:00 +00:00
|
|
|
"-DOSQUERY_THRIFT_LIB=thrift/lib/cpp",
|
|
|
|
"-DOSQUERY_THRIFT_SERVER_LIB=thrift/lib/cpp/server/example",
|
|
|
|
"-DOSQUERY_THRIFT_POINTER=std",
|
|
|
|
"-DOSQUERY_THRIFT=osquery/gen-cpp/",
|
2015-02-10 05:57:45 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
"""
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(description=(
|
|
|
|
"Generate a TARGETS files from CMake metadata"
|
|
|
|
))
|
|
|
|
parser.add_argument("--input", "-i", required=True)
|
2015-02-25 08:09:43 +00:00
|
|
|
parser.add_argument("--version", "-v", required=True)
|
2015-03-04 16:45:21 +00:00
|
|
|
parser.add_argument("--sdk", required=True)
|
2015-02-10 05:57:45 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
try:
|
|
|
|
with open(args.input, "r") as f:
|
|
|
|
try:
|
|
|
|
json_data = json.loads(f.read())
|
|
|
|
except ValueError:
|
|
|
|
logging.critical("Error: %s is not valid JSON" % args.input)
|
|
|
|
|
|
|
|
source_files = get_files_to_compile(json_data)
|
|
|
|
print(TARGETS_PREAMBLE)
|
|
|
|
for source_file in source_files:
|
|
|
|
print(" \"%s\"," % source_file)
|
2015-02-25 08:09:43 +00:00
|
|
|
print(TARGETS_POSTSCRIPT % (args.version, args.sdk))
|
2015-02-10 05:57:45 +00:00
|
|
|
|
|
|
|
except IOError:
|
|
|
|
logging.critical("Error: %s doesn't exist" % args.input)
|