[Issue 14681] New: Add a way to specify a file import's contents on the command line

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jun 10 21:40:43 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14681

          Issue ID: 14681
           Summary: Add a way to specify a file import's contents on the
                    command line
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: yebblies at gmail.com

C/C++ compilers generally have the ability to set preprocessor symbols from the
command line.  While dmd's -version=ident covers most use cases, it is
sometimes useful to set the symbol to a specific value and access this inside
the program.

eg -DVERSION=3

With DMD this can be done by creating a file and using -J/import(), but there
is no way to set the value directly on the command line.

My proposed syntax to extend -J/import() to allow setting a value:
dmd -J:key=value main.d

Then in the program the import() syntax is used to retrieve the value:
static assert(import(":key") == "value");

The ':' prefix allows the compiler to tell apart import paths and key/value
pairs.

--


More information about the Digitalmars-d-bugs mailing list