Skip to content

Commit

Permalink
remove file name handling from lib.d
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright authored and dlang-bot committed Aug 16, 2023
1 parent 6fdf33d commit 705782a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 38 deletions.
20 changes: 19 additions & 1 deletion compiler/src/dmd/glue.d
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,25 @@ void generateCodeAndWrite(Module[] modules, const(char)*[] libmodules,
if (writeLibrary)
{
library = Library.factory(target.objectFormat(), target.lib_ext, eSink);
library.setFilename(objdir, libname);

/* Determine actual file name of library to write to by combining
* objdir, libname, the first object file name, and lib_ext
*/
const(char)[] arg;
if (!libname.length)
{
// get name of the first object file
const(char)[] n = global.params.objfiles[0].toDString;
n = FileName.name(n); // remove its path
arg = FileName.forceExt(n, library.lib_ext); // force library name extension
}
else
arg = FileName.defaultExt(libname, library.lib_ext);
if (!FileName.absolute(arg))
arg = FileName.combine(objdir, arg);

library.setFilename(arg);

// Add input object and input library files to output library
foreach (p; libmodules)
library.addObject(p.toDString(), null);
Expand Down
45 changes: 15 additions & 30 deletions compiler/src/dmd/lib.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,16 @@
module dmd.lib;

import core.stdc.stdio;
import core.stdc.stdarg;

import dmd.globals;
import dmd.location;
import dmd.common.outbuffer;
import dmd.errorsink;
import dmd.location;
import dmd.target : Target;
import dmd.utils;

import dmd.common.outbuffer;
import dmd.root.file;
import dmd.root.filename;
import dmd.root.string;

import dmd.libomf;
import dmd.libmscoff;
import dmd.libelf;
import dmd.libmach;
import dmd.libmscoff;
import dmd.libomf;

private enum LOG = false;

Expand Down Expand Up @@ -59,34 +52,26 @@ class Library


/***********************************
* Set the library file name based on the output directory
* and the filename.
* Add default library file name extension.
* Set library file name
* Params:
* dir = path to file
* filename = name of file relative to `dir`
* filename = name of library file
*/
final void setFilename(const(char)[] dir, const(char)[] filename)
final void setFilename(const char[] filename)
{
static if (LOG)
{
printf("LibElf::setFilename(dir = '%.*s', filename = '%.*s')\n",
cast(int)dir.length, dir.ptr, cast(int)filename.length, filename.ptr);
printf("LibElf::setFilename(filename = '%.*s')\n",
cast(int)filename.length, filename.ptr);
}
const(char)[] arg = filename;
if (!arg.length)
{
// Generate lib file name from first obj name
const(char)[] n = global.params.objfiles[0].toDString;
n = FileName.name(n);
arg = FileName.forceExt(n, lib_ext);
}
if (!FileName.absolute(arg))
arg = FileName.combine(dir, arg);

loc = Loc(FileName.defaultExt(arg, lib_ext).ptr, 0, 0);
loc = Loc(filename.ptr, 0, 0);
}

/*************
* Retrieve library file name
* Returns:
* filename = name of library file
*/
final const(char)* getFilename() const
{
return loc.filename;
Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dmd/libelf.d
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ version (Windows)
import core.sys.windows.stat;
}

import dmd.globals;
import dmd.lib;
import dmd.location;
import dmd.utils;

import dmd.root.array;
import dmd.root.file;
import dmd.root.filename;
import dmd.common.outbuffer;
import dmd.root.port;
Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dmd/libmach.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ version (Windows)
import core.sys.windows.stat;
}

import dmd.globals;
import dmd.lib;
import dmd.location;
import dmd.utils;

import dmd.root.array;
import dmd.root.file;
import dmd.root.filename;
import dmd.common.outbuffer;
import dmd.root.port;
Expand Down
1 change: 0 additions & 1 deletion compiler/src/dmd/libmscoff.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import dmd.location;
import dmd.utils;

import dmd.root.array;
import dmd.root.file;
import dmd.root.filename;
import dmd.common.outbuffer;
import dmd.root.port;
Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dmd/libomf.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ import core.stdc.string;
import core.stdc.stdlib;
import core.bitop;

import dmd.globals;
import dmd.utils;
import dmd.lib;
import dmd.location;

import dmd.root.array;
import dmd.root.file;
import dmd.root.filename;
import dmd.root.rmem;
import dmd.common.outbuffer;
Expand Down

0 comments on commit 705782a

Please sign in to comment.