-
-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compilation_db and TempFileMunge interference #4275
Comments
As noted in the discord discussion, my recommended way to handle this is to have the compilation database tool replace |
I'm not sure what you mean by "contextual generator". diff --git a/SCons/Tool/compilation_db.py b/SCons/Tool/compilation_db.py
index 9e72fe9a4..39d725722 100644
--- a/SCons/Tool/compilation_db.py
+++ b/SCons/Tool/compilation_db.py
@@ -32,6 +32,7 @@ which is the name that most clang tools search for by default.
import json
import itertools
import fnmatch
+import sys
import SCons
from .cxx import CXXSuffixes
@@ -114,11 +115,13 @@ def compilation_db_entry_action(target, source, env, **kw):
:param kw:
:return: None
"""
-
+ cenv = env["__COMPILATIONDB_ENV"].Clone()
+ cenv['MAXLINELENGTH']=sys.maxsize
+ cenv = env["__COMPILATIONDB_ENV"]
command = env["__COMPILATIONDB_UACTION"].strfunction(
target=env["__COMPILATIONDB_UOUTPUT"],
source=env["__COMPILATIONDB_USOURCE"],
- env=env["__COMPILATIONDB_ENV"],
+ env=cenv,
)
entry = { |
…#4275 with TempFileMunge
…ue just during compilation_db command substitution
After a bit of thought, we just need to change MAXLINELENGTH for the substitution, what do you think about it @acmorrow : TZe-0xff@dac7df3 |
The above is not a great solution, because the |
The code you mention is not the latest I would suggest (please have a look at my branch for a more light fix) From my understanding, this code belongs to the action step and the strfunction call does the substitution directly. My new fix relies on that (and seems to work fine) : changing the MAXLINELENGTH just during this strfunction call. |
You should not Clone() an environment in an Action.. |
As @acmorrow mentioned changing |
Isn't the MAXLINELENGTH overload during the strfunction call the lightest way to do that ? |
Obviously, I read about generators in documentation, but I may benefit from some guidance here. |
Okay, I finally figured what you guys mean by using a generator (the SCons user guide was not helpful ...).
|
As suggested, I tried the |
Just to be crystal clear, here is my proposal (this is typically more flexible than anything replacing MAXLINELENGTH at generation, intervention happens at very last possible moment and does not impact environment in which target will be built) : diff --git a/SCons/Tool/compilation_db.py b/SCons/Tool/compilation_db.py
index 9e72fe9a4..370c68c3f 100644
--- a/SCons/Tool/compilation_db.py
+++ b/SCons/Tool/compilation_db.py
@@ -32,6 +32,7 @@ which is the name that most clang tools search for by default.
import json
import itertools
import fnmatch
+import sys
import SCons
from .cxx import CXXSuffixes
@@ -114,13 +115,21 @@ def compilation_db_entry_action(target, source, env, **kw):
:param kw:
:return: None
"""
-
+
+ # Disable potential TempFileMunge mechanism just for the substitution in following strfunction
+ # by raising MAXLINELENGTH to highest possible integer value
+ org_maxlinelength = env["__COMPILATIONDB_ENV"]['MAXLINELENGTH']
+ env["__COMPILATIONDB_ENV"]['MAXLINELENGTH'] = sys.maxsize
+
command = env["__COMPILATIONDB_UACTION"].strfunction(
target=env["__COMPILATIONDB_UOUTPUT"],
source=env["__COMPILATIONDB_USOURCE"],
env=env["__COMPILATIONDB_ENV"],
)
-
+
+ # restore MAXLINELENGTH once substitution is done
+ env["__COMPILATIONDB_ENV"]['MAXLINELENGTH'] = org_maxlinelength
+
entry = {
"directory": env.Dir("#").abspath,
"command": command,
|
That's fine as long as you're not building in paralllel.. (only -j 1 is guaranteed to not step on another build step) I have another solution I'll be PR'ing shortly. |
…line), also extending serveral APIs to allow specifying an overrides dictionary which would override (at the last minute) any envvar or potentially env TARGET/SOURCE when subst is being called a subst() or subst_list(). Tests created. Docs still need to be updated.
The issue with this solution is if you build in parallel you may have a real compile step run inbetween changing and saving, and restoring MAXLINELENGTH. I've just posted PR #4278 as another solution. |
You're absolutely right ! The original environment shall remain untouched at all (substitution) times. We actually use parallel build so I will be able to test your fix in another environment. |
Good point. I have the original repro SConstruct from above, I'll wrap it in a test case, or add to an existing testcase possibly later today. But, If you'd like to give it a try, you'll have to create a branch of my branch and then PR back to my branch. |
…#4275 with TempFileMunge
…#4275 with TempFileMunge
Added specific test for Compilation Database to reproduce issue SCons#4275…
Solution for Issue #4275 (Compilation db uses TEMPFILE generated command line instead of the plain command line)
Describe the bug
Using compilation_db tool in a build where command line exceeds MAXLINELENGTH triggers the TempFileMunge mechanism (which creates temporary files to put command line into) leads to a unusable compilation_database.json (listed commands are not valid since relying on temporary files).
Required information
Link to SCons Users thread discussing your issue.
https://discord.com/channels/571796279483564041/571796280146133047/1045026901330239599
Version of SCons
Version of Python
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:01:55) [MSC v.1900 32 bit (Intel)] on win32
Which python distribution if applicable (python.org, cygwin, anaconda, macports, brew,etc)
python.org
How you installed SCons
pip
What Platform are you on? (Linux/Windows and which version)
Windows 10
SConstruct
src/main.c
How you invoke scons (The command line you're using "scons --flags some_arguments")
scons
Output
compile_commands.json
The text was updated successfully, but these errors were encountered: