Skip to content
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

New AutotoolsDeps, AutotoolsToolchain helpers in conan.tools.gnu #8457

Merged
merged 64 commits into from Mar 29, 2021

Conversation

memsharded
Copy link
Member

@memsharded memsharded commented Feb 8, 2021

Changelog: Feature: New AutotoolsDeps, AutotoolsToolchain helpers in conan.tools.gnu
Docs: conan-io/docs#2057

Close #7070 (will invert the logic in _GLIBCXX_USE_CXX11_ABI)

if hasattr(self._conanfile, 'settings_build'):
os_build, arch_build = get_build_os_arch(self._conanfile)
else:
# FIXME: Why not use 'os_build' and 'arch_build' from conanfile.settings?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's new helper, can we avoid all these os_build/arch_build mess and just use modern two-profile approach?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, definitely, it is very ongoing work, I plan to refactor everything and use the 2 profiles.

os_build, arch_build = get_build_os_arch(self._conanfile)
else:
# FIXME: Why not use 'os_build' and 'arch_build' from conanfile.settings?
os_build = detected_os() or platform.system()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say, that may be going forward, avoid auto-detecting altogether and specify everything explicitly in profile/settings, to ensure it's reproducible?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% agree, there will be no auto-detection here, only deterministic from profiles.

self._conanfile.run(cmd, win_bash=self._win_bash, subsystem=self.subsystem)

def _configure_help_output(self, configure_path):
from six import StringIO # Python 2 and 3 compatible
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the new helper, I think we can avoid python 2 and six

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, ongoing work.

if platform.system() == "Windows":
cmd = "autotoolsdeps.bat && autotools.bat && {}".format(make_program)
else:
cmd = "bash -c 'source autotoolsdeps.sh "\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't hard-code bash here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless it is the only way to make it work reproducibly. The autotoolsdeps.sh, etc are using bash. If we are supporting other shells, we need tests, I don't want to add things into the new codebase that cannot be tested.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the make command is not hard-coded and got from the config.
the same, more or less, should be done for the bash I believe.
also, maybe it's enough to just use plain sh or $SHELL?
I don't think we need advanced bash-specific features, and it would be nice to be portable and require only posix sh.
bash is not always available and not a default shell everywhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The make command is hardcoded, most of the times it doesn't come from config:

make_program = os.getenv("CONAN_MAKE_PROGRAM") or make_program or "make"

I guess you are aware that many recipes in ConanCenter are doing make_program=which("make") or which("mingw32-make") to be able to work on Windows. No config here, but recipes hardcoding it.

Same as bash, hardcoded here:

return which("bash")
.

The fact that they have configs, doesn't mean that they are not hardcoded in the codebase. Same I am doing here, we can discuss some defaults as we gain knowledge, but I am not introducing new hardcoded things.

The new Environment files at the moment only work on bash. If we can generalize them to work on different shells, or to provide different generated files, for different shells, good for me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know there are recipes doing that, as I wrote some of them.
that might be a sign we're not managing things the best way.
in some cases, mingw32-make is valid defaults, in some cases valid default could be nmake or just plain make.
that might be the reason we need to provide helper to deduce sane default based on settings, e.g. it may return MinGW make, nmake, GNU make or BSD make depending on system and compiler.
but that we know already the logic doesn't believe to the AutoToolsBuildEnvironment or recipes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, agree, a helper would be the best. This helper can hardcode some defaults for some given configurations (settings, etc), and always have a [conf] to be able to override it.

But lets wait a bit and have a minimum set of build helpers, just the most common "AutotoolsXXX" ones, that work well and make recipes simpler for a majority of cases, before extracting new helpers like get_make_program(conanfile), when we gain more insights about these defaults, our new helpers will be closer to something stable.

Copy link
Contributor

@SSE4 SSE4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may we try to avoid complicated logic (e.g. platform-specific), at least in the first iteration?

libs = ["-l%s" % library for library in self.libs]

# Ldflags
# TODO: Discuss, should the helper filter frameworks based on compiler?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote to keep the least possible logic in these helpers. if some filtering has to be done, it doesn't belong here. and IMO it's the responsibility of the recipe author to ensure the correct CppInfo is built for the given configuration.


make_program = self._conanfile.conf["tools.gnu"].make_program
if make_program is None:
make_program = "mingw32-make" if platform.system() == "Windows" else "make"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't think it's always desired to enforce mingw32-make on Windows. it should go from the configuration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is probably a sane default in windows, the same as make is in other platforms. But we will see as we keep adding support for other subsystems, I am fine with removing it.


tmp_compilation_flags = copy.copy(self.flags)

if tools.is_apple_os(self._os):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it belongs here as well. let's keep all platform-specific code as minimal as possible, and isolated. the way we did it previously was proven to be fragile and doesn't scale well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, this code is not used at the moment, needs to be worked on.

@@ -0,0 +1,138 @@
import textwrap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this one deserves its own first class generator? and new Virtual*Env generators might be based on that one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet. This could be a first class model, like self.env_info = Environment() in the recipes. This is separated in another branch and will have a separate PR once it is stabilized.

@memsharded memsharded marked this pull request as ready for review March 27, 2021 20:32
@memsharded memsharded added this to the 1.35 milestone Mar 27, 2021
# TODO: tools.XCRun(self._conanfile.settings).sdk_path
# TODO: "-arch", tools.to_apple_arch(self._arch)

def _cxx11_abi_define(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

belongs to conan/tools/_compilers.py?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to factor out to a common place like _compilers.py only when there is a repetition/duplicated code needed somewhere else.

if libcxx == 'libstdc++':
return '_GLIBCXX_USE_CXX11_ABI=0'

def _libcxx(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

belongs to conan/tools/_compilers.py?

# FIXME: Use settings, not platform Not always defined :(
# os_ = self._conanfile.settings_build.get_safe("os")
if platform.system() == "Windows":
build_env.save_bat("conanbuildenv.bat")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name is too generic? may overwrite other generators, if multiple are used together...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conanxxxx filenames are generated by Conan (probably we should document this more explicitly too).
This filename is automatically used by self.run() and is the same filename generated by VirtualEnv (to be automatically injected too). The idea is that this file is already the aggregation of the necessary build environments, in a single file, oriented also to make user life easier at the consumer flow.

Ideas welcome, any suggestion of other filename?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if I got the idea. what if we add similar generator e.g. for premake, which will also need VirtualEnv.
and what if project uses both autotoolsgen and premake (e.g. it has to sub-directories with different build systems)
now both will try to create conanbuildenv.bat to override each other?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autotools generators do not create conanbuildenv.bat, AutotoolsGen that wraps both Autotools and VirtualEnv does. In the same spirit, if you want to combine Autotools and Premake in an ordered, structured way, you can do it directly in the recipe, aggregating environments before saving conanbuildenv.bat or creating a generator that aggregates them and using it.

@memsharded memsharded merged commit ea15adb into conan-io:develop Mar 29, 2021
@memsharded memsharded deleted the feature/tools_autotools branch March 29, 2021 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] Invert the logic of _GLIBCXX_USE_CXX11_ABI ?
2 participants