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

Standard as an option #2042

Closed
wants to merge 39 commits into from
Closed

Conversation

lasote
Copy link
Contributor

@lasote lasote commented Nov 17, 2017

#1799 (part of #2033, but can be completed later)

CHANGED TO USE THE config_options METHOD, BUT AFFECTED BY #2108

  • Very similar to Standard as subsetting: NOT MERGE #2030 but using options instead.
  • Added new mechanism (to discuss) to add programmatically common options like "shared" or now the standard. def options(self, config) method instead of options attribute. Look at the tests.
  • Removed deprecated helpers
  • Added MSBuild() helper that uses VisualStudioBuildEnvironment and the tools to build a vs project.
  • I think this approach is cleaner, with fewer side effects and given that has not been a massive demanded feature, maybe it's reasonable to manage it as an option, only in the packages that declare it. To study (can be done later) if we want to add it somehow to the "conan new" templates.
  • VS14 not forced in test suite, working with 2017

@codecov-io
Copy link

codecov-io commented Nov 20, 2017

Codecov Report

Merging #2042 into develop will decrease coverage by 1.72%.
The diff coverage is 86.73%.

@@             Coverage Diff             @@
##           develop    #2042      +/-   ##
===========================================
- Coverage    95.89%   94.16%   -1.73%     
===========================================
  Files          350      352       +2     
  Lines        28056    28121      +65     
===========================================
- Hits         26904    26481     -423     
- Misses        1152     1640     +488

@lasote lasote changed the title WIP NOT MERGE: Standard as an option Standard as an option Nov 20, 2017
@lasote lasote modified the milestones: 0.29, 0.30 Nov 20, 2017

v98 = v98gnu = v11 = v11gnu = v14 = v14gnu = v17 = v17gnu = None

if not float(clang_version) < 4.0:
Copy link
Member

Choose a reason for hiding this comment

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

Feels a bit hacky this comparison, not saying it doesnt work...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, suggestions?

Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

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

Good job, generally I like it. Please see comments.

if self._cppstd:
if self._cppstd.endswith("gnu"):
ret["CONAN_CMAKE_CXX_STANDARD"] = self._cppstd[:-3]
ret["CONAN_CMAKE_CXX_EXTENSIONS"] = "ON"
Copy link
Member

Choose a reason for hiding this comment

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

Maybe CONAN_CMAKE_CXX_GNU_EXTENSIONS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the variable in CMake is CMAKE_CXX_EXTENSIONS:

set(CMAKE_CXX_EXTENSIONS OFF)
On some platforms, this results in linking to a different library (e.g. -std=c++11 rather than -std=gnu++11). The default behavior is for C++ extensions to be enabled. 

if self.std:
ret.append(self.std)

ret.extend(['/D%s' % lib for lib in self.defines])
Copy link
Member

Choose a reason for hiding this comment

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

defines only if self.std?


def _get_cl_list(self, quotes=True):
if quotes:
ret = ['/I%s' % lib for lib in self.include_paths]
Copy link
Member

Choose a reason for hiding this comment

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

These two lines are identical

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch

@@ -234,6 +234,30 @@ def generate_targets_section(dependencies):
endif()
endmacro()

macro(conan_set_std)
if (CMAKE_VERSION VERSION_LESS "3.1")
if(CONAN_STD_CXX_FLAG)
Copy link
Member

Choose a reason for hiding this comment

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

I don't fully get the CONAN_STD_CXX_FLAG and CONAN_CMAKE_CXX_STANDARD, I guess something Cmake-ish

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CONAN_STD_CXX_FLAG: Only used in case the CMake < 3.1, it is directly the flag to pass to the compiler, because CMake < 3.1 do no support it another way. Includes the -std=XXXX. Conan uses the compilers_info.py to translate to the correct flag depending on each compiler/version.

CONAN_CMAKE_CXX_STANDARD: Used > 3.1. Do not include the -std=XXX is directly the value of the standard, 98, 11, 14, 17. Internally CMake will translate it to the -std=xxx taking also into account the CMAKE_CXX_EXTENSIONS to know if it should like with "gnu++11" or just "c++11".

def add_shared(self, default=False):
self.options.add_option("shared", [True, False], default)

def add_cppstd(self, default=None):
Copy link
Member

Choose a reason for hiding this comment

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

This self.add_cppstd() default to 11 seems a bit weird to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, better to keep it explicit and not optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mhh, maybe it should be defaulted to the compiler's version default?

"compiler": "gcc",
"compiler.libcxx": "libstdc++11",
"compiler.version": "4.9"})
options = MockOptions({"cppstd": "17"})
Copy link
Member

Choose a reason for hiding this comment

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

I am wondering if this should be managed somehow. So you requested cppstd=17, which is impossible, it will be ignored, but it will affect the binary package ID? Maybe should it raise?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably shouldn't be a valid option if you used the "add_cppstd" and will raise because of it. (not in this case of Mock()).
Actually we miss information in the case of Visual Studio, where depending on the revision of the compiler the default standard can change. In visual 2015 rev3 the default is cpp14, and c++11 makes no sense, there is no flag to specify a lower one, but in previous revisions the default was c++11.

def test_variables(self):
# GCC 32
settings = MockSettings({"build_type": "Release",
"arch": "x86",
"compiler": "gcc",
"compiler.libcxx": "libstdc++"})
conanfile = MockConanfile(settings)
conanfile = MockConanfile(settings, MockOptions({}))
Copy link
Member

Choose a reason for hiding this comment

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

Maybe set a default in MockConanFile constructor

self.deps_cpp_info = namedtuple("deps_cpp_info", "sysroot")("/path/to/sysroot")
self.output = TestBufferConanOutput()
if shared is not None:
self.options = namedtuple("options", "shared")(shared)
self.options = Options(PackageOptions({"shared": ["True", "False"]}))
self.options.values = OptionsValues([("shared", shared)])
Copy link
Member

Choose a reason for hiding this comment

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

self.options.shared = True

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's already assigned because of the default value, right? it's not needed to assign it.

default_options= "shared=False"

def options(self, config):
config.add_shared()
Copy link
Member

Choose a reason for hiding this comment

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

How does it looks to add other options than shared & standards when using the options() method?

Copy link
Contributor Author

@lasote lasote Dec 4, 2017

Choose a reason for hiding this comment

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

config.options.add_option("flavour", ["choco", "strawberry", "orange"], "orange")
It has to be added to the docs, of course

error = client.run('create Hello/1.2.1@lasote/stable -o Hello:cppstd=11 -s compiler="Visual Studio" -s '
'compiler.version=14', ignore_error=True)
self.assertTrue(error)
client.save(files)
Copy link
Member

Choose a reason for hiding this comment

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

why save again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not needed.

@memsharded
Copy link
Member

I have a further question: how the default for a certain compiler differs from the selected one: So if I use -o Pkg:cppstd=c++11, and it happens that C++11 is the default for my current settings, then I will be creating another binary with a different package ID which happens to be the same.

@lasote lasote modified the milestones: 0.30, 1.0 Dec 5, 2017
@lasote lasote modified the milestones: 1.0, 1.1 Dec 20, 2017
@lasote lasote removed this from the 1.1 milestone Feb 20, 2018
@lasote
Copy link
Contributor Author

lasote commented Feb 21, 2018

Discarded PR in favor of #2486

@lasote lasote closed this Feb 21, 2018
@ghost ghost removed the stage: review label Feb 21, 2018
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.

4 participants