Git Product home page Git Product logo

Comments (3)

eli-schwartz avatar eli-schwartz commented on June 21, 2024 1

This is expected behavior since you told the compiler to use an actual argument with zero length.

An array of length one, content '' is not the same as an array of length zero, no content. There are valid use cases for both, e.g. the value to a flag can be set to empty and this produces different results compared to not passing the flag at all.

Is there a reason you wanted to pass a blank string as a positive component of the compiler command line?

from meson.

zoziha avatar zoziha commented on June 21, 2024

@eli-schwartz, thanks for the reply, I thought that the behavior of meson will automatically remove the quotes, and then pass it to the compiler. There is a deviation between my understanding and the meson feature.

But in retrospect, this incident surprised me. My original meson.build was to use meson_options.txt to control the macro definition -DC2: diff-1 (bad).

 project('test', 'fortran')

-test_lib = static_library('test1', 'src/kinds.F90', fortran_args: [''])  # This is the problem: `fortran_args: ['']`
+C2 = get_option('C2')
+if C2
+    C2_macro = '-DC2'
+else
+    C2_macro = ''
+endif
+
+test_lib = static_library('test1', 'src/kinds.F90', fortran_args: [C2_macro])  # This is the problem: `fortran_args: ['']`

 exe = executable('test2', 'src/main.f90',
    link_with: [test_lib])
+option('C2', type: 'boolean', value: false, description: 'use C2 macros')
+option('C4', type: 'boolean', value: true, description: 'use C4 macros')

I didn't mean to pass the empty string [""] to the compiler, when C2 == False, I just pass the compiler parameter []. meson <=1.2.3, my meson project works fine, and after updating the version to 1.4.0, the project failed to build, which surprised me, but no hints.


Now I know I should define macros like this diff-2 (good):

diff --git a/meson.build b/meson.build
index b594880..b3a3783 100644
--- a/meson.build
+++ b/meson.build
@@ -1,13 +1,11 @@
 project('test', 'fortran')
 
-C2 = get_option('C2')
-if C2
-    C2_macro = '-DC2'
-else
-    C2_macro = ''
+fortran_args = []
+if get_option('C2')
+    fortran_args += '-DC2'
 endif
 
-test_lib = static_library('test1', 'src/kinds.F90', fortran_args: [C2_macro])  # This is the problem: `fortran_args: ['']`
+test_lib = static_library('test1', 'src/kinds.F90', fortran_args: [fortran_args])

 exe = executable('test2', 'src/main.f90',
     link_with: [test_lib])

Crude idea, maybe meson can detect the existence of "", after all, "" will cause the compilation to fail, and the user side is not easy to find the root reason, because there is no obvious hint; or maybe it is not necessary to do this, because at least the latest meson 1.4.0 will throw a compilation error (this is a expected behavior, compared to meson <=1.2.3), but the user like me may not be good to detect the cause of failure.

diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 28f5d532f..6684a9697 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -2891,7 +2891,13 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
                 commands += compiler.get_include_args(d, i.is_system)
         # Add per-target compile args, f.ex, `c_args : ['-DFOO']`. We set these
         # near the end since these are supposed to override everything else.
-        commands += self.escape_extra_args(target.get_extra_args(compiler.get_language()))
+        commands += [
+            s
+            for s in self.escape_extra_args(
+                target.get_extra_args(compiler.get_language())
+            )
+            if s != ""
+        ]
 
         # D specific additional flags
         if compiler.language == 'd':

from meson.

eli-schwartz avatar eli-schwartz commented on June 21, 2024

@eli-schwartz, thanks for the reply, I thought that the behavior of meson will automatically remove the quotes, and then pass it to the compiler. There is a deviation between my understanding and the meson feature.

Meson doesn't remove quotes. Quotes are syntax, not data. '' isn't a pair of empty quotes, it is a meson array containing one string. It gets forwarded to the compiler using bash, and bash also uses quotes as syntax to denote strings (in this case, not always. Bash requires quotes for ambiguous cases that cannot be word-split obviously otherwise, and a blank string is one of those cases where bash needs those quotes.)

I didn't mean to pass the empty string [""] to the compiler, when C2 == False, I just pass the compiler parameter []. meson <=1.2.3, my meson project works fine, and after updating the version to 1.4.0, the project failed to build, which surprised me, but no hints.

In my testing, both meson 1.2.3 and meson 1.4.0 fail in the same way. You would need to use [] in both cases.

from meson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.