From 97bfc7e23fe60ddfc5846c7fc2c823f2f5b9d7d8 Mon Sep 17 00:00:00 2001 From: Alex Burton Date: Thu, 11 May 2023 22:10:34 +1000 Subject: Added support for use of .di files, and added tests for three compilers. --- SCons/Tool/DCommon.py | 28 ++++++++++++- SCons/Tool/dmd.py | 14 +++++-- SCons/Tool/gdc.py | 18 +++++--- SCons/Tool/ldc.py | 14 +++++-- test/D/di/Common/__init__.py | 0 test/D/di/Common/common.py | 84 +++++++++++++++++++++++++++++++++++++ test/D/di/Image/SConstruct_template | 15 +++++++ test/D/di/Image/helloWorldMain.d | 6 +++ test/D/di/Image/source/helloWorld.d | 5 +++ test/D/di/sconstest-dmd.py | 37 ++++++++++++++++ test/D/di/sconstest-gdc.py | 37 ++++++++++++++++ test/D/di/sconstest-ldc.py | 37 ++++++++++++++++ 12 files changed, 280 insertions(+), 15 deletions(-) create mode 100644 test/D/di/Common/__init__.py create mode 100644 test/D/di/Common/common.py create mode 100644 test/D/di/Image/SConstruct_template create mode 100644 test/D/di/Image/helloWorldMain.d create mode 100644 test/D/di/Image/source/helloWorld.d create mode 100644 test/D/di/sconstest-dmd.py create mode 100644 test/D/di/sconstest-gdc.py create mode 100644 test/D/di/sconstest-ldc.py diff --git a/SCons/Tool/DCommon.py b/SCons/Tool/DCommon.py index a4f976d..64d1cbc 100644 --- a/SCons/Tool/DCommon.py +++ b/SCons/Tool/DCommon.py @@ -30,7 +30,7 @@ Coded by Russel Winder (russel@winder.org.uk) """ import os.path - +import SCons.Defaults def isD(env, source) -> int: if not source: @@ -57,6 +57,32 @@ def allAtOnceEmitter(target, source, env): env.Clean(target[0], str(target[0]) + '.o') return target, source +def _optWithIxes(pre,x,suf,env,f=lambda x: x, target=None, source=None): +# a single optional argument version of _concat +# print ("_optWithIxes",str(target),str(source)) + if x in env: + l = f(SCons.PathList.PathList([env[x]]).subst_path(env, target, source)) + return pre + str(l[0]) + suf + else: + return "" + +def DObjectEmitter(target,source,env): + if "DINTFDIR" in env: + if (len(target) != 1): + raise Exception("expect only one object target") + targetBase, targetName = os.path.split(SCons.Util.to_String(target[0])) + extraTarget = os.path.join(targetBase,str(env["DINTFDIR"]),targetName[:-len(env["OBJSUFFIX"])] + env["DIFILESUFFIX"]) + target.append(extraTarget) + return (target,source) + +def DStaticObjectEmitter(target,source,env): + target,source = SCons.Defaults.StaticObjectEmitter(target,source,env) + return DObjectEmitter(target,source,env) + +def DSharedObjectEmitter(target,source,env): + target,source = SCons.Defaults.SharedObjectEmitter(target,source,env) + return DObjectEmitter(target,source,env) + # Local Variables: # tab-width:4 # indent-tabs-mode:nil diff --git a/SCons/Tool/dmd.py b/SCons/Tool/dmd.py index 7b2a249..9755c90 100644 --- a/SCons/Tool/dmd.py +++ b/SCons/Tool/dmd.py @@ -87,18 +87,20 @@ def generate(env) -> None: static_obj.add_action('.d', SCons.Defaults.DAction) shared_obj.add_action('.d', SCons.Defaults.ShDAction) - static_obj.add_emitter('.d', SCons.Defaults.StaticObjectEmitter) - shared_obj.add_emitter('.d', SCons.Defaults.SharedObjectEmitter) + static_obj.add_emitter('.d', DCommon.DStaticObjectEmitter) + shared_obj.add_emitter('.d', DCommon.DSharedObjectEmitter) env['DC'] = env.Detect(['dmd', 'ldmd2', 'gdmd']) or 'dmd' - env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS -c -of$TARGET $SOURCES' + env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DINTFDIR -c -of$TARGET $SOURCES' 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['_DINTFDIR'] = '${_optWithIxes(DINTFDIRPREFIX, DINTFDIRKEY, DINTFDIRSUFFIX, __env__, Dirs, TARGET, SOURCE)}' + env['_optWithIxes'] = DCommon._optWithIxes env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}' env['SHDC'] = '$DC' - env['SHDCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS -c -fPIC -of$TARGET $SOURCES' + env['SHDCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DINTFDIR -c -fPIC -of$TARGET $SOURCES' env['DPATH'] = ['#/'] env['DFLAGS'] = [] @@ -117,6 +119,10 @@ def generate(env) -> None: env['DFLAGPREFIX'] = '-' env['DFLAGSUFFIX'] = '' env['DFILESUFFIX'] = '.d' + env['DIFILESUFFIX'] = '.di' + env['DINTFDIRKEY'] = 'DINTFDIR' + env['DINTFDIRPREFIX'] = '-Hd=' + env['DINTFDIRSUFFIX'] = '' env['DLINK'] = '$DC' env['DLINKFLAGS'] = SCons.Util.CLVar('') diff --git a/SCons/Tool/gdc.py b/SCons/Tool/gdc.py index c77e27a..6b34558 100644 --- a/SCons/Tool/gdc.py +++ b/SCons/Tool/gdc.py @@ -59,18 +59,20 @@ def generate(env) -> None: static_obj.add_action('.d', SCons.Defaults.DAction) shared_obj.add_action('.d', SCons.Defaults.ShDAction) - static_obj.add_emitter('.d', SCons.Defaults.StaticObjectEmitter) - shared_obj.add_emitter('.d', SCons.Defaults.SharedObjectEmitter) + static_obj.add_emitter('.d', DCommon.DStaticObjectEmitter) + shared_obj.add_emitter('.d', DCommon.DSharedObjectEmitter) env['DC'] = env.Detect('gdc') or 'gdc' - env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS -c -o $TARGET $SOURCES' + env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DINTFDIR -c -o $TARGET $SOURCES' 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['_DINTFDIR'] = '${_optWithIxes(DINTFDIRPREFIX, DINTFDIRKEY, DINTFDIRSUFFIX, __env__, Dirs, TARGET, SOURCE)}' + env['_optWithIxes'] = DCommon._optWithIxes env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}' env['SHDC'] = '$DC' - env['SHDCOM'] = '$SHDC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS -fPIC -c -o $TARGET $SOURCES' + env['SHDCOM'] = '$SHDC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DINTFDIR -fPIC -c -o $TARGET $SOURCES' env['DPATH'] = ['#/'] env['DFLAGS'] = [] @@ -82,13 +84,17 @@ def generate(env) -> None: env['DINCPREFIX'] = '-I' env['DINCSUFFIX'] = '' - env['DVERPREFIX'] = '-version=' + env['DVERPREFIX'] = '-fversion=' env['DVERSUFFIX'] = '' - env['DDEBUGPREFIX'] = '-debug=' + env['DDEBUGPREFIX'] = '-fdebug=' env['DDEBUGSUFFIX'] = '' env['DFLAGPREFIX'] = '-' env['DFLAGSUFFIX'] = '' env['DFILESUFFIX'] = '.d' + env['DIFILESUFFIX'] = '.di' + env['DINTFDIRKEY'] = 'DINTFDIR' + env['DINTFDIRPREFIX'] = '-Hd' + env['DINTFDIRSUFFIX'] = '' env['DLINK'] = '$DC' env['DLINKFLAGS'] = SCons.Util.CLVar('') diff --git a/SCons/Tool/ldc.py b/SCons/Tool/ldc.py index 7583853..a86d1b6 100644 --- a/SCons/Tool/ldc.py +++ b/SCons/Tool/ldc.py @@ -63,18 +63,20 @@ def generate(env) -> None: static_obj.add_action('.d', SCons.Defaults.DAction) shared_obj.add_action('.d', SCons.Defaults.ShDAction) - static_obj.add_emitter('.d', SCons.Defaults.StaticObjectEmitter) - shared_obj.add_emitter('.d', SCons.Defaults.SharedObjectEmitter) + static_obj.add_emitter('.d', DCommon.DStaticObjectEmitter) + shared_obj.add_emitter('.d', DCommon.DSharedObjectEmitter) env['DC'] = env.Detect('ldc2') or 'ldc2' - env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS -c -of=$TARGET $SOURCES' + env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DINTFDIR -c -of=$TARGET $SOURCES' 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['_DINTFDIR'] = '${_optWithIxes(DINTFDIRPREFIX, DINTFDIRKEY, DINTFDIRSUFFIX, __env__, Dirs, TARGET, SOURCE)}' + env['_optWithIxes'] = DCommon._optWithIxes env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}' env['SHDC'] = '$DC' - env['SHDCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS -c -relocation-model=pic -of=$TARGET $SOURCES' + env['SHDCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DINTFDIR -c -relocation-model=pic -of=$TARGET $SOURCES' env['DPATH'] = ['#/'] env['DFLAGS'] = [] @@ -93,6 +95,10 @@ def generate(env) -> None: env['DFLAGPREFIX'] = '-' env['DFLAGSUFFIX'] = '' env['DFILESUFFIX'] = '.d' + env['DIFILESUFFIX'] = '.di' + env['DINTFDIRKEY'] = 'DINTFDIR' + env['DINTFDIRPREFIX'] = '-Hd=' + env['DINTFDIRSUFFIX'] = '' env['DLINK'] = '$DC' env['DLINKFLAGS'] = SCons.Util.CLVar('') diff --git a/test/D/di/Common/__init__.py b/test/D/di/Common/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/D/di/Common/common.py b/test/D/di/Common/common.py new file mode 100644 index 0000000..a8c844e --- /dev/null +++ b/test/D/di/Common/common.py @@ -0,0 +1,84 @@ +""" +Support functions for all the tests. +""" + +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import TestSCons + +from os.path import abspath, dirname + +import sys +sys.path.insert(1, abspath(dirname(__file__) + '/../../Support')) + +from executablesSearch import isExecutableOfToolAvailable + +def testForTool(tool): + + test = TestSCons.TestSCons() + + 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; +void go() +{ + //comment + writeln("Hello World."); +}''') + + test.not_up_to_date("source/helloWorld.o") + test.up_to_date("helloWorldMain.o 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.pass_test() +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/D/di/Image/SConstruct_template b/test/D/di/Image/SConstruct_template new file mode 100644 index 0000000..478b39e --- /dev/null +++ b/test/D/di/Image/SConstruct_template @@ -0,0 +1,15 @@ +# -*- mode:python; coding:utf-8; -*- + +import os +import SCons.Node + +environment = Environment( + tools=['link','ar' ,'{}'] +) + +environment.Decider("content") + +o1 = environment.Object('source/helloWorld.d',DINTFDIR = "../include")[0] +o2 = environment.Object('helloWorldMain.d',DPATH="include") + +environment.Program('hw', [o2,o1]) diff --git a/test/D/di/Image/helloWorldMain.d b/test/D/di/Image/helloWorldMain.d new file mode 100644 index 0000000..419205d --- /dev/null +++ b/test/D/di/Image/helloWorldMain.d @@ -0,0 +1,6 @@ +import helloWorld; + +void main() +{ + go(); +} diff --git a/test/D/di/Image/source/helloWorld.d b/test/D/di/Image/source/helloWorld.d new file mode 100644 index 0000000..9912ec0 --- /dev/null +++ b/test/D/di/Image/source/helloWorld.d @@ -0,0 +1,5 @@ +import std.stdio; +void go() +{ + writeln("Hello World."); +} diff --git a/test/D/di/sconstest-dmd.py b/test/D/di/sconstest-dmd.py new file mode 100644 index 0000000..df6ddeb --- /dev/null +++ b/test/D/di/sconstest-dmd.py @@ -0,0 +1,37 @@ +""" +Test compiling and executing using the dmd tool. +""" + +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +from Common.common import testForTool +testForTool('dmd') + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/D/di/sconstest-gdc.py b/test/D/di/sconstest-gdc.py new file mode 100644 index 0000000..43bb8eb --- /dev/null +++ b/test/D/di/sconstest-gdc.py @@ -0,0 +1,37 @@ +""" +Test compiling and executing using the gcd tool. +""" + +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +from Common.common import testForTool +testForTool('gdc') + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/D/di/sconstest-ldc.py b/test/D/di/sconstest-ldc.py new file mode 100644 index 0000000..f61efbc --- /dev/null +++ b/test/D/di/sconstest-ldc.py @@ -0,0 +1,37 @@ +""" +Test compiling and executing using the ldc tool. +""" + +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +from Common.common import testForTool +testForTool('ldc') + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: -- cgit v0.12 From cdb7bf554f3e5aef56036ed7587eb9f97b77e5db Mon Sep 17 00:00:00 2001 From: Alex Burton Date: Thu, 11 May 2023 22:18:32 +1000 Subject: added change to CHANGES.txt --- CHANGES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.txt b/CHANGES.txt index d4ad973..f150c4e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -23,6 +23,7 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER calls dunder method __call__. Invoke instance directly." - Python 3.9 dropped the alias base64.decodestring, deprecated since 3.1. Only used in msvs.py. Use base64.decodebytes instead. + - D compilers : added support for generation of .di interface files RELEASE 4.5.2 - Sun, 21 Mar 2023 14:08:29 -0700 -- cgit v0.12 From ae820bd6143c1e6d3b4bc53d331f0f9adafce735 Mon Sep 17 00:00:00 2001 From: Alex Burton Date: Fri, 12 May 2023 10:20:53 +1000 Subject: Fixed circular reference to SCons.Defaults. --- SCons/Tool/DCommon.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/SCons/Tool/DCommon.py b/SCons/Tool/DCommon.py index 64d1cbc..dc12a3c 100644 --- a/SCons/Tool/DCommon.py +++ b/SCons/Tool/DCommon.py @@ -28,9 +28,9 @@ Common code for the various D tools. Coded by Russel Winder (russel@winder.org.uk) 2012-09-06 """ +import SCons.Util import os.path -import SCons.Defaults def isD(env, source) -> int: if not source: @@ -57,7 +57,7 @@ def allAtOnceEmitter(target, source, env): env.Clean(target[0], str(target[0]) + '.o') return target, source -def _optWithIxes(pre,x,suf,env,f=lambda x: x, target=None, source=None): +def _optWithIxes(pre,x,suf,env,f=lambda x: x, target=None, source=None) -> str: # a single optional argument version of _concat # print ("_optWithIxes",str(target),str(source)) if x in env: @@ -76,11 +76,13 @@ def DObjectEmitter(target,source,env): return (target,source) def DStaticObjectEmitter(target,source,env): - target,source = SCons.Defaults.StaticObjectEmitter(target,source,env) + for tgt in target: + tgt.attributes.shared = None return DObjectEmitter(target,source,env) def DSharedObjectEmitter(target,source,env): - target,source = SCons.Defaults.SharedObjectEmitter(target,source,env) + for tgt in target: + tgt.attributes.shared = 1 return DObjectEmitter(target,source,env) # Local Variables: -- cgit v0.12 From 42fc06fb0151a9fbb762e608bcb7f044c872b97f Mon Sep 17 00:00:00 2001 From: Alex Burton Date: Fri, 12 May 2023 10:30:27 +1000 Subject: removed unnecessary __init__.py file --- test/D/di/Common/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test/D/di/Common/__init__.py diff --git a/test/D/di/Common/__init__.py b/test/D/di/Common/__init__.py deleted file mode 100644 index e69de29..0000000 -- cgit v0.12 From e9c17c7d71127539717f4084e43e449af4995e81 Mon Sep 17 00:00:00 2001 From: Alex Burton Date: Fri, 12 May 2023 10:41:24 +1000 Subject: Update copyright in test python. --- test/D/di/Common/common.py | 12 ++++++------ test/D/di/sconstest-dmd.py | 12 ++++++------ test/D/di/sconstest-gdc.py | 12 ++++++------ test/D/di/sconstest-ldc.py | 12 ++++++------ 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/test/D/di/Common/common.py b/test/D/di/Common/common.py index a8c844e..6ca40f9 100644 --- a/test/D/di/Common/common.py +++ b/test/D/di/Common/common.py @@ -1,9 +1,6 @@ -""" -Support functions for all the tests. -""" - +# MIT License # -# __COPYRIGHT__ +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -23,7 +20,10 @@ Support functions for all the tests. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# + +""" +Test D compilers use of .di files +""" __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" diff --git a/test/D/di/sconstest-dmd.py b/test/D/di/sconstest-dmd.py index df6ddeb..1798cb1 100644 --- a/test/D/di/sconstest-dmd.py +++ b/test/D/di/sconstest-dmd.py @@ -1,9 +1,6 @@ -""" -Test compiling and executing using the dmd tool. -""" - +# MIT License # -# __COPYRIGHT__ +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -23,7 +20,10 @@ Test compiling and executing using the dmd tool. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# + +""" +Test dmd use of .di files +""" __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" diff --git a/test/D/di/sconstest-gdc.py b/test/D/di/sconstest-gdc.py index 43bb8eb..1db1d3b 100644 --- a/test/D/di/sconstest-gdc.py +++ b/test/D/di/sconstest-gdc.py @@ -1,9 +1,6 @@ -""" -Test compiling and executing using the gcd tool. -""" - +# MIT License # -# __COPYRIGHT__ +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -23,7 +20,10 @@ Test compiling and executing using the gcd tool. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# + +""" +Test gdc use of .di files +""" __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" diff --git a/test/D/di/sconstest-ldc.py b/test/D/di/sconstest-ldc.py index f61efbc..07fd089 100644 --- a/test/D/di/sconstest-ldc.py +++ b/test/D/di/sconstest-ldc.py @@ -1,9 +1,6 @@ -""" -Test compiling and executing using the ldc tool. -""" - +# MIT License # -# __COPYRIGHT__ +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -23,7 +20,10 @@ Test compiling and executing using the ldc tool. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# + +""" +Test ldc use of .di files +""" __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -- cgit v0.12 From f7126c269654b6b99af6b0e932b7865c459f2037 Mon Sep 17 00:00:00 2001 From: Alex Burton Date: Fri, 12 May 2023 10:52:37 +1000 Subject: Added documentation of di file environment variables. --- SCons/Tool/DCommon.xml | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/SCons/Tool/DCommon.xml b/SCons/Tool/DCommon.xml index 55da85d..9b5288f 100644 --- a/SCons/Tool/DCommon.xml +++ b/SCons/Tool/DCommon.xml @@ -350,6 +350,45 @@ See also &cv-link-DLINKFLAGS; for linking static objects. + + + + Suffix of d include files default is .di + + + + + + + +Suffix of d include files default is .di + + + + + + + +Path where .di files will be generated + + + + + + + +Prefix to send the di path argument to compiler + + + + + + + +Suffix to send the di path argument to compiler + + + -- cgit v0.12 From 087016f69ff32e273f8998c30620e678bdf1f1aa Mon Sep 17 00:00:00 2001 From: Alex Burton Date: Fri, 12 May 2023 11:10:17 +1000 Subject: added line to release.txt --- RELEASE.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE.txt b/RELEASE.txt index bafda47..7a522f3 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -16,7 +16,7 @@ Here is a summary of the changes since 4.5.2: NEW FUNCTIONALITY ----------------- -- List new features (presumably why a checkpoint is being released) +- D compilers : added support for generation of .di interface files DEPRECATED FUNCTIONALITY ------------------------ -- cgit v0.12 From 59ddff997130ed7ac691d63d7069fd9acf5b35e1 Mon Sep 17 00:00:00 2001 From: Alex Burton Date: Fri, 12 May 2023 11:12:18 +1000 Subject: removed duplicate flag documentation --- SCons/Tool/DCommon.xml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/SCons/Tool/DCommon.xml b/SCons/Tool/DCommon.xml index 9b5288f..30a86f9 100644 --- a/SCons/Tool/DCommon.xml +++ b/SCons/Tool/DCommon.xml @@ -353,14 +353,6 @@ See also &cv-link-DLINKFLAGS; for linking static objects. - Suffix of d include files default is .di - - - - - - - Suffix of d include files default is .di -- cgit v0.12 From a3646bd6eca2028bd7c3dece7883a702bd68ff13 Mon Sep 17 00:00:00 2001 From: Alex Burton Date: Fri, 12 May 2023 12:03:15 +1000 Subject: Removed optWithIxes in favour of existing concat function. DINTFDIR is now a list so that it works with concat, although only one di path makes sense. --- SCons/Tool/DCommon.py | 13 ++----------- SCons/Tool/DCommon.xml | 2 +- SCons/Tool/dmd.py | 5 ++--- SCons/Tool/gdc.py | 5 ++--- SCons/Tool/ldc.py | 5 ++--- 5 files changed, 9 insertions(+), 21 deletions(-) diff --git a/SCons/Tool/DCommon.py b/SCons/Tool/DCommon.py index dc12a3c..b4c5d85 100644 --- a/SCons/Tool/DCommon.py +++ b/SCons/Tool/DCommon.py @@ -28,9 +28,9 @@ Common code for the various D tools. Coded by Russel Winder (russel@winder.org.uk) 2012-09-06 """ -import SCons.Util import os.path +import SCons.Util def isD(env, source) -> int: if not source: @@ -57,17 +57,8 @@ def allAtOnceEmitter(target, source, env): env.Clean(target[0], str(target[0]) + '.o') return target, source -def _optWithIxes(pre,x,suf,env,f=lambda x: x, target=None, source=None) -> str: -# a single optional argument version of _concat -# print ("_optWithIxes",str(target),str(source)) - if x in env: - l = f(SCons.PathList.PathList([env[x]]).subst_path(env, target, source)) - return pre + str(l[0]) + suf - else: - return "" - def DObjectEmitter(target,source,env): - if "DINTFDIR" in env: + if "DINTFDIR" in env and len(env["DINTFDIR"]): if (len(target) != 1): raise Exception("expect only one object target") targetBase, targetName = os.path.split(SCons.Util.to_String(target[0])) diff --git a/SCons/Tool/DCommon.xml b/SCons/Tool/DCommon.xml index 30a86f9..636329c 100644 --- a/SCons/Tool/DCommon.xml +++ b/SCons/Tool/DCommon.xml @@ -358,7 +358,7 @@ Suffix of d include files default is .di - + Path where .di files will be generated diff --git a/SCons/Tool/dmd.py b/SCons/Tool/dmd.py index 9755c90..4eb3f89 100644 --- a/SCons/Tool/dmd.py +++ b/SCons/Tool/dmd.py @@ -95,8 +95,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['_DINTFDIR'] = '${_optWithIxes(DINTFDIRPREFIX, DINTFDIRKEY, DINTFDIRSUFFIX, __env__, Dirs, TARGET, SOURCE)}' - env['_optWithIxes'] = DCommon._optWithIxes + env['_DINTFDIR'] = '${_concat(DINTFDIRPREFIX, DINTFDIR, DINTFDIRSUFFIX, __env__, Dirs, TARGET, SOURCE)}' env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}' env['SHDC'] = '$DC' @@ -106,6 +105,7 @@ def generate(env) -> None: env['DFLAGS'] = [] env['DVERSIONS'] = [] env['DDEBUG'] = [] + env['DINTFDIR'] = [] if env['DC']: DCommon.addDPATHToEnv(env, env['DC']) @@ -120,7 +120,6 @@ def generate(env) -> None: env['DFLAGSUFFIX'] = '' env['DFILESUFFIX'] = '.d' env['DIFILESUFFIX'] = '.di' - env['DINTFDIRKEY'] = 'DINTFDIR' env['DINTFDIRPREFIX'] = '-Hd=' env['DINTFDIRSUFFIX'] = '' diff --git a/SCons/Tool/gdc.py b/SCons/Tool/gdc.py index 6b34558..e0f9888 100644 --- a/SCons/Tool/gdc.py +++ b/SCons/Tool/gdc.py @@ -67,8 +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['_DINTFDIR'] = '${_optWithIxes(DINTFDIRPREFIX, DINTFDIRKEY, DINTFDIRSUFFIX, __env__, Dirs, TARGET, SOURCE)}' - env['_optWithIxes'] = DCommon._optWithIxes + env['_DINTFDIR'] = '${_concat(DINTFDIRPREFIX, DINTFDIR, DINTFDIRSUFFIX, __env__, Dirs, TARGET, SOURCE)}' env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}' env['SHDC'] = '$DC' @@ -78,6 +77,7 @@ def generate(env) -> None: env['DFLAGS'] = [] env['DVERSIONS'] = [] env['DDEBUG'] = [] + env['DINTFDIR'] = [] if env['DC']: DCommon.addDPATHToEnv(env, env['DC']) @@ -92,7 +92,6 @@ def generate(env) -> None: env['DFLAGSUFFIX'] = '' env['DFILESUFFIX'] = '.d' env['DIFILESUFFIX'] = '.di' - env['DINTFDIRKEY'] = 'DINTFDIR' env['DINTFDIRPREFIX'] = '-Hd' env['DINTFDIRSUFFIX'] = '' diff --git a/SCons/Tool/ldc.py b/SCons/Tool/ldc.py index a86d1b6..8d9f920 100644 --- a/SCons/Tool/ldc.py +++ b/SCons/Tool/ldc.py @@ -71,8 +71,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['_DINTFDIR'] = '${_optWithIxes(DINTFDIRPREFIX, DINTFDIRKEY, DINTFDIRSUFFIX, __env__, Dirs, TARGET, SOURCE)}' - env['_optWithIxes'] = DCommon._optWithIxes + env['_DINTFDIR'] = '${_concat(DINTFDIRPREFIX, DINTFDIR, DINTFDIRSUFFIX, __env__, Dirs, TARGET, SOURCE)}' env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}' env['SHDC'] = '$DC' @@ -82,6 +81,7 @@ def generate(env) -> None: env['DFLAGS'] = [] env['DVERSIONS'] = [] env['DDEBUG'] = [] + env['DINTFDIR'] = [] if env['DC']: DCommon.addDPATHToEnv(env, env['DC']) @@ -96,7 +96,6 @@ def generate(env) -> None: env['DFLAGSUFFIX'] = '' env['DFILESUFFIX'] = '.d' env['DIFILESUFFIX'] = '.di' - env['DINTFDIRKEY'] = 'DINTFDIR' env['DINTFDIRPREFIX'] = '-Hd=' env['DINTFDIRSUFFIX'] = '' -- cgit v0.12 From be9392e26a4bb8e9b8f6f8534aec709cbb280f1b Mon Sep 17 00:00:00 2001 From: Alex Burton Date: Fri, 12 May 2023 14:57:34 +1000 Subject: removed unnecessary decider selection --- test/D/di/Image/SConstruct_template | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/D/di/Image/SConstruct_template b/test/D/di/Image/SConstruct_template index 478b39e..d3e4dcc 100644 --- a/test/D/di/Image/SConstruct_template +++ b/test/D/di/Image/SConstruct_template @@ -7,8 +7,6 @@ environment = Environment( tools=['link','ar' ,'{}'] ) -environment.Decider("content") - o1 = environment.Object('source/helloWorld.d',DINTFDIR = "../include")[0] o2 = environment.Object('helloWorldMain.d',DPATH="include") -- cgit v0.12 From 62b0f4e604ad633d1ec51fc2723bcdcf52ce8b09 Mon Sep 17 00:00:00 2001 From: Alex Burton Date: Fri, 12 May 2023 15:02:01 +1000 Subject: DefaultEnvironment optimisation. --- test/D/di/Image/SConstruct_template | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/D/di/Image/SConstruct_template b/test/D/di/Image/SConstruct_template index d3e4dcc..bd33320 100644 --- a/test/D/di/Image/SConstruct_template +++ b/test/D/di/Image/SConstruct_template @@ -1,7 +1,8 @@ # -*- mode:python; coding:utf-8; -*- import os -import SCons.Node + +DefaultEnvironment(tools=[]) environment = Environment( tools=['link','ar' ,'{}'] -- cgit v0.12 From a094046a4ae0d81a58606559382281544e2f3356 Mon Sep 17 00:00:00 2001 From: Alex Burton Date: Fri, 12 May 2023 15:02:14 +1000 Subject: Uncesseray revision stuff. --- test/D/di/sconstest-dmd.py | 2 -- test/D/di/sconstest-gdc.py | 2 -- test/D/di/sconstest-ldc.py | 2 -- 3 files changed, 6 deletions(-) diff --git a/test/D/di/sconstest-dmd.py b/test/D/di/sconstest-dmd.py index 1798cb1..84833d7 100644 --- a/test/D/di/sconstest-dmd.py +++ b/test/D/di/sconstest-dmd.py @@ -25,8 +25,6 @@ Test dmd use of .di files """ -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - from Common.common import testForTool testForTool('dmd') diff --git a/test/D/di/sconstest-gdc.py b/test/D/di/sconstest-gdc.py index 1db1d3b..611f53f 100644 --- a/test/D/di/sconstest-gdc.py +++ b/test/D/di/sconstest-gdc.py @@ -25,8 +25,6 @@ Test gdc use of .di files """ -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - from Common.common import testForTool testForTool('gdc') diff --git a/test/D/di/sconstest-ldc.py b/test/D/di/sconstest-ldc.py index 07fd089..06f8941 100644 --- a/test/D/di/sconstest-ldc.py +++ b/test/D/di/sconstest-ldc.py @@ -25,8 +25,6 @@ Test ldc use of .di files """ -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - from Common.common import testForTool testForTool('ldc') -- cgit v0.12 From 38655bb5d62f72519684218dc45a727886cbc9bb Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 19 Jun 2023 23:39:04 +0000 Subject: Clean up and simplify logic. TODO: scons -c isn't removing the .di files. Mainly these changes only work for dmd at present --- SCons/Defaults.py | 3 +++ SCons/Tool/DCommon.py | 14 ++++++++------ SCons/Tool/DCommon.xml | 5 ++--- SCons/Tool/default.xml | 5 ++--- SCons/Tool/dmd.py | 10 +++++++--- SCons/Tool/ldc.py | 9 +++++++-- test/D/di/Image/SConstruct_template | 15 ++++++++++----- 7 files changed, 39 insertions(+), 22 deletions(-) diff --git a/SCons/Defaults.py b/SCons/Defaults.py index 15041a5..a680cb4 100644 --- a/SCons/Defaults.py +++ b/SCons/Defaults.py @@ -677,6 +677,9 @@ def __lib_either_version_flag(env, version_var1, version_var2, flags_var): return None + + + ConstructionEnvironment = { 'BUILDERS': {}, 'SCANNERS': [SCons.Tool.SourceFileScanner], diff --git a/SCons/Tool/DCommon.py b/SCons/Tool/DCommon.py index b4c5d85..d0c07a3 100644 --- a/SCons/Tool/DCommon.py +++ b/SCons/Tool/DCommon.py @@ -58,12 +58,14 @@ def allAtOnceEmitter(target, source, env): return target, source def DObjectEmitter(target,source,env): - if "DINTFDIR" in env and len(env["DINTFDIR"]): - if (len(target) != 1): - raise Exception("expect only one object target") - targetBase, targetName = os.path.split(SCons.Util.to_String(target[0])) - extraTarget = os.path.join(targetBase,str(env["DINTFDIR"]),targetName[:-len(env["OBJSUFFIX"])] + env["DIFILESUFFIX"]) - target.append(extraTarget) + di_file_dir = env.get('DI_FILE_DIR', False) + # TODO: Verify sane DI_FILE_DIR? + if di_file_dir: + di_file_suffix = env.subst('$DI_FILE_SUFFIX', target=target, source=source) + file_base = os.path.basename(target[0].get_path()) + # 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)) + # print("New Target:%s"%" ".join([str(t) for t in target])) return (target,source) def DStaticObjectEmitter(target,source,env): diff --git a/SCons/Tool/DCommon.xml b/SCons/Tool/DCommon.xml index 636329c..6b4ebf1 100644 --- a/SCons/Tool/DCommon.xml +++ b/SCons/Tool/DCommon.xml @@ -1,9 +1,8 @@ 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['_DINTFDIR'] = '${_concat(DINTFDIRPREFIX, DINTFDIR, DINTFDIRSUFFIX, __env__, Dirs, TARGET, SOURCE)}' + + env['_DINTFDIR'] = "${DI_FILE_DIR and DINTFDIRPREFIX+DI_FILE_DIR+DINTFDIRSUFFIX}" + env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}' env['SHDC'] = '$DC' @@ -105,7 +107,6 @@ def generate(env) -> None: env['DFLAGS'] = [] env['DVERSIONS'] = [] env['DDEBUG'] = [] - env['DINTFDIR'] = [] if env['DC']: DCommon.addDPATHToEnv(env, env['DC']) @@ -119,7 +120,10 @@ def generate(env) -> None: env['DFLAGPREFIX'] = '-' env['DFLAGSUFFIX'] = '' env['DFILESUFFIX'] = '.d' - env['DIFILESUFFIX'] = '.di' + + env['DI_FILE_DIR'] = '' + env['DI_FILE_SUFFIX'] = '.di' + env['DINTFDIRPREFIX'] = '-Hd=' env['DINTFDIRSUFFIX'] = '' diff --git a/SCons/Tool/ldc.py b/SCons/Tool/ldc.py index 8d9f920..9fe4343 100644 --- a/SCons/Tool/ldc.py +++ b/SCons/Tool/ldc.py @@ -71,7 +71,9 @@ 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['_DINTFDIR'] = '${_concat(DINTFDIRPREFIX, DINTFDIR, DINTFDIRSUFFIX, __env__, Dirs, TARGET, SOURCE)}' + + env['_DINTFDIR'] = "${DI_FILE_DIR and DINTFDIRPREFIX+DI_FILE_DIR+DINTFDIRSUFFIX}" + env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}' env['SHDC'] = '$DC' @@ -95,7 +97,10 @@ def generate(env) -> None: env['DFLAGPREFIX'] = '-' env['DFLAGSUFFIX'] = '' env['DFILESUFFIX'] = '.d' - env['DIFILESUFFIX'] = '.di' + + env['DI_FILE_DIR'] = '' + env['DI_FILE_SUFFIX'] = '.di' + env['DINTFDIRPREFIX'] = '-Hd=' env['DINTFDIRSUFFIX'] = '' diff --git a/test/D/di/Image/SConstruct_template b/test/D/di/Image/SConstruct_template index bd33320..d734329 100644 --- a/test/D/di/Image/SConstruct_template +++ b/test/D/di/Image/SConstruct_template @@ -4,11 +4,16 @@ import os DefaultEnvironment(tools=[]) -environment = Environment( - tools=['link','ar' ,'{}'] +env = Environment( + tools=['link','ar' ,'{}'], + DPATH=['include'], + DI_FILE_DIR='include' ) -o1 = environment.Object('source/helloWorld.d',DINTFDIR = "../include")[0] -o2 = environment.Object('helloWorldMain.d',DPATH="include") -environment.Program('hw', [o2,o1]) +# 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']) -- cgit v0.12 From aa2d2d3dab51a472dee8742e6e133c38a078144c Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 20 Jun 2023 16:09:35 +0000 Subject: Switch D Scanner logic to prefer .di over .d when satisfying includes per https://dlang.org/dmd-linux.html#interface-files --- SCons/Scanner/D.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SCons/Scanner/D.py b/SCons/Scanner/D.py index 9bc608f..fbb2894 100644 --- a/SCons/Scanner/D.py +++ b/SCons/Scanner/D.py @@ -48,9 +48,11 @@ class D(Classic): # translate dots (package separators) to slashes inc = include.replace('.', '/') - i = SCons.Node.FS.find_file(inc + '.d', (source_dir,) + path) + # According to https://dlang.org/dmd-linux.html#interface-files + # Prefer .di files over .d files when processing includes(imports) + i = SCons.Node.FS.find_file(inc + '.di', (source_dir,) + path) if i is None: - i = SCons.Node.FS.find_file(inc + '.di', (source_dir,) + path) + i = SCons.Node.FS.find_file(inc + '.d', (source_dir,) + path) return i, include def find_include_names(self, node): -- cgit v0.12 From ab642d1295eb4d350404f4402387c166c8f60894 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 20 Jun 2023 16:10:13 +0000 Subject: Use pathlib to get file stem to build D interface filename. Add new DINTFOR and variables to gdc --- SCons/Tool/DCommon.py | 4 ++-- SCons/Tool/gdc.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/SCons/Tool/DCommon.py b/SCons/Tool/DCommon.py index d0c07a3..3cd3dab 100644 --- a/SCons/Tool/DCommon.py +++ b/SCons/Tool/DCommon.py @@ -29,8 +29,8 @@ Coded by Russel Winder (russel@winder.org.uk) 2012-09-06 """ +from pathlib import Path import os.path -import SCons.Util def isD(env, source) -> int: if not source: @@ -62,7 +62,7 @@ def DObjectEmitter(target,source,env): # TODO: Verify sane DI_FILE_DIR? if di_file_dir: di_file_suffix = env.subst('$DI_FILE_SUFFIX', target=target, source=source) - file_base = os.path.basename(target[0].get_path()) + 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)) # print("New Target:%s"%" ".join([str(t) for t in target])) diff --git a/SCons/Tool/gdc.py b/SCons/Tool/gdc.py index e0f9888..4a99edc 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['_DINTFDIR'] = '${_concat(DINTFDIRPREFIX, DINTFDIR, DINTFDIRSUFFIX, __env__, Dirs, TARGET, SOURCE)}' + env['_DINTFDIR'] = "${DI_FILE_DIR and DINTFDIRPREFIX+DI_FILE_DIR+DINTFDIRSUFFIX}" env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}' env['SHDC'] = '$DC' @@ -91,7 +91,8 @@ def generate(env) -> None: env['DFLAGPREFIX'] = '-' env['DFLAGSUFFIX'] = '' env['DFILESUFFIX'] = '.d' - env['DIFILESUFFIX'] = '.di' + env['DI_FILE_DIR'] = '' + env['DI_FILE_SUFFIX'] = '.di' env['DINTFDIRPREFIX'] = '-Hd' env['DINTFDIRSUFFIX'] = '' -- cgit v0.12 From 966dddf8631d77adcaaca4ba6dc37082368647a4 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 20 Jun 2023 16:19:57 +0000 Subject: changed new vars to be DI_FILE_* instead of DINTF*. Updated docs, changes, release --- RELEASE.txt | 6 ++++-- SCons/Tool/DCommon.xml | 8 ++++---- SCons/Tool/dmd.py | 10 +++++----- SCons/Tool/gdc.py | 12 ++++++------ SCons/Tool/ldc.py | 11 +++++------ 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/RELEASE.txt b/RELEASE.txt index b6ab921..ce05c11 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -16,8 +16,10 @@ Here is a summary of the changes since 4.5.2: NEW FUNCTIONALITY ----------------- -- D compilers : added support for generation of .di interface files - +- D compilers : added support for generation of .di interface files. + New variables DI_FILE_DIR, DI_FILE_DIR_PREFIX, DI_FILE_DIR_SUFFIX, + DI_FILE_SUFFIX. + DEPRECATED FUNCTIONALITY ------------------------ diff --git a/SCons/Tool/DCommon.xml b/SCons/Tool/DCommon.xml index 6b4ebf1..80b0b15 100644 --- a/SCons/Tool/DCommon.xml +++ b/SCons/Tool/DCommon.xml @@ -349,7 +349,7 @@ See also &cv-link-DLINKFLAGS; for linking static objects. - + Suffix of d include files default is .di @@ -357,7 +357,7 @@ Suffix of d include files default is .di - + Path where .di files will be generated @@ -365,7 +365,7 @@ Path where .di files will be generated - + Prefix to send the di path argument to compiler @@ -373,7 +373,7 @@ Prefix to send the di path argument to compiler - + Suffix to send the di path argument to compiler diff --git a/SCons/Tool/dmd.py b/SCons/Tool/dmd.py index c61e503..c3ac0ca 100644 --- a/SCons/Tool/dmd.py +++ b/SCons/Tool/dmd.py @@ -91,17 +91,17 @@ def generate(env) -> None: shared_obj.add_emitter('.d', DCommon.DSharedObjectEmitter) env['DC'] = env.Detect(['dmd', 'ldmd2', 'gdmd']) or 'dmd' - env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DINTFDIR -c -of$TARGET $SOURCES' + env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DI_FLAGS -c -of$TARGET $SOURCES' 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['_DINTFDIR'] = "${DI_FILE_DIR and DINTFDIRPREFIX+DI_FILE_DIR+DINTFDIRSUFFIX}" + env['_DI_FLAGS'] = "${DI_FILE_DIR and DI_FILE_DIR_PREFIX+DI_FILE_DIR+DI_FILE_DIR_SUFFFIX}" env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}' env['SHDC'] = '$DC' - env['SHDCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DINTFDIR -c -fPIC -of$TARGET $SOURCES' + env['SHDCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DI_FLAGS -c -fPIC -of$TARGET $SOURCES' env['DPATH'] = ['#/'] env['DFLAGS'] = [] @@ -124,8 +124,8 @@ def generate(env) -> None: env['DI_FILE_DIR'] = '' env['DI_FILE_SUFFIX'] = '.di' - env['DINTFDIRPREFIX'] = '-Hd=' - env['DINTFDIRSUFFIX'] = '' + env['DI_FILE_DIR_PREFIX'] = '-Hd=' + env['DI_FILE_DIR_SUFFFIX'] = '' env['DLINK'] = '$DC' env['DLINKFLAGS'] = SCons.Util.CLVar('') diff --git a/SCons/Tool/gdc.py b/SCons/Tool/gdc.py index 4a99edc..9f29d72 100644 --- a/SCons/Tool/gdc.py +++ b/SCons/Tool/gdc.py @@ -63,21 +63,20 @@ def generate(env) -> None: shared_obj.add_emitter('.d', DCommon.DSharedObjectEmitter) env['DC'] = env.Detect('gdc') or 'gdc' - env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DINTFDIR -c -o $TARGET $SOURCES' + env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DI_FLAGS -c -o $TARGET $SOURCES' 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['_DINTFDIR'] = "${DI_FILE_DIR and DINTFDIRPREFIX+DI_FILE_DIR+DINTFDIRSUFFIX}" + env['_DI_FLAGS'] = "${DI_FILE_DIR and DI_FILE_DIR_PREFIX+DI_FILE_DIR+DI_FILE_DIR_SUFFFIX}" env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}' env['SHDC'] = '$DC' - env['SHDCOM'] = '$SHDC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DINTFDIR -fPIC -c -o $TARGET $SOURCES' + env['SHDCOM'] = '$SHDC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DI_FLAGS -fPIC -c -o $TARGET $SOURCES' env['DPATH'] = ['#/'] env['DFLAGS'] = [] env['DVERSIONS'] = [] env['DDEBUG'] = [] - env['DINTFDIR'] = [] if env['DC']: DCommon.addDPATHToEnv(env, env['DC']) @@ -91,10 +90,11 @@ def generate(env) -> None: env['DFLAGPREFIX'] = '-' env['DFLAGSUFFIX'] = '' env['DFILESUFFIX'] = '.d' + env['DI_FILE_DIR'] = '' env['DI_FILE_SUFFIX'] = '.di' - env['DINTFDIRPREFIX'] = '-Hd' - env['DINTFDIRSUFFIX'] = '' + env['DI_FILE_DIR_PREFIX'] = '-Hd' + env['DI_FILE_DIR_SUFFFIX'] = '' env['DLINK'] = '$DC' env['DLINKFLAGS'] = SCons.Util.CLVar('') diff --git a/SCons/Tool/ldc.py b/SCons/Tool/ldc.py index 9fe4343..5fb6070 100644 --- a/SCons/Tool/ldc.py +++ b/SCons/Tool/ldc.py @@ -67,23 +67,22 @@ def generate(env) -> None: shared_obj.add_emitter('.d', DCommon.DSharedObjectEmitter) env['DC'] = env.Detect('ldc2') or 'ldc2' - env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DINTFDIR -c -of=$TARGET $SOURCES' + env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DI_FLAGS -c -of=$TARGET $SOURCES' 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['_DINTFDIR'] = "${DI_FILE_DIR and DINTFDIRPREFIX+DI_FILE_DIR+DINTFDIRSUFFIX}" + env['_DI_FLAGS'] = "${DI_FILE_DIR and DI_FILE_DIR_PREFIX+DI_FILE_DIR+DI_FILE_DIR_SUFFFIX}" env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}' env['SHDC'] = '$DC' - env['SHDCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DINTFDIR -c -relocation-model=pic -of=$TARGET $SOURCES' + env['SHDCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DI_FLAGS -c -relocation-model=pic -of=$TARGET $SOURCES' env['DPATH'] = ['#/'] env['DFLAGS'] = [] env['DVERSIONS'] = [] env['DDEBUG'] = [] - env['DINTFDIR'] = [] if env['DC']: DCommon.addDPATHToEnv(env, env['DC']) @@ -101,8 +100,8 @@ def generate(env) -> None: env['DI_FILE_DIR'] = '' env['DI_FILE_SUFFIX'] = '.di' - env['DINTFDIRPREFIX'] = '-Hd=' - env['DINTFDIRSUFFIX'] = '' + env['DI_FILE_DIR_PREFIX'] = '-Hd=' + env['DI_FILE_DIR_SUFFFIX'] = '' env['DLINK'] = '$DC' env['DLINKFLAGS'] = SCons.Util.CLVar('') -- cgit v0.12 From 4f362a0e2c52c96c5f637492bfcc7d4a1ca7ee11 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 20 Jun 2023 17:28:42 +0000 Subject: [ci skip] CHANGES.txt added new variables to blurb --- CHANGES.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 9c773bb..7d17c3e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -34,7 +34,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER a .py extension to open a file that is not an absolute path. - SCons test runner now uses pathlib to normalize and compare paths to test files. - - D compilers : added support for generation of .di interface files + - D compilers : added support for generation of .di interface files. + New variables DI_FILE_DIR, DI_FILE_DIR_PREFIX, DI_FILE_DIR_SUFFIX, + DI_FILE_SUFFIX. - Fixed: when using the mingw tool, if an msys2 Python is used (os.sep is '/' rather than the Windows default '\'), certain Configure checks could fail due to the construction of the path to run the compiled check. -- cgit v0.12