Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions xmake/modules/detect/tools/find_deployqt.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
--!A cross-platform build utility based on Lua
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- Copyright (C) 2015-present, Xmake Open Source Community.
--
-- @author ruki
-- @file find_deployqt.lua
--

-- imports
import("lib.detect.find_program")

-- find deployqt
--
-- @param opt the argument options, e.g. {version = true}
--
-- @return program
--
function main(opt)

-- init options
opt = opt or {}
opt.check = opt.check or function (program)
-- check version to verify the program is working
if is_host("windows") then
-- windeployqt --help should return successfully
os.run("%s --help", program)
elseif is_host("macosx") then
-- macdeployqt --help should return successfully
os.run("%s --help", program)
else
-- assume linux, linuxdeployqt --help should return successfully
os.run("%s --help", program)
end
end
Comment on lines +34 to +46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The check function doesn't explicitly return a value, so it implicitly returns nil. This will cause the check to fail for any program found. You should return the result of os.run. Additionally, the if/elseif/else block is redundant because the same command is executed for all platforms. The function can be simplified significantly.

    opt.check = opt.check or function (program)
        -- check version to verify the program is working
        -- windeployqt/macdeployqt/linuxdeployqt --help should return successfully
        return os.run("%s --help", program)
    end


-- define program names for different platforms
local program_name = opt.program
if not program_name then
if is_host("windows") then
program_name = "windeployqt"
elseif is_host("macosx") then
program_name = "macdeployqt"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is a trailing whitespace character at the end of this line. It should be removed for code cleanliness.

            program_name = "macdeployqt"

else
-- linux and other unix-like systems
program_name = "linuxdeployqt"
end
end

-- additional search paths for common Qt installations
if not opt.paths then
opt.paths = {}

if is_host("windows") then
-- common Qt installation paths on Windows
table.insert(opt.paths, "C:\\Qt\\*\\bin")
table.insert(opt.paths, "C:\\Qt\\Tools\\*\\bin")
table.insert(opt.paths, path.join(os.getenv("QTDIR") or "", "bin"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

When the QTDIR environment variable is not set or is empty, path.join(os.getenv("QTDIR") or "", "bin") can resolve to an unintended absolute path (e.g., C:\bin on Windows). This could lead to finding an incorrect tool or unnecessary filesystem searches. It's safer to add this path only when QTDIR is set to a non-empty string.

            local qtdir = os.getenv("QTDIR")
            if qtdir and #qtdir > 0 then
                table.insert(opt.paths, path.join(qtdir, "bin"))
            end

elseif is_host("macosx") then
-- common Qt installation paths on macOS
table.insert(opt.paths, "/usr/local/Qt*/*/bin")
table.insert(opt.paths, "~/Qt/*/bin")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is a trailing whitespace character at the end of this line. It should be removed for code cleanliness.

            table.insert(opt.paths, "~/Qt/*/bin")

table.insert(opt.paths, "/opt/Qt*/*/bin")
table.insert(opt.paths, path.join(os.getenv("QTDIR") or "", "bin"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to the Windows case, when the QTDIR environment variable is not set or is empty, an unintended path might be searched. It's better to only add the path if QTDIR is defined and not empty.

            local qtdir = os.getenv("QTDIR")
            if qtdir and #qtdir > 0 then
                table.insert(opt.paths, path.join(qtdir, "bin"))
            end

else
-- common Qt installation paths on Linux
table.insert(opt.paths, "/usr/lib/qt*/bin")
table.insert(opt.paths, "/usr/lib64/qt*/bin")
table.insert(opt.paths, "/opt/qt*/bin")
table.insert(opt.paths, "/usr/local/qt*/bin")
table.insert(opt.paths, "~/Qt/*/bin")
table.insert(opt.paths, path.join(os.getenv("QTDIR") or "", "bin"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to the Windows and macOS cases, when the QTDIR environment variable is not set or is empty, an unintended path might be searched. It's better to only add the path if QTDIR is defined and not empty.

            local qtdir = os.getenv("QTDIR")
            if qtdir and #qtdir > 0 then
                table.insert(opt.paths, path.join(qtdir, "bin"))
            end

end
end

-- find program
return find_program(program_name, opt)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This file is missing a newline character at the end. Most files in this project end with a newline, so it would be good to add one for consistency.