SCons / scons

SCons - a software construction tool
http://scons.org
MIT License
2.03k stars 311 forks source link

'TryCompile' doesn't work with yacc source files in Scons 4.x #3998

Open jdpipe opened 2 years ago

jdpipe commented 2 years ago

As discussed on Discord and at Stack Overflow:

I have the following little test script in SCons that works file with SCons 3.1.2, but fails with SCons 4.2.0. Can anyone suggest a good workaround?

env = Environment(tools = ['default','yacc','lex','swig'])

yacc_test_text = """
%{
#include <stdio.h>

/* MSVC++ needs this before it can swallow Bison output */
#ifdef _MSC_VER
# define __STDC__
#endif
%}
%token MSG
%start ROOT
%%
ROOT:
    MSG { printf("HELLO"); } 
    ;
%%
"""

def CheckYacc(context):
    context.Message("Checking for Yacc ('%s')... " % context.env.get('YACC'))
    is_ok = context.TryCompile(yacc_test_text,".y")
    context.Result(is_ok)
    return is_ok

conf = Configure(env, custom_tests = {'CheckYacc' : CheckYacc})

conf.env['HAVE_YACC'] = True
if not conf.CheckYacc():
    conf.env['HAVE_YACC'] = False

conf.Finish()

if env['HAVE_YACC']:
    print("yacc is ok")
else:
    print("yacc is borken")

The output in SCons 3.1.1:

john@ovo:~/Desktop/test1$ scons
scons: Reading SConscript files ...
Checking for Yacc ('bison')... yes
yacc is ok
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.

whereas for SCons 4.2.0, I get:

john@ovo:~/Desktop/test1$ scons
scons: Reading SConscript files ...

scons: *** While building `['.sconf_temp/conftest_dd0e1c3dfab0803d28d6c748a4e13339_0SConfActionsContentDummyTarget']' from `['.sconf_temp/conftest_dd0e1c3dfab0803d28d6c748a4e13339_0.y']': Don't know how to build from a source file with suffix `.y'.  Expected a suffix in this list: ['.c', '.m', '.cpp', '.cc', '.cxx', '.c++', '.C++', '.mm', '.C', '.f', '.for', '.ftn', '.fpp', '.FPP', '.F', '.FOR', '.FTN', '.f77', '.F77', '.f90', '.F90', '.f95', '.F95', '.f03', '.F03', '.f08', '.F08', '.s', '.asm', '.ASM', '.spp', '.SPP', '.sx', '.S', '.d'].
File "/home/john/Desktop/test1/SConstruct", line 23, in CheckYacc

Required information

mwichmann commented 2 years ago

As a nitpick (this is not the problem here, and this was already mentioned in chat so this is really just for anyone else that might drop by and read this) - you should save the result of Finish, which will be the configure-modified copy of the original construction environment, so like:

env = conf.Finish()
mwichmann commented 2 years ago

Copied from StackOverflow thread:

This has to do with the requested builder Object() not having rules to translate .y -> .o, which it shouldn't. This only comes into play in newer SCons' because we try to ensure unique temp file names for config steps using the signature of the action used to build such. – @bdbaddog