Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Issue 3541 - Add -oq to dmd (use fully qualified module name as object filename) #563

Merged
merged 2 commits into from over 2 years ago

4 participants

jacob-carlborg Walter Bright Daniel Murphy Timothee Cour
jacob-carlborg

Issue 3541 - Add -oq to dmd (use fully qualified module name as object filename).

Trying this again, I've just updated my fork. I have tested this on Mac OS X by running the Phobos unit tests and they all DO PASS. The command line I used to run the unit tests was "make unittest".

http://d.puremagic.com/issues/show_bug.cgi?id=3541

jacob-carlborg Revert "revert pull 169"
This reverts commit 9d664ad3a00d2a09be3aa67cdebb4d4641cdb42f.
44265f9
src/mars.c
@@ -207,7 +207,7 @@ void verror(Loc loc, const char *format, va_list ap)
207 207
 #endif
208 208
         fprintf(stdmsg, "\n");
209 209
         fflush(stdmsg);
210  
-//halt();
  210
+halt();
3
Daniel Murphy Collaborator

Could you please get rid of this?

I wonder where that came from but it's restored now.

Daniel Murphy Collaborator

Walter adds it in for debugging and it accidentally ended up getting left in the master branch for a couple of weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Walter Bright

It would be nice to also include a pull request for the documentation to add documentation for -oq

Walter Bright WalterBright merged commit cf8c00b into from December 18, 2011
Walter Bright WalterBright closed this December 18, 2011
Walter Bright

Sigh. Windows still fails to build the phobos unittests with this patch. I'm going to have to revert it again. I want to emphasize that existing behavior must not change if -oq is not used - we cannot break peoples' existing build processes.


..\dmd -O -nofloat -w -d -property -L/co -unittest unittest.d std\variant.d std
\stream.d std\socket.d std\socketstream.d std\perf.d std\container.d std\conv.d
std\zip.d std\cstream.d std\loader.d std__fileinit.d std\datebase.d std\re
gex.d std\stdarg.d std\stdint.d std\json.d std\parallelism.d std\gregorian.
d std\mathspecial.d std\internal\math\biguintcore.d std\internal\math\biguint
noasm.d std\internal\math\biguintx86.d std\internal\math\gammafunction.d std\in
ternal\math\errorfunction.d std\internal\windows\advapi32.d crc32.d std\c\pro
cess.d std\c\stdarg.d std\c\stddef.d std\c\stdlib.d std\c\string.d std\c\ti
me.d std\c\math.d std\c\windows\com.d std\c\windows\stat.d std\c\windows\win
dows.d std\c\windows\winsock.d std\windows\charset.d std\windows\iunknown.d
std\windows\registry.d std\windows\syserror.d unittest11.obj unittest12.obj uni
ttest2.obj etc\c\zlib\zlib.lib ..\druntime\lib\druntime.lib
std.contracts has been scheduled for deprecation. Please use std.exception inste
ad.
Notice: As of Phobos 2.055, std.date and std.dateparse have been deprecated. The
y will be removed in February 2012. Please use std.datetime instead.
std.perf has been scheduled for deprecation. Please use std.datetime instead.
Notice: As of Phobos 2.055, std.regexp has been deprecated. It will be removed i
n February 2012. Please use std.regex instead.
std.stdarg is deprecated. You should import core.vararg instead.
Notice: As of Phobos 2.055, std.gregorian has been deprecated. It will be remove
d in February 2012. Please use std.datetime instead.

unittest
Error: 'unittest' not found

--- errorlevel 1

Walter Bright

Also, please do not use tabs in source files.

jacob-carlborg

I guess I have to try and test this on Windows. I apologize for the problems this has caused. I'll fix the tabs and documentation in a, hopefully, upcoming pull request.

Brad Roberts braddr referenced this pull request from a commit October 21, 2012
Commit has since been removed from the repository and is no longer available.
Deleted user Unknown referenced this pull request from a commit December 24, 2013
Commit has since been removed from the repository and is no longer available.
Deleted user Unknown referenced this pull request from a commit December 25, 2013
Commit has since been removed from the repository and is no longer available.
Deleted user Unknown referenced this pull request from a commit December 25, 2013
Commit has since been removed from the repository and is no longer available.
Timothee Cour timotheecour commented on the diff February 10, 2014
src/module.c
@@ -646,6 +662,9 @@ void Module::parse()
646 662
          */
