Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. qmake: Get parent path / chop one path level
Forum Updated to NodeBB v4.3 + New Features

qmake: Get parent path / chop one path level

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
21 Posts 4 Posters 12.1k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? A Former User

    Yes, it's easy: clean_path( c:/sources/projects/dummyProject/code/.. )

    A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #7

    @Wieland

    Unfortunately not available in Qt 4.8

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #8

      :-/ Well, how bout using the system's shell?
      NEWPATH = $$system( somecode )

      A 1 Reply Last reply
      0
      • ? A Former User

        :-/ Well, how bout using the system's shell?
        NEWPATH = $$system( somecode )

        A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #9

        @Wieland

        Thank you. You are coming up with ideas upon ideas. Unfortunately, this one has to run both on Windows and Linux. And if it's not a built-in command, it means every build environment must be adapted to support it.

        I think I'm about ready to give up...

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #10

          Hi,

          Since it's about calling tools on Windows, you probably need to replace the forward slashes before using the path to run the tool you want.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            Since it's about calling tools on Windows, you probably need to replace the forward slashes before using the path to run the tool you want.

            A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #11

            @SGaist

            Has to run both on Windows and Linux...

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #12

              That's why there are scopes that can be used for this kind of situations

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Asperamanca
                wrote on last edited by
                #13

                I have something that works...under some circumstances.
                It seems to always work when running a scripted compile run (Windows and Linux, vs2010 and gcc), but it doesn't seem to work in Creator when evaluating files of the code model.

                defineReplace(replaceBackslashes) {
                   TEMP_DIRNAME = $$1
                   FINAL_DIRNAME = $$replace(TEMP_DIRNAME,\\\\,/)
                   return($$FINAL_DIRNAME)
                }
                
                defineReplace(cleanupPath) {
                   TEMP_DIRNAME = $$files($$1)
                   FINAL_DIRNAME = $$replaceBackslashes($$TEMP_DIRNAME)
                   return($$FINAL_DIRNAME)
                }
                

                For Creator, both TEMP_DIRNAME and FINAL_DIRNAME in "cleanupPath" are always empty...for some reason. In the scripted compile job, they look just the way they are supposed to.

                Any idea why?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #14

                  Probably because Qt Creator doesn't pass any parameter.

                  How are you calling qmake on the command line ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    Asperamanca
                    wrote on last edited by
                    #15

                    A typical scripted call to qmake would look something like this:

                    qmake.exe CONFIG-=debug CONFIG-=release CONFIG-=debug_and_release CONFIG-=build_all CONFIG+=debug CONFIG+=hmk_build -o tpet.mak ..\..\..\code\tpet.pro
                    
                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #16

                      Then why not use _PRO_FILE_PWD_ as suggested by @Wieland and your replace function to convert forward slashed to back slashes so you wouldn't be dependent on how you call qmake.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      A 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        Then why not use _PRO_FILE_PWD_ as suggested by @Wieland and your replace function to convert forward slashed to back slashes so you wouldn't be dependent on how you call qmake.

                        A Offline
                        A Offline
                        Asperamanca
                        wrote on last edited by Asperamanca
                        #17

                        @SGaist
                        Going in circles....
                        Certainly, I use the _PRO_FILE_PWD_ as my starting point, but some tools need a clean path without stuff likepwdFolder/../../xyz/folder in it. The function he suggested for cleaning the path is not available in Qt 4.8.

                        This brings me back to the question why my original code does not work in context of Creator's code evaluation.
                        According to the docs, $files "Expands the specified wildcard pattern and returns a list of filenames. If recursive is true, this function descends into subdirectories."

                        Assuming that a folder is also a file (at least, that is how most file systems I know treat folders internally), the function should evaluate the location of the folder, and return the correct clean path for it. And it does so in the scripted qmake call.

                        There is no more information in the docs - whether there are certainly boundary conditions for this function to work, limitations, etc. So I'm really at a loss why this does not work as expected.

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by SGaist
                          #18

                          Try with:

                          defineReplace(cleanPath) {
                              win32:1 ~= s|\\\\|/|g
                              contains(1, ^/.*):pfx = /
                              else:pfx =
                              segs = $ $split(1, /)
                              out =
                              for(seg, segs) {
                                  equals(seg, ..):out = $ $member(out, 0, -2)
                                  else:!equals(seg, .):out += $ $seg
                              }
                              win32:return($$join(out, \\, $ $pfx))
                              return($$join(out, /, $ $pfx))
                          }
                          
                          sub_dir = $ $_PRO_FILE_PWD_/../testme
                          path_for_cmd = $ $cleanPath($ $sub_dir)
                          
                          message($ $path_for_cmd)
                          

                          With additional space between $ removed

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          A kkmspbK 2 Replies Last reply
                          1
                          • SGaistS SGaist

                            Try with:

                            defineReplace(cleanPath) {
                                win32:1 ~= s|\\\\|/|g
                                contains(1, ^/.*):pfx = /
                                else:pfx =
                                segs = $ $split(1, /)
                                out =
                                for(seg, segs) {
                                    equals(seg, ..):out = $ $member(out, 0, -2)
                                    else:!equals(seg, .):out += $ $seg
                                }
                                win32:return($$join(out, \\, $ $pfx))
                                return($$join(out, /, $ $pfx))
                            }
                            
                            sub_dir = $ $_PRO_FILE_PWD_/../testme
                            path_for_cmd = $ $cleanPath($ $sub_dir)
                            
                            message($ $path_for_cmd)
                            

                            With additional space between $ removed

                            A Offline
                            A Offline
                            Asperamanca
                            wrote on last edited by
                            #19

                            @SGaist
                            Wow, thanks! I'll have to find a calm minute to wrap my mind around this...

                            1 Reply Last reply
                            0
                            • SGaistS SGaist

                              Try with:

                              defineReplace(cleanPath) {
                                  win32:1 ~= s|\\\\|/|g
                                  contains(1, ^/.*):pfx = /
                                  else:pfx =
                                  segs = $ $split(1, /)
                                  out =
                                  for(seg, segs) {
                                      equals(seg, ..):out = $ $member(out, 0, -2)
                                      else:!equals(seg, .):out += $ $seg
                                  }
                                  win32:return($$join(out, \\, $ $pfx))
                                  return($$join(out, /, $ $pfx))
                              }
                              
                              sub_dir = $ $_PRO_FILE_PWD_/../testme
                              path_for_cmd = $ $cleanPath($ $sub_dir)
                              
                              message($ $path_for_cmd)
                              

                              With additional space between $ removed

                              kkmspbK Offline
                              kkmspbK Offline
                              kkmspb
                              wrote on last edited by
                              #20

                              @SGaist Thank you! It works for me. Just $ $ needs to rewrite to $$!

                              SGaistS 1 Reply Last reply
                              0
                              • kkmspbK kkmspb

                                @SGaist Thank you! It works for me. Just $ $ needs to rewrite to $$!

                                SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #21

                                @kkmspb you're welcome!

                                That's likely related to the old forum which rendered double $ as single hence using a space was mandatory in the answer to show that two were required.

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0
                                • aha_1980A aha_1980 has marked this topic as solved on

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved