Repository: mesonbuild/meson

Issue:
Windows module fails on multiple resource files with same name
I have a project with multiple subfolders that contain resource scripts named 'rsrc.rc', this worked with at least 0.44.0, but fails with current master:

> meson.build:7:0: ERROR:  Tried to create target "Windows resource for file 'rsrc.rc'", but a target of that name already exists.

Here is a small testcase: [rsrcbug.zip](https://github.com/mesonbuild/meson/files/2007861/rsrcbug.zip)



Discussion:

Resolving patch:
diff --git a/mesonbuild/modules/windows.py b/mesonbuild/modules/windows.py
--- a/mesonbuild/modules/windows.py
+++ b/mesonbuild/modules/windows.py
@@ -88,8 +88,10 @@ def add_target(src):
                 'depend_files': wrc_deps,
             }
 
-            if isinstance(src, (str, mesonlib.File)):
-                name = 'file {!r}'.format(str(src))
+            if isinstance(src, str):
+                name = 'file {!r}'.format(os.path.join(state.subdir, src))
+            elif isinstance(src, mesonlib.File):
+                name = 'file {!r}'.format(src.relative_name())
             elif isinstance(src, build.CustomTarget):
                 if len(src.get_outputs()) > 1:
                     raise MesonException('windows.compile_resources does not accept custom targets with more than 1 output.')


Test patch:
diff --git a/test cases/windows/16 resource scripts with duplicate filenames/a/meson.build b/test cases/windows/16 resource scripts with duplicate filenames/a/meson.build
new file mode 100644
--- /dev/null
+++ b/test cases/windows/16 resource scripts with duplicate filenames/a/meson.build	
@@ -0,0 +1 @@
+a = win.compile_resources('rsrc.rc')
diff --git a/test cases/windows/16 resource scripts with duplicate filenames/a/rsrc.rc b/test cases/windows/16 resource scripts with duplicate filenames/a/rsrc.rc
new file mode 100644
--- /dev/null
+++ b/test cases/windows/16 resource scripts with duplicate filenames/a/rsrc.rc	
@@ -0,0 +1 @@
+a RCDATA { "a" }
diff --git a/test cases/windows/16 resource scripts with duplicate filenames/b/meson.build b/test cases/windows/16 resource scripts with duplicate filenames/b/meson.build
new file mode 100644
--- /dev/null
+++ b/test cases/windows/16 resource scripts with duplicate filenames/b/meson.build	
@@ -0,0 +1,2 @@
+bf = files('rsrc.rc')
+b = win.compile_resources(bf)
diff --git a/test cases/windows/16 resource scripts with duplicate filenames/b/rsrc.rc b/test cases/windows/16 resource scripts with duplicate filenames/b/rsrc.rc
new file mode 100644
--- /dev/null
+++ b/test cases/windows/16 resource scripts with duplicate filenames/b/rsrc.rc	
@@ -0,0 +1 @@
+b RCDATA { "b" }
diff --git a/test cases/windows/16 resource scripts with duplicate filenames/c/meson.build b/test cases/windows/16 resource scripts with duplicate filenames/c/meson.build
new file mode 100644
--- /dev/null
+++ b/test cases/windows/16 resource scripts with duplicate filenames/c/meson.build	
@@ -0,0 +1,2 @@
+cf = files('rsrc.rc')
+c = win.compile_resources(cf)
diff --git a/test cases/windows/16 resource scripts with duplicate filenames/c/rsrc.rc b/test cases/windows/16 resource scripts with duplicate filenames/c/rsrc.rc
new file mode 100644
--- /dev/null
+++ b/test cases/windows/16 resource scripts with duplicate filenames/c/rsrc.rc	
@@ -0,0 +1 @@
+c RCDATA { "c" }
diff --git a/test cases/windows/16 resource scripts with duplicate filenames/meson.build b/test cases/windows/16 resource scripts with duplicate filenames/meson.build
new file mode 100644
--- /dev/null
+++ b/test cases/windows/16 resource scripts with duplicate filenames/meson.build	
@@ -0,0 +1,19 @@
+project('foobar', 'c')
+
+win = import('windows')
+
+subdir('a')
+subdir('b')
+subdir('c')
+
+main = win.compile_resources('rsrc.rc')
+
+testa = executable('testa', 'verify.c', a)
+testb = executable('testb', 'verify.c', b)
+testc = executable('testc', 'verify.c', c)
+testmain = executable('testmain', 'verify.c', main)
+
+test('a', testa, args: 'a')
+test('b', testb, args: 'b')
+test('c', testc, args: 'c')
+test('main', testmain, args: 'main')
diff --git a/test cases/windows/16 resource scripts with duplicate filenames/rsrc.rc b/test cases/windows/16 resource scripts with duplicate filenames/rsrc.rc
new file mode 100644
--- /dev/null
+++ b/test cases/windows/16 resource scripts with duplicate filenames/rsrc.rc	
@@ -0,0 +1 @@
+main RCDATA { "main" }
diff --git a/test cases/windows/16 resource scripts with duplicate filenames/verify.c b/test cases/windows/16 resource scripts with duplicate filenames/verify.c
new file mode 100644
--- /dev/null
+++ b/test cases/windows/16 resource scripts with duplicate filenames/verify.c	
@@ -0,0 +1,23 @@
+#include <assert.h>
+#include <windows.h>
+
+int main(int arc, char *argv[])
+{
+  // verify that the expected resource exists and has the expected contents
+  HRSRC hRsrc;
+  unsigned int size;
+  HGLOBAL hGlobal;
+  void* data;
+
+  hRsrc = FindResource(NULL, argv[1], RT_RCDATA);
+  assert(hRsrc);
+
+  size = SizeofResource(NULL, hRsrc);
+  hGlobal = LoadResource(NULL, hRsrc);
+  data = LockResource(hGlobal);
+
+  assert(size == strlen(argv[1]));
+  assert(memcmp(data, argv[1], size) == 0);
+
+  return 0;
+}