dub icon indicating copy to clipboard operation
dub copied to clipboard

extraDependencyFiles doesn't expand the glob strings

Open aminya opened this issue 4 years ago • 1 comments
trafficstars

System information

  • dub version: (e.g. dub 1.3.0) 1.26.1
  • OS Platform and distribution: (e.g. Windows 10, Linux Ubuntu 16.04) Windows 10
  • compiler version (e.g. dmd-2.074.1) dmd 2.097.1 or ldc2 1.27.1

Bug Description

In the documentation, it says that I can use glob to specify extraDependencyFiles, however, when I do, dub doesn't expand the glob. It instead gives this message in the verbose mode:

File ./*.txt doesn't exist, triggering rebuild

How to reproduce?

Add a glob pattern to extraDependencyFiles, and run dub build --verbose twice without changing the project content. It will rebuild.

Expected Behavior

It should check if the files have changed, and then rebuild.

Logs

aminya avatar Aug 24 '21 06:08 aminya

I made an implementation of what I need. Should I make a PR?

import std.file : DirEntry, write, read, tempDir, exists, SpanMode, dirEntries;
import std.path : buildPath, extension, baseName;
import std.digest: hexDigest;
import std.digest.crc: CRC32;

/** Check if a folder has changed
  Params:
    rootDir = the directory to check
    pattern = the pattern to check like "*.{d,di}"
  Returns:
    a boolean showing if the folder has changed
*/
bool folderHasChanged(string rootDir, string pattern) @trusted
{
  const cacheName = buildPath(tempDir(), hexDigest!CRC32(pattern ~ rootDir.baseName()));
  const newCache = getUniqueHash(rootDir, pattern);
  if (!cacheName.exists())
  {
    write(cacheName, newCache);
    return true;
  }
  const changed = newCache != cast(ulong[]) read(cacheName);
  if (changed) {
    write(cacheName, newCache);
  }
  return changed;
}

/** Get a unique cache for a directory
  Params:
    rootDir = the directory to check
    pattern = the pattern to check like "*.{d,di}"
  Returns:
    a buffer of `ulong[]`
*/
ulong[] getUniqueHash(string rootDir, string pattern) @trusted
{
  ulong[] buffer;
  foreach (directoryEntry; dirEntries(rootDir, pattern, SpanMode.breadth))
  {
    buffer ~= getUniqueHash(directoryEntry);
  }
  return buffer;
}

/// Get a unique hash for a DirEntry
/// https://github.com/WebFreak001/FSWatch/blob/1925700c64d9a26fbb2a6231b2cf94dc343800a4/source/fswatch.d#L38
ulong getUniqueHash(DirEntry entry) @trusted
{
  version (Windows)
    return entry.timeLastModified.stdTime ^ cast(ulong) entry.attributes;
  else version (Posix)
    return entry.statBuf.st_ino | (cast(ulong) entry.statBuf.st_dev << 32UL);
  else
    return (entry.timeLastModified.stdTime ^ (
        cast(ulong) entry.attributes << 32UL) ^ entry.linkAttributes) * entry.size;
}

aminya avatar Aug 24 '21 08:08 aminya

in the variable expansion code it should be enough to enable to "glob" / paths parameter for the setting I think - needs a test then though

WebFreak001 avatar Feb 13 '23 15:02 WebFreak001