[build2] bdep new allows projects names that are invalid c++ namespace names

Klaim - Joël Lamotte mjklaim at gmail.com
Tue Aug 14 13:35:27 UTC 2018


Hello,

There is an minor issue with projects names using characters that are
not allowed
in C++ namespaces. When `bdep new` for example is used and generates code,
it create a namespace name which is invalid in C++ if the project name have some
characters allowed by build2 in target names.
For an example using `-` (dash) see the end of this email.
I think the issue would be similar with other languages which might not allow
different characters than C++.

Suggestion A:
1. allow library name as now (I think it would not be pleasant for users
    if libraries with dashes in names were not allowed);
2. when generating the namespace, change unavailable characters
    to `_` (underscore) trimmed;
3. provide a way to specify the namespace in commands generating code,
in particular `bdep new` (I don't see such an option).

Going this way would however open potential complexity for all variations of how
the code is generated, because it would force you to support tons of
customization
options and that's not really the role of tools like bdep.

So another option:
B. 1. Do not allow project names with names invalid for the specified language
     2. Ignore 1 if one of the options specify to not generate code

That way the user can still do something but will have to create the
code themselve.
And that's the easiest thing to do.

Or
C. Like B but:
Provide a way to specify a namespace/module name (lets be language agnostic)
different than the target name, this one have to be valid in the
specified language,
while the target name can have a different name.

Joël

--------------
Example (the error is because the generated names:

PS G:\perso\experiments> bdep new mylib-versionned -t lib
warning: library name does not start with 'lib'
  info: this package may not be acceptable to some repositories
created new library project mylib-versionned in
G:\perso\experiments\mylib-versionned\
PS G:\perso\experiments> cd .\mylib-versionned\
PS G:\perso\experiments\mylib-versionned> bdep init -C ../build cxx
config.cxx=cl
initializing in project G:\perso\experiments\mylib-versionned\
created configuration G:\perso\experiments\build\ 1
default,forwarded,auto-synchronized
synchronizing:
  new mylib-versionned/0.1.0-a.0.19700101000000
PS G:\perso\experiments\mylib-versionned> b
mkdir ..\build\mylib-versionned\fsdir{mylib-versionned\}
mkdir ..\build\mylib-versionned\tests\fsdir{basics\}
version.in mylib-versionned\version.hxx.in
c++ mylib-versionned\cxx{mylib-versionned}@..\build\mylib-versionned\mylib-versionned\
c++ mylib-versionned\cxx{mylib-versionned}@..\build\mylib-versionned\mylib-versionned\
c++ tests\basics\cxx{driver}@..\build\mylib-versionned\tests\basics\
G:\perso\experiments\mylib-versionned\mylib-versionned/mylib-versionned.hxx(8):
error C2059: syntax error: '-'
G:\perso\experiments\mylib-versionned\mylib-versionned/mylib-versionned.hxx(9):
error C2143: syntax error: missing ';' before '{'
G:\perso\experiments\mylib-versionned\mylib-versionned/mylib-versionned.hxx(9):
error C2447: '{': missing function header (old-style formal list?)
G:\perso\experiments\mylib-versionned\mylib-versionned\mylib-versionned.cxx(8):
error C2059: syntax error: '-'
G:\perso\experiments\mylib-versionned\mylib-versionned\mylib-versionned.cxx(9):
error C2143: syntax error: missing ';' before '{'
G:\perso\experiments\mylib-versionned\mylib-versionned\mylib-versionned.cxx(9):
error C2447: '{': missing function header (old-style formal list?)
G:\perso\experiments\mylib-versionned\mylib-versionned/mylib-versionned.hxx(8):
error C2059: syntax error: '-'
G:\perso\experiments\mylib-versionned\mylib-versionned/mylib-versionned.hxx(9):
error C2143: syntax error: missing ';' before '{'
G:\perso\experiments\mylib-versionned\mylib-versionned/mylib-versionned.hxx(9):
error C2447: '{': missing function header (old-style formal list?)
G:\perso\experiments\mylib-versionned\mylib-versionned\mylib-versionned.cxx(8):
error C2059: syntax error: '-'
G:\perso\experiments\mylib-versionned\mylib-versionned\mylib-versionned.cxx(9):
error C2143: syntax error: missing ';' before '{'
G:\perso\experiments\mylib-versionned\mylib-versionned\mylib-versionned.cxx(9):
error C2447: '{': missing function header (old-style formal list?)
G:\perso\experiments\mylib-versionned\mylib-versionned/mylib-versionned.hxx(8):
error C2059: syntax error: '-'
G:\perso\experiments\mylib-versionned\mylib-versionned/mylib-versionned.hxx(9):
error C2143: syntax error: missing ';' before '{'
G:\perso\experiments\mylib-versionned\mylib-versionned/mylib-versionned.hxx(9):
error C2447: '{': missing function header (old-style formal list?)
G:\perso\experiments\mylib-versionned\tests\basics\driver.cxx(11):
error C2143: syntax error: missing ';' before '-'
G:\perso\experiments\mylib-versionned\tests\basics\driver.cxx(11):
error C2871: 'mylib': a namespace with this name does not exist
G:\perso\experiments\mylib-versionned\tests\basics\driver.cxx(11):
error C2065: 'versionned': undeclared identifier
G:\perso\experiments\mylib-versionned\tests\basics\driver.cxx(17):
error C3861: 'say_hello': identifier not found
G:\perso\experiments\mylib-versionned\tests\basics\driver.cxx(26):
error C3861: 'say_hello': identifier not found
info: failed to update ..\build\dir{mylib-versionned\}

PS G:\perso\experiments\mylib-versionned> b --version
build2 0.8.0-a.0.3cad4e39c8d2
libbutl 0.8.0-a.0.7c665d965c0e
host x86_64-microsoft-win32-msvc14.1
Copyright (c) 2014-2018 Code Synthesis Ltd
This is free software released under the MIT license.
PS G:\perso\experiments\mylib-versionned> bdep --version
bdep 0.8.0-a.0.4a9790b9d826
libbpkg 0.8.0-a.0.0f50af28d1cf
libbutl 0.8.0-a.0.7c665d965c0e
Copyright (c) 2014-2018 Code Synthesis Ltd
This is free software released under the MIT license.



More information about the users mailing list