22# Copyright 2004-present Facebook. All Rights Reserved.
33
44import argparse
5+ import json
56import os
67import re
78import shlex
1920OPT_ARG_ADD_BUILD_ENV_VAR = "--env-var"
2021OPT_ARG_LOCAL = "--local"
2122OPT_ARG_NUM_JOBS = "--num-jobs"
23+ OPT_ARG_EXTRAS_DIR = "--extras-dir"
24+ OPT_ARG_EXTRA_CMAKE_DEFINES = "--extra-cmake-defines"
2225
2326FBOSS_IMAGE_NAME = "fboss_image"
2427FBOSS_CONTAINER_NAME = "FBOSS_BUILD_CONTAINER"
@@ -157,6 +160,26 @@ def parse_args():
157160 "If unspecified, the default is the number of cpus. (CPU(s) in lspcu output)"
158161 ),
159162 )
163+ parser .add_argument (
164+ OPT_ARG_EXTRAS_DIR ,
165+ type = str ,
166+ required = False ,
167+ help = (
168+ "The contents of this directory will be mounted into the docker "
169+ "image at /var/extras."
170+ ),
171+ )
172+ parser .add_argument (
173+ OPT_ARG_EXTRA_CMAKE_DEFINES ,
174+ type = str ,
175+ required = False ,
176+ help = (
177+ "Extra cmake defines passed to getdeps.py: "
178+ "Input json map that contains extra cmake defines to be used "
179+ "when compiling the current project and all its deps. "
180+ 'e.g: \' {"CMAKE_CXX_FLAGS": "--bla"}\' '
181+ ),
182+ )
160183
161184 return parser .parse_args ()
162185
@@ -236,6 +259,8 @@ def run_fboss_build(
236259 env_vars : List [str ],
237260 use_local : bool ,
238261 num_jobs : Optional [int ],
262+ extras_dir : Optional [str ],
263+ extra_cmake_defines : Optional [str ],
239264):
240265 use_stable_hashes ()
241266
@@ -261,15 +286,26 @@ def run_fboss_build(
261286 # Add TTY flags
262287 if docker_output :
263288 cmd_args .append ("-it" )
289+ if extras_dir :
290+ cmd_args .extend (["-v" , f"{ extras_dir } :/var/extras:rw" ])
264291 # Add args for docker container name
265292 cmd_args .append (f"--name={ FBOSS_CONTAINER_NAME } " )
266293 # Add args for image name
267294 cmd_args .append (f"{ FBOSS_IMAGE_NAME } :latest" )
268295 # Add build command args
296+ extra_defines = {
297+ "CMAKE_BUILD_TYPE" : "MinSizeRel" ,
298+ "CMAKE_CXX_STANDARD" : "20" ,
299+ "CMAKE_C_COMPILER" : "/opt/rh/gcc-toolset-12/root/usr/bin/gcc" ,
300+ "CMAKE_CXX_COMPILER" : "/opt/rh/gcc-toolset-12/root/usr/bin/g++" ,
301+ }
302+ if extra_cmake_defines :
303+ for k , v in json .loads (extra_cmake_defines ).items ():
304+ extra_defines [k ] = v
269305 build_cmd = [
270306 "./build/fbcode_builder/getdeps.py" ,
271307 "build" ,
272- ' --extra-cmake-defines={"CMAKE_BUILD_TYPE": "MinSizeRel", "CMAKE_CXX_STANDARD": "20", "CMAKE_C_COMPILER": "/opt/rh/gcc-toolset-12/root/usr/bin/gcc", "CMAKE_CXX_COMPILER": "/opt/rh/gcc-toolset-12/root/usr/bin/g++"}' ,
308+ f" --extra-cmake-defines={ json . dumps ( extra_defines ) } " ,
273309 "--scratch-path" ,
274310 f"{ CONTAINER_SCRATCH_PATH } " ,
275311 ]
@@ -336,6 +372,8 @@ def main():
336372 args .env_vars ,
337373 args .local ,
338374 args .num_jobs ,
375+ args .extras_dir ,
376+ args .extra_cmake_defines ,
339377 )
340378
341379 cleanup_fboss_build_container ()
0 commit comments