647 663
         if (!Lexer::isValidIdentifier(this->ident->toChars()))
648 664
             error("has non-identifier characters in filename, use module declaration instead");
  665
+
  666
+		if (global.params.packagePaths)
  667
+			error("has no module declaration; this is not allowed when using option -oq");
1

this is unusually restrictive. AndrejMitrovic@6d9f4e9 doesn't have this restriction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Dec 16, 2011
jacob-carlborg Revert "revert pull 169"
This reverts commit 9d664ad3a00d2a09be3aa67cdebb4d4641cdb42f.
44265f9
jacob-carlborg Remove call to "halt". d6b073d
This page is out of date. Refresh to see the latest.
24  src/mars.c
@@ -345,6 +345,7 @@ Usage:\n\
345 345
   -odobjdir      write object & library files to directory objdir\n\
346 346
   -offilename    name output file to filename\n\
347 347
   -op            do not strip paths from source file\n\
  348
+  -oq            use fully qualified module name for object filenames\n\
348 349
   -profile       profile runtime performance of generated code\n\
349 350
   -property      enforce property syntax\n\
350 351
   -quiet         suppress unnecessary messages\n\
@@ -591,6 +592,12 @@ int main(int argc, char *argv[])
591 592
                         global.params.preservePaths = 1;
592 593
                         break;
593 594
 
  595
+                    case 'q':
  596
+                        if (p[3])
  597
+                            goto Lerror;
  598
+                        global.params.packagePaths = 1;
  599
+                        break;
  600
+
594 601
                     case 0:
595 602
                         error("-o no longer supported, use -of or -od");
596 603
                         break;
@@ -1025,6 +1032,7 @@ int main(int argc, char *argv[])
1025 1032
     // Create Modules
1026 1033
     Modules modules;
1027 1034
     modules.reserve(files.dim);
  1035
+
1028 1036
     int firstmodule = 1;
1029 1037
     for (size_t i = 0; i < files.dim; i++)
1030 1038
     {
@@ -1142,11 +1150,6 @@ int main(int argc, char *argv[])
1142 1150
         Identifier *id = Lexer::idPool(name);
1143 1151
         m = new Module(files[i], id, global.params.doDocComments, global.params.doHdrGeneration);
1144 1152
         modules.push(m);
1145  
-
1146  
-        if (firstmodule)
1147  
-        {   global.params.objfiles->push(m->objfile->name->str);
1148  
-            firstmodule = 0;
1149  
-        }
1150 1153
     }
1151 1154
 
1152 1155
 #if WINDOWS_SEH
@@ -1184,8 +1187,7 @@ int main(int argc, char *argv[])
1184 1187
         if (!Module::rootModule)
1185 1188
             Module::rootModule = m;
1186 1189
         m->importedFrom = m;
1187  
-        if (!global.params.oneobj || modi == 0 || m->isDocFile)
1188  
-            m->deleteObjFile();
  1190
+
1189 1191
 #if ASYNCREAD
1190 1192
         if (aw->read(filei))
1191 1193
         {
@@ -1193,6 +1195,9 @@ int main(int argc, char *argv[])
1193 1195
         }
1194 1196
 #endif
1195 1197
         m->parse();
  1198
+        m->prepareObjfile();
  1199
+        if (!global.params.oneobj || modi == 0 || m->isDocFile)
  1200
+            m->deleteObjFile();
1196 1201
         if (m->isDocFile)
1197 1202
         {
1198 1203
             anydocfiles = true;
@@ -1215,6 +1220,11 @@ int main(int argc, char *argv[])
1215 1220
             if (global.params.objfiles->dim == 0)
1216 1221
                 global.params.link = 0;
1217 1222
         }
  1223
+
  1224
+        if (firstmodule)
  1225
+        {   global.params.objfiles->push(m->objfile->name->str);
  1226
+            firstmodule = 0;
  1227
+        }
1218 1228
     }
1219 1229
 #if ASYNCREAD
1220 1230
     AsyncRead::dispose(aw);
1  src/mars.h
@@ -170,6 +170,7 @@ struct Param
170 170
     char useInline;     // inline expand functions
171 171
     char release;       // build release version
172 172
     char preservePaths; // !=0 means don't strip path from source file
  173
