@@ -32,14 +32,6 @@ from buildscripts import moduleconfig
3232import libdeps
3333
3434EnsureSConsVersion ( 1 , 1 , 0 )
35- if "uname" in dir (os ):
36- scons_data_dir = ".scons/%s/%s" % ( os .uname ()[0 ] , os .getenv ( "HOST" , "nohost" ) )
37- else :
38- scons_data_dir = ".scons/%s/" % os .getenv ( "HOST" , "nohost" )
39- SConsignFile ( scons_data_dir + "/sconsign" )
40-
41- DEFAULT_INSTALL_DIR = "/usr/local"
42-
4335
4436def findSettingsSetup ():
4537 sys .path .append ( "." )
@@ -140,8 +132,11 @@ def using_system_version_of_cxx_libraries():
140132 return True in [use_system_version_of_library (x ) for x in cxx_library_names ]
141133
142134def get_variant_dir ():
135+
136+ build_dir = get_option ('build-dir' ).rstrip ('/' )
137+
143138 if has_option ('variant-dir' ):
144- return "#build/" + get_option ('variant-dir' )
139+ return ( build_dir + '/' + get_option ('variant-dir' )). rstrip ( '/' )
145140
146141 substitute = lambda x : re .sub ( "[:,\\ \\ /]" , "_" , x )
147142
@@ -170,10 +165,10 @@ def get_variant_dir():
170165 extras += ["branch_" + substitute ( utils .getGitBranch () )]
171166
172167 if has_option ('cache' ):
173- s = "#build/ cached/ "
168+ s = "cached"
174169 s += "/" .join (extras ) + "/"
175170 else :
176- s = "#build/ ${PYSYSPLATFORM}/"
171+ s = "${PYSYSPLATFORM}/"
177172 a += extras
178173
179174 if len (a ) > 0 :
@@ -182,19 +177,20 @@ def get_variant_dir():
182177 else :
183178 s += "normal/"
184179
185- return s
180+ return ( build_dir + '/' + s ). rstrip ( '/' )
186181
187182# build output
188183add_option ( "mute" , "do not display commandlines for compiling and linking, to reduce screen noise" , 0 , False )
189184
190185# installation/packaging
191- add_option ( "prefix" , "installation prefix" , 1 , False , default = DEFAULT_INSTALL_DIR )
186+ add_option ( "prefix" , "installation prefix" , 1 , False , default = '$BUILD_ROOT/install' )
192187add_option ( "distname" , "dist name (0.8.0)" , 1 , False )
193188add_option ( "distmod" , "additional piece for full dist name" , 1 , False )
194189add_option ( "distarch" , "override the architecture name in dist output" , 1 , False )
195190add_option ( "nostrip" , "do not strip installed binaries" , 0 , False )
196191add_option ( "extra-variant-dirs" , "extra variant dir components, separated by commas" , 1 , False )
197192add_option ( "add-branch-to-variant-dir" , "add current git branch to the variant dir" , 0 , False )
193+ add_option ( "build-dir" , "build output directory" , 1 , False , default = '#build' )
198194add_option ( "variant-dir" , "override variant subdirectory" , 1 , False )
199195
200196# linking options
@@ -337,15 +333,38 @@ add_option('cache',
337333
338334add_option ('cache-dir' ,
339335 "Specify the directory to use for caching objects if --cache is in use" ,
340- 1 , False , default = "#build/cached/. cache" )
336+ 1 , False , default = "$BUILD_ROOT/scons/ cache" )
341337
342338# don't run configure if user calls --help
343339if GetOption ('help' ):
344340 Return ()
345341
346342# --- environment setup ---
347343
348- variantDir = get_variant_dir ()
344+ # If the user isn't using the # to indicate top-of-tree or $ to expand a variable, forbid
345+ # relative paths. Relative paths don't really work as expected, because they end up relative to
346+ # the top level SConstruct, not the invokers CWD. We could in theory fix this with
347+ # GetLaunchDir, but that seems a step too far.
348+ buildDir = get_option ('build-dir' ).rstrip ('/' )
349+ if buildDir [0 ] not in ['$' , '#' ]:
350+ if not os .path .isabs (buildDir ):
351+ print ("Do not use relative paths with --build-dir" )
352+ Exit (1 )
353+
354+ cacheDir = get_option ('cache-dir' ).rstrip ('/' )
355+ if cacheDir [0 ] not in ['$' , '#' ]:
356+ if not os .path .isabs (cachdDIr ):
357+ print ("Do not use relative paths with --cache-dir" )
358+ Exit (1 )
359+
360+ installDir = get_option ('prefix' ).rstrip ('/' )
361+ if installDir [0 ] not in ['$' , '#' ]:
362+ if not os .path .isabs (installDir ):
363+ print ("Do not use relative paths with --prefix" )
364+ Exit (1 )
365+
366+ sconsDataDir = Dir (buildDir ).Dir ('scons' )
367+ SConsignFile (str (sconsDataDir .File ('sconsign' )))
349368
350369def printLocalInfo ():
351370 import sys , SCons
@@ -407,7 +426,13 @@ v8suffix = '' if v8version == '3.12' else '-' + v8version
407426
408427usePCH = has_option ( "usePCH" )
409428
410- env = Environment ( BUILD_DIR = variantDir ,
429+ # Yes, BUILD_ROOT vs BUILD_DIR is confusing. Ideally, BUILD_DIR would actually be called
430+ # VARIANT_DIR, and at some point we should probably do that renaming. Until we do though, we
431+ # also need an Environment variable for the argument to --build-dir, which is the parent of all
432+ # variant dirs. For now, we call that BUILD_ROOT. If and when we s/BUILD_DIR/VARIANT_DIR/g,
433+ # then also s/BUILD_ROOT/BUILD_DIR/g.
434+ env = Environment ( BUILD_ROOT = buildDir ,
435+ BUILD_DIR = get_variant_dir (),
411436 DIST_ARCHIVE_SUFFIX = '.tgz' ,
412437 EXTRAPATH = get_option ("extrapath" ),
413438 MODULE_BANNERS = [],
@@ -419,12 +444,14 @@ env = Environment( BUILD_DIR=variantDir,
419444 TARGET_ARCH = msarch ,
420445 tools = ["default" , "gch" , "jsheader" , "mergelib" , "unittest" ],
421446 UNITTEST_ALIAS = 'unittests' ,
422- UNITTEST_LIST = '#build/unittests.txt' ,
447+ # TODO: Move unittests.txt to $BUILD_DIR, but that requires
448+ # changes to MCI.
449+ UNITTEST_LIST = '$BUILD_ROOT/unittests.txt' ,
423450 PYSYSPLATFORM = os .sys .platform ,
424-
425451 PCRE_VERSION = '8.30' ,
426- CONFIGUREDIR = '#' + scons_data_dir + '/sconf_temp' ,
427- CONFIGURELOG = '#' + scons_data_dir + '/config.log'
452+ CONFIGUREDIR = sconsDataDir .Dir ('sconf_temp' ),
453+ CONFIGURELOG = sconsDataDir .File ('config.log' ),
454+ INSTALL_DIR = installDir ,
428455 )
429456
430457if has_option ("cache" ):
@@ -435,7 +462,7 @@ if has_option("cache"):
435462 if has_option ("gcov" ):
436463 print ("Mixing --cache and --gcov doesn't work correctly yet. See SERVER-11084" )
437464 Exit (1 )
438- env .CacheDir (str (env .Dir (get_option ( 'cache-dir' ) )))
465+ env .CacheDir (str (env .Dir (cacheDir )))
439466
440467# This could be 'if solaris', but unfortuantely that variable hasn't been set yet.
441468if "sunos5" == os .sys .platform :
@@ -588,15 +615,11 @@ if force64:
588615
589616env ['PROCESSOR_ARCHITECTURE' ] = processor
590617
591- installDir = DEFAULT_INSTALL_DIR
592618nixLibPrefix = "lib"
593619
594620dontReplacePackage = False
595621isBuildingLatest = False
596622
597- if has_option ( "prefix" ):
598- installDir = GetOption ( "prefix" )
599-
600623def filterExists (paths ):
601624 return filter (os .path .exists , paths )
602625
@@ -1844,7 +1867,6 @@ env['SERVER_DIST_BASENAME'] = 'mongodb-%s-%s' % (getSystemInstallName(), distNam
18441867distFile = "${SERVER_ARCHIVE}"
18451868
18461869env ['NIX_LIB_DIR' ] = nixLibPrefix
1847- env ['INSTALL_DIR' ] = installDir
18481870
18491871# ---- CONVENIENCE ----
18501872
0 commit comments