Skip to content

Commit

Permalink
Implemented -deps with no args
Browse files Browse the repository at this point in the history
Purpose: Output everything dependency related to stdout.

Prints to stdout + prefix for different kind of dependencies:

depsVersion Any version() found
depsImport Any imports found (same as -deps=file output, except prefixed with depsImport)
depsFile Any file imports found
depsLib Any libraries specified with pragma(lib)
depsDebug  Andy debug() statements found (Not yet implemented)
  • Loading branch information
eskimor committed Jun 4, 2013
1 parent 00ed71a commit ab3f315
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 56 deletions.
18 changes: 16 additions & 2 deletions src/attrib.c
Expand Up @@ -1038,12 +1038,26 @@ void PragmaDeclaration::semantic(Scope *sc)
StringExp *se = e->toString();
if (!se)
error("string expected for library name, not '%s'", e->toChars());
else if (global.params.verbose)
else
{
char *name = (char *)mem.malloc(se->len + 1);
memcpy(name, se->string, se->len);
name[se->len] = 0;
printf("library %s\n", name);
if (global.params.verbose)
{
printf("library %s\n", name);
}
if(global.params.moduleDeps != NULL && global.params.moduleDepsFile == NULL)
{
OutBuffer *ob = global.params.moduleDeps;
ob->writestring("depsLib ");
ob->writestring(sc->module->toPrettyChars());
ob->writestring(" (");
escapePath(ob, sc->module->srcfile->toChars());
ob->writestring(") : ");
ob->writestring((char *) name);
ob->writenl();
}
mem.free(name);
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/cond.c
Expand Up @@ -240,6 +240,19 @@ void VersionCondition::addPredefinedGlobalIdent(const char *ident)
VersionCondition::VersionCondition(Module *mod, unsigned level, Identifier *ident)
: DVCondition(mod, level, ident)
{
if (global.params.moduleDeps != NULL && global.params.moduleDepsFile == NULL)
{
OutBuffer *ob = global.params.moduleDeps;
ob->writestring("depsVersion ");
ob->writestring(mod->toPrettyChars());
ob->writestring(" (");
escapePath(ob, mod->srcfile->toChars());
ob->writestring(") : ");
if(ident)
ob->printf("%s\n", ident->toChars());
else
ob->printf("%d\n", level);
}
}

int VersionCondition::include(Scope *sc, ScopeDsymbol *s)
Expand Down
5 changes: 3 additions & 2 deletions src/expression.c
Expand Up @@ -7072,9 +7072,10 @@ Expression *FileExp::semantic(Scope *sc)

if (global.params.verbose)
printf("file %s\t(%s)\n", (char *)se->string, name);
if (global.params.fileModuleDeps != NULL)
if (global.params.moduleDeps != NULL && global.params.moduleDepsFile == NULL)
{
OutBuffer *ob = global.params.fileModuleDeps;
OutBuffer *ob = global.params.moduleDeps;
ob->writestring("depsFile ");
ob->writestring(sc->module->toPrettyChars());
ob->writestring(" (");
escapePath(ob, sc->module->srcfile->toChars());
Expand Down
23 changes: 2 additions & 21 deletions src/import.c
Expand Up @@ -138,26 +138,6 @@ void Import::load(Scope *sc)
//printf("-Import::load('%s'), pkg = %p\n", toChars(), pkg);
}

void escapePath(OutBuffer *buf, const char *fname)
{
while (1)
{
switch (*fname)
{
case 0:
return;
case '(':
case ')':
case '\\':
buf->writebyte('\\');
default:
buf->writebyte(*fname);
break;
}
fname++;
}
}

void Import::importAll(Scope *sc)
{
if (!mod)
Expand Down Expand Up @@ -276,7 +256,8 @@ void Import::semantic(Scope *sc)
*/

OutBuffer *ob = global.params.moduleDeps;

if(!global.params.moduleDepsFile)
ob->writestring("depsImport ");
ob->writestring(sc->module->toPrettyChars());
ob->writestring(" (");
escapePath(ob, sc->module->srcfile->toChars());
Expand Down
2 changes: 0 additions & 2 deletions src/import.h
Expand Up @@ -65,7 +65,5 @@ class Import : public Dsymbol
Import *isImport() { return this; }
};

/// Little helper function for writting out deps. (Also used in expression.c for string imports)
void escapePath(OutBuffer *buf, const char *fname);

#endif /* DMD_IMPORT_H */
72 changes: 45 additions & 27 deletions src/mars.c
Expand Up @@ -335,8 +335,8 @@ Usage:\n\
-debug=ident compile in debug code identified by ident\n\
-debuglib=name set symbolic debug library to name\n\
-defaultlib=name set default library to name\n\
-deps=filename write module dependencies to filename\n\
-filedeps=filename write module string import dependencies to filename\n%s"
-deps write module import dependencies to stdoutput. (All dependencies including file/version/debug/lib)\n\
-deps=filename write module dependencies to filename (only imports - deprecated)\n%s"
" -g add symbolic debug info\n\
-gc add symbolic debug info, pretend to be C\n\
-gs always emit stack frame\n\
Expand Down Expand Up @@ -883,20 +883,21 @@ Language changes listed by -transition=id:\n\
setdebuglib = 1;
global.params.debuglibname = p + 1 + 9;
}
else if (memcmp(p + 1, "deps=", 5) == 0)
else if (memcmp(p + 1, "deps", 4) == 0)
{
global.params.moduleDepsFile = p + 1 + 5;
if (!global.params.moduleDepsFile[0])
goto Lnoarg;
if(global.params.moduleDeps)
{
error(0, "-deps[=file] can only be provided once!");
break;
}
if(p[5]=='=')
{
global.params.moduleDepsFile = p + 1 + 5;
if (!global.params.moduleDepsFile[0])
goto Lnoarg;
} // Else output to stdout.
global.params.moduleDeps = new OutBuffer;
}
else if (memcmp(p + 1, "filedeps=", 9) == 0)
{
global.params.fileModuleDepsFile = p + 1 + 9;
if (!global.params.fileModuleDepsFile[0])
goto Lnoarg;
global.params.fileModuleDeps = new OutBuffer;
}
else if (strcmp(p + 1, "main") == 0)
{
global.params.addMain = true;
Expand Down Expand Up @@ -1499,21 +1500,17 @@ Language changes listed by -transition=id:\n\

if (global.params.moduleDeps != NULL)
{
assert(global.params.moduleDepsFile != NULL);

File deps(global.params.moduleDepsFile);
OutBuffer* ob = global.params.moduleDeps;
deps.setbuffer((void*)ob->data, ob->offset);
deps.writev();
}
if (global.params.fileModuleDeps != NULL)
{
assert(global.params.fileModuleDepsFile != NULL);

File fileDeps(global.params.fileModuleDepsFile);
OutBuffer* ob = global.params.fileModuleDeps;
fileDeps.setbuffer((void*)ob->data, ob->offset);
fileDeps.writev();
if(global.params.moduleDepsFile != NULL)
{
File deps(global.params.moduleDepsFile);
deps.setbuffer((void*)ob->data, ob->offset);
deps.writev();
}
else
{
printf("%.*s", ob->offset, ob->data);
}
}

// Scan for functions to inline
Expand Down Expand Up @@ -1805,6 +1802,27 @@ void getenv_setargv(const char *envvar, size_t *pargc, char** *pargv)
*pargv = argv->tdata();
}

void escapePath(OutBuffer *buf, const char *fname)
{
while (1)
{
switch (*fname)
{
case 0:
return;
case '(':
case ')':
case '\\':
buf->writebyte('\\');
default:
buf->writebyte(*fname);
break;
}
fname++;
}
}


/***********************************
* Parse command line arguments for -m32 or -m64
* to detect the desired architecture.
Expand Down
4 changes: 2 additions & 2 deletions src/mars.h
Expand Up @@ -212,9 +212,7 @@ struct Param
const char *debuglibname; // default library for debug builds

char *moduleDepsFile; // filename for deps output
char *fileModuleDepsFile; // filename for file (string imports) deps output
OutBuffer *moduleDeps; // contents to be written to deps file
OutBuffer *fileModuleDeps; // contents to be written to file deps file

// Hidden debug switches
char debuga;
Expand Down Expand Up @@ -449,5 +447,7 @@ void obj_append(Dsymbol *s);
void obj_write_deferred(Library *library);

const char *importHint(const char *s);
/// Little helper function for writting out deps.
void escapePath(OutBuffer *buf, const char *fname);

#endif /* DMD_MARS_H */

0 comments on commit ab3f315

Please sign in to comment.