+    char packagePaths;  // !=0 means use the fully qualified module name as object file output filename
173 174
     char warnings;      // 0: enable warnings
174 175
                         // 1: warnings as errors
175 176
                         // 2: informational warnings (no errors)
45  src/module.c
@@ -67,6 +67,7 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
67 67
 
68 68
 //    printf("Module::Module(filename = '%s', ident = '%s')\n", filename, ident->toChars());
69 69
     this->arg = filename;
  70
+	orig_filename = filename;
70 71
     md = NULL;
71 72
     errors = 0;
72 73
     numlines = 0;
@@ -136,6 +137,21 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
136 137
         }
137 138
     }
138 139
 
  140
+    srcfile = new File(srcfilename);
  141
+
  142
+    if (doDocComment)
  143
+        setDocfile();
  144
+
  145
+    if (doHdrGen)
  146
+        setHdrfile();
  147
+}
  148
+
  149
+void Module::prepareObjfile()
  150
+{
  151
+	char *filename = orig_filename;
  152
+    FileName *objfilename;
  153
+    FileName *symfilename;
  154
+
139 155
     char *argobj;
140 156
     if (global.params.objname)
141 157
         argobj = global.params.objname;
@@ -153,6 +169,18 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
153 169
     {
154 170
         if (global.params.preservePaths)
155 171
             argobj = filename;
  172
+
  173
+	    else if (global.params.packagePaths) {
  174
+	        argobj = (char*)toPrettyChars();
  175
+	        //FileName::forceExt will think the last part of the package path is an extension
  176
+	        //argobj = argobj ~ '.' ~ global.obj_ext;
  177
+	        char* tmp = (char*)calloc(1, strlen(argobj) + strlen(global.obj_ext) + 2);
  178
+	        memcpy(tmp, argobj, strlen(argobj));
  179
+	        tmp[strlen(argobj)] = '.';
  180
+	        memcpy(tmp + strlen(argobj) + 1, global.obj_ext, strlen(global.obj_ext));
  181
+	        argobj = tmp;
  182
+	    }
  183
+
156 184
         else
157 185
             argobj = FileName::name(filename);
158 186
         if (!FileName::absolute(argobj))
@@ -169,18 +197,6 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
169 197
 
170 198
     symfilename = FileName::forceExt(filename, global.sym_ext);
171 199
 
172  
-    srcfile = new File(srcfilename);
173  
-
174  
-    if (doDocComment)
175  
-    {
176  
-        setDocfile();
177  
-    }
178  
-
179  
-    if (doHdrGen)
180  
-    {
181  
-        setHdrfile();
182  
-    }
183  
-
184 200
     objfile = new File(objfilename);
185 201
     symfile = new File(symfilename);
186 202
 }
@@ -243,7 +259,7 @@ void Module::setHdrfile()
243 259
 
244 260
 void Module::deleteObjFile()
245 261
 {
246  
-    if (global.params.obj)
  262
+    if (global.params.obj && objfile)
247 263
         objfile->remove();
248 264
     if (docfile)
249 265
         docfile->remove();
@@ -646,6 +662,9 @@ void Module::parse()
646 662
          */
647 663
         if (!Lexer::isValidIdentifier(this->ident->toChars()))
648 664
             error("has non-identifier characters in filename, use module declaration instead");
  665
+
  666
+		if (global.params.packagePaths)
  667
+			error("has no module declaration; this is not allowed when using option -oq");
649 668
     }
650 669
 
651 670
     // Update global list of modules
3  src/module.h
@@ -58,6 +58,7 @@ struct Module : Package
58 58
 
59 59
 
60 60
     const char *arg;    // original argument name
  61
+    char *orig_filename; //original filename (passed to Module ctor)
61 62
     ModuleDeclaration *md; // if !NULL, the contents of the ModuleDeclaration declaration
62 63
     File *srcfile;      // input source file
63 64
     File *objfile;      // output .obj file
@@ -114,6 +115,8 @@ struct Module : Package
114 115
     Module(char *arg, Identifier *ident, int doDocComment, int doHdrGen);
115 116
     ~Module();
116 117
 
  118
+    void prepareObjfile();
  119
+
117 120
     static Module *load(Loc loc, Identifiers *packages, Identifier *ident);
118 121
 
119 122
     void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.