From ccaa0a8c97997bf75672451b9d65dc6e48b8395a Mon Sep 17 00:00:00 2001 From: Alex Burton Date: Thu, 6 Jul 2023 15:09:53 +1000 Subject: [PATCH 1/2] Test for how di handles are handled with variant dir. --- test/D/di/Common/common.py | 64 +++++++++++-------- test/D/di/Image/SConstruct_template | 6 -- test/D/di/VariantDirImage/SConstruct_template | 15 +++++ test/D/di/VariantDirImage/hws/SConscript | 2 + .../D/di/VariantDirImage/hws/helloWorldMain.d | 6 ++ .../VariantDirImage/hws/source/helloWorld.d | 5 ++ 6 files changed, 64 insertions(+), 34 deletions(-) create mode 100644 test/D/di/VariantDirImage/SConstruct_template create mode 100644 test/D/di/VariantDirImage/hws/SConscript create mode 100644 test/D/di/VariantDirImage/hws/helloWorldMain.d create mode 100644 test/D/di/VariantDirImage/hws/source/helloWorld.d diff --git a/test/D/di/Common/common.py b/test/D/di/Common/common.py index 6ca40f91c9..5097ba0bd4 100644 --- a/test/D/di/Common/common.py +++ b/test/D/di/Common/common.py @@ -43,40 +43,48 @@ def testForTool(tool): if not isExecutableOfToolAvailable(test, tool) : test.skip_test("Required executable for tool '{0}' not found, skipping test.\n".format(tool)) - test.dir_fixture('Image') - with open('SConstruct_template', 'r') as f: - config = f.read().format(tool) - test.write('SConstruct', config) - - test.run(options="--debug=explain") - - test.must_exist('source/helloWorld.o') - test.must_exist('helloWorldMain.o') - test.must_exist('include/helloWorld.di') - test.must_exist('hw') - - test.run(program=test.workpath('hw'+TestSCons._exe)) - test.fail_test(test.stdout() != 'Hello World.\n') - - #add a comment and test that this doesn't result in a complete rebuild of all the files that include helloWorld.d because the comment doesn't change helloWorld.di - test.write("source/helloWorld.d",'''import std.stdio; + for img in ["Image","VariantDirImage"]: + if img == "VariantDirImage": + buildPrefix = "build/" + sourcePrefix = "hws/" + else: + sourcePrefix = "" + buildPrefix = "" + test.dir_fixture(img) + with open('SConstruct_template', 'r') as f: + config = f.read().format(tool) + test.write('SConstruct', config) + + test.run(options="--debug=explain") + + test.must_exist(buildPrefix + 'source/helloWorld.o') + test.must_exist(buildPrefix + 'helloWorldMain.o') + test.must_exist(buildPrefix + 'include/helloWorld.di') + test.must_exist(buildPrefix + 'hw') + + test.run(program=test.workpath(buildPrefix + 'hw'+TestSCons._exe)) + test.fail_test(test.stdout() != 'Hello World.\n') + + #add a comment and test that this doesn't result in a complete rebuild of all the files that include helloWorld.d because the comment doesn't change helloWorld.di + test.write(sourcePrefix + "source/helloWorld.d",'''import std.stdio; void go() { - //comment - writeln("Hello World."); + //comment + writeln("Hello World."); }''') - test.not_up_to_date("source/helloWorld.o") - test.up_to_date("helloWorldMain.o hw") + test.not_up_to_date(buildPrefix + "source/helloWorld.o") + test.up_to_date(buildPrefix + "helloWorldMain.o") + test.up_to_date(buildPrefix + "hw") - test.run("-c") - - test.must_not_exist('source/helloWorld.o') - test.must_not_exist('helloWorldMain.o') - test.must_not_exist('include/helloWorld.di') - test.must_not_exist('hw') + test.run("-c") + + test.must_not_exist(buildPrefix + 'source/helloWorld.o') + test.must_not_exist(buildPrefix + 'helloWorldMain.o') + test.must_not_exist(buildPrefix + 'include/helloWorld.di') + test.must_not_exist(buildPrefix + 'hw') - test.pass_test() + test.pass_test() # Local Variables: # tab-width:4 # indent-tabs-mode:nil diff --git a/test/D/di/Image/SConstruct_template b/test/D/di/Image/SConstruct_template index d73432904f..5e7d5cd595 100644 --- a/test/D/di/Image/SConstruct_template +++ b/test/D/di/Image/SConstruct_template @@ -10,10 +10,4 @@ env = Environment( DI_FILE_DIR='include' ) - -# o1 = env.Object('source/helloWorld.d') -# o2 = env.Object('helloWorldMain.d') -# env.Program('hw', [o1[0], o2[0]]) - -# Alternatively env.Program('hw', ['helloWorldMain.d','source/helloWorld.d']) diff --git a/test/D/di/VariantDirImage/SConstruct_template b/test/D/di/VariantDirImage/SConstruct_template new file mode 100644 index 0000000000..1def3d9633 --- /dev/null +++ b/test/D/di/VariantDirImage/SConstruct_template @@ -0,0 +1,15 @@ +# -*- mode:python; coding:utf-8; -*- + +import os + +DefaultEnvironment(tools=[]) + +env = Environment( + tools=['link','ar' ,'{}'], + DPATH=['include'], + DI_FILE_DIR='build/include' +) + + +SConscript('hws/SConscript',exports=['env'],variant_dir="build") + diff --git a/test/D/di/VariantDirImage/hws/SConscript b/test/D/di/VariantDirImage/hws/SConscript new file mode 100644 index 0000000000..3b6e27feb6 --- /dev/null +++ b/test/D/di/VariantDirImage/hws/SConscript @@ -0,0 +1,2 @@ +Import('env') +env.Program('hw', ['helloWorldMain.d','source/helloWorld.d']) diff --git a/test/D/di/VariantDirImage/hws/helloWorldMain.d b/test/D/di/VariantDirImage/hws/helloWorldMain.d new file mode 100644 index 0000000000..419205d9b0 --- /dev/null +++ b/test/D/di/VariantDirImage/hws/helloWorldMain.d @@ -0,0 +1,6 @@ +import helloWorld; + +void main() +{ + go(); +} diff --git a/test/D/di/VariantDirImage/hws/source/helloWorld.d b/test/D/di/VariantDirImage/hws/source/helloWorld.d new file mode 100644 index 0000000000..9912ec0fd8 --- /dev/null +++ b/test/D/di/VariantDirImage/hws/source/helloWorld.d @@ -0,0 +1,5 @@ +import std.stdio; +void go() +{ + writeln("Hello World."); +} From f1a8f268f06d9f6199130b0b05ab88a2e970e999 Mon Sep 17 00:00:00 2001 From: Alex Burton Date: Thu, 6 Jul 2023 20:50:15 +1000 Subject: [PATCH 2/2] DI_FILE_DIR using variant dir passing now, but needs env['VARIANT_DIR'] to be set. --- SCons/Tool/DCommon.py | 2 +- SCons/Tool/dmd.py | 4 ++-- SCons/Tool/gdc.py | 3 ++- SCons/Tool/ldc.py | 4 ++-- test/D/di/Common/common.py | 23 ++++++++++--------- test/D/di/Image/SConstruct_template | 2 +- test/D/di/Image/{helloWorldMain.d => main.d} | 2 +- .../{source/helloWorld.d => parts/part.d} | 0 test/D/di/VariantDirImage/SConstruct_template | 6 ++--- test/D/di/VariantDirImage/hws/SConscript | 5 +++- .../hws/{helloWorldMain.d => main.d} | 2 +- .../hws/{source/helloWorld.d => parts/part.d} | 0 12 files changed, 28 insertions(+), 25 deletions(-) rename test/D/di/Image/{helloWorldMain.d => main.d} (55%) rename test/D/di/Image/{source/helloWorld.d => parts/part.d} (100%) rename test/D/di/VariantDirImage/hws/{helloWorldMain.d => main.d} (55%) rename test/D/di/VariantDirImage/hws/{source/helloWorld.d => parts/part.d} (100%) diff --git a/SCons/Tool/DCommon.py b/SCons/Tool/DCommon.py index 35f8f3d6e9..f8bdffa93f 100644 --- a/SCons/Tool/DCommon.py +++ b/SCons/Tool/DCommon.py @@ -65,7 +65,7 @@ def DObjectEmitter(target,source,env): di_file_suffix = env.subst('$DI_FILE_SUFFIX', target=target, source=source) file_base = Path(target[0].get_path()).stem # print(f'DObjectEmitter: {di_file_dir}/*{file_base}*{di_file_suffix}') - target.append(env.fs.File(f"{file_base}{di_file_suffix}", di_file_dir)) + target.append(env.fs.File(Path(di_file_dir,f"{file_base}{di_file_suffix}"))) # print("New Target:%s"%" ".join([str(t) for t in target])) return (target,source) diff --git a/SCons/Tool/dmd.py b/SCons/Tool/dmd.py index c3ac0ca6f0..d88fa3e265 100644 --- a/SCons/Tool/dmd.py +++ b/SCons/Tool/dmd.py @@ -96,7 +96,7 @@ def generate(env) -> None: env['_DVERFLAGS'] = '${_concat(DVERPREFIX, DVERSIONS, DVERSUFFIX, __env__)}' env['_DDEBUGFLAGS'] = '${_concat(DDEBUGPREFIX, DDEBUG, DDEBUGSUFFIX, __env__)}' - env['_DI_FLAGS'] = "${DI_FILE_DIR and DI_FILE_DIR_PREFIX+DI_FILE_DIR+DI_FILE_DIR_SUFFFIX}" + env['_DI_FLAGS'] = "${DI_FILE_DIR and DI_FILE_DIR_PREFIX+VARIANT_DIR+DI_FILE_DIR+DI_FILE_DIR_SUFFFIX}" env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}' @@ -121,9 +121,9 @@ def generate(env) -> None: env['DFLAGSUFFIX'] = '' env['DFILESUFFIX'] = '.d' + env['VARIANT_DIR'] = '' env['DI_FILE_DIR'] = '' env['DI_FILE_SUFFIX'] = '.di' - env['DI_FILE_DIR_PREFIX'] = '-Hd=' env['DI_FILE_DIR_SUFFFIX'] = '' diff --git a/SCons/Tool/gdc.py b/SCons/Tool/gdc.py index 9f29d72e29..44da26b527 100644 --- a/SCons/Tool/gdc.py +++ b/SCons/Tool/gdc.py @@ -67,7 +67,7 @@ def generate(env) -> None: env['_DINCFLAGS'] = '${_concat(DINCPREFIX, DPATH, DINCSUFFIX, __env__, RDirs, TARGET, SOURCE)}' env['_DVERFLAGS'] = '${_concat(DVERPREFIX, DVERSIONS, DVERSUFFIX, __env__)}' env['_DDEBUGFLAGS'] = '${_concat(DDEBUGPREFIX, DDEBUG, DDEBUGSUFFIX, __env__)}' - env['_DI_FLAGS'] = "${DI_FILE_DIR and DI_FILE_DIR_PREFIX+DI_FILE_DIR+DI_FILE_DIR_SUFFFIX}" + env['_DI_FLAGS'] = "${DI_FILE_DIR and DI_FILE_DIR_PREFIX+VARIANT_DIR+DI_FILE_DIR+DI_FILE_DIR_SUFFFIX}" env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}' env['SHDC'] = '$DC' @@ -91,6 +91,7 @@ def generate(env) -> None: env['DFLAGSUFFIX'] = '' env['DFILESUFFIX'] = '.d' + env['VARIANT_DIR'] = '' env['DI_FILE_DIR'] = '' env['DI_FILE_SUFFIX'] = '.di' env['DI_FILE_DIR_PREFIX'] = '-Hd' diff --git a/SCons/Tool/ldc.py b/SCons/Tool/ldc.py index 5fb60705a2..4d31745dd0 100644 --- a/SCons/Tool/ldc.py +++ b/SCons/Tool/ldc.py @@ -72,7 +72,7 @@ def generate(env) -> None: env['_DVERFLAGS'] = '${_concat(DVERPREFIX, DVERSIONS, DVERSUFFIX, __env__)}' env['_DDEBUGFLAGS'] = '${_concat(DDEBUGPREFIX, DDEBUG, DDEBUGSUFFIX, __env__)}' - env['_DI_FLAGS'] = "${DI_FILE_DIR and DI_FILE_DIR_PREFIX+DI_FILE_DIR+DI_FILE_DIR_SUFFFIX}" + env['_DI_FLAGS'] = "${DI_FILE_DIR and DI_FILE_DIR_PREFIX+VARIANT_DIR+DI_FILE_DIR+DI_FILE_DIR_SUFFFIX}" env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}' @@ -97,9 +97,9 @@ def generate(env) -> None: env['DFLAGSUFFIX'] = '' env['DFILESUFFIX'] = '.d' + env['VARIANT_DIR'] = '' env['DI_FILE_DIR'] = '' env['DI_FILE_SUFFIX'] = '.di' - env['DI_FILE_DIR_PREFIX'] = '-Hd=' env['DI_FILE_DIR_SUFFFIX'] = '' diff --git a/test/D/di/Common/common.py b/test/D/di/Common/common.py index 5097ba0bd4..866ace75e9 100644 --- a/test/D/di/Common/common.py +++ b/test/D/di/Common/common.py @@ -43,7 +43,8 @@ def testForTool(tool): if not isExecutableOfToolAvailable(test, tool) : test.skip_test("Required executable for tool '{0}' not found, skipping test.\n".format(tool)) - for img in ["Image","VariantDirImage"]: + for img in ["VariantDirImage","Image"]: + if img == "VariantDirImage": buildPrefix = "build/" sourcePrefix = "hws/" @@ -57,34 +58,34 @@ def testForTool(tool): test.run(options="--debug=explain") - test.must_exist(buildPrefix + 'source/helloWorld.o') - test.must_exist(buildPrefix + 'helloWorldMain.o') - test.must_exist(buildPrefix + 'include/helloWorld.di') + test.must_exist(buildPrefix + 'parts/part.o') + test.must_exist(buildPrefix + 'main.o') + test.must_exist(buildPrefix + 'include/part.di') test.must_exist(buildPrefix + 'hw') test.run(program=test.workpath(buildPrefix + 'hw'+TestSCons._exe)) test.fail_test(test.stdout() != 'Hello World.\n') #add a comment and test that this doesn't result in a complete rebuild of all the files that include helloWorld.d because the comment doesn't change helloWorld.di - test.write(sourcePrefix + "source/helloWorld.d",'''import std.stdio; + test.write(sourcePrefix + "parts/part.d",'''import std.stdio; void go() { //comment writeln("Hello World."); }''') - test.not_up_to_date(buildPrefix + "source/helloWorld.o") - test.up_to_date(buildPrefix + "helloWorldMain.o") + test.not_up_to_date(buildPrefix + "parts/part.o") + test.up_to_date(buildPrefix + "main.o",options='--debug=explain') test.up_to_date(buildPrefix + "hw") test.run("-c") - test.must_not_exist(buildPrefix + 'source/helloWorld.o') - test.must_not_exist(buildPrefix + 'helloWorldMain.o') - test.must_not_exist(buildPrefix + 'include/helloWorld.di') + test.must_not_exist(buildPrefix + 'parts/part.o') + test.must_not_exist(buildPrefix + 'main.o') + test.must_not_exist(buildPrefix + 'include/part.di') test.must_not_exist(buildPrefix + 'hw') - test.pass_test() + test.pass_test() # Local Variables: # tab-width:4 # indent-tabs-mode:nil diff --git a/test/D/di/Image/SConstruct_template b/test/D/di/Image/SConstruct_template index 5e7d5cd595..1153d30b82 100644 --- a/test/D/di/Image/SConstruct_template +++ b/test/D/di/Image/SConstruct_template @@ -10,4 +10,4 @@ env = Environment( DI_FILE_DIR='include' ) -env.Program('hw', ['helloWorldMain.d','source/helloWorld.d']) +env.Program('hw', ['main.d','parts/part.d']) diff --git a/test/D/di/Image/helloWorldMain.d b/test/D/di/Image/main.d similarity index 55% rename from test/D/di/Image/helloWorldMain.d rename to test/D/di/Image/main.d index 419205d9b0..b9804752d9 100644 --- a/test/D/di/Image/helloWorldMain.d +++ b/test/D/di/Image/main.d @@ -1,4 +1,4 @@ -import helloWorld; +import part; void main() { diff --git a/test/D/di/Image/source/helloWorld.d b/test/D/di/Image/parts/part.d similarity index 100% rename from test/D/di/Image/source/helloWorld.d rename to test/D/di/Image/parts/part.d diff --git a/test/D/di/VariantDirImage/SConstruct_template b/test/D/di/VariantDirImage/SConstruct_template index 1def3d9633..05b753e107 100644 --- a/test/D/di/VariantDirImage/SConstruct_template +++ b/test/D/di/VariantDirImage/SConstruct_template @@ -6,10 +6,8 @@ DefaultEnvironment(tools=[]) env = Environment( tools=['link','ar' ,'{}'], - DPATH=['include'], - DI_FILE_DIR='build/include' + VARIANT_DIR='build/' ) - -SConscript('hws/SConscript',exports=['env'],variant_dir="build") +SConscript('hws/SConscript',exports=['env'],variant_dir="build",duplicate=False) diff --git a/test/D/di/VariantDirImage/hws/SConscript b/test/D/di/VariantDirImage/hws/SConscript index 3b6e27feb6..a3401fb5b2 100644 --- a/test/D/di/VariantDirImage/hws/SConscript +++ b/test/D/di/VariantDirImage/hws/SConscript @@ -1,2 +1,5 @@ Import('env') -env.Program('hw', ['helloWorldMain.d','source/helloWorld.d']) + + +o = env.Object('parts/part.d',DI_FILE_DIR='include')[0] +env.Program('hw', ['main.d',o],DPATH='include') diff --git a/test/D/di/VariantDirImage/hws/helloWorldMain.d b/test/D/di/VariantDirImage/hws/main.d similarity index 55% rename from test/D/di/VariantDirImage/hws/helloWorldMain.d rename to test/D/di/VariantDirImage/hws/main.d index 419205d9b0..b9804752d9 100644 --- a/test/D/di/VariantDirImage/hws/helloWorldMain.d +++ b/test/D/di/VariantDirImage/hws/main.d @@ -1,4 +1,4 @@ -import helloWorld; +import part; void main() { diff --git a/test/D/di/VariantDirImage/hws/source/helloWorld.d b/test/D/di/VariantDirImage/hws/parts/part.d similarity index 100% rename from test/D/di/VariantDirImage/hws/source/helloWorld.d rename to test/D/di/VariantDirImage/hws/parts/part.d