Skip to content

Commit

Permalink
Improve xmake scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
AidanSun05 committed Aug 15, 2024
1 parent 46bdab1 commit c29a555
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 56 deletions.
41 changes: 19 additions & 22 deletions xmake-requires.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@
},
version = "3.4"
},
["imguitextselect#31fecfc4"] = {
repo = {
url = "./xmake"
},
version = "1.1.1"
},
["imgui v1.91.0-docking#8ff1f880"] = {
branch = "v1.91.0-docking",
repo = {
Expand All @@ -90,6 +84,12 @@
},
version = "v1.91.0-docking"
},
["imguitextselect#31fecfc4"] = {
repo = {
url = "./xmake"
},
version = "1.1.1"
},
["libffi#f26e00a1"] = {
repo = {
branch = "master",
Expand Down Expand Up @@ -368,12 +368,6 @@
},
version = "3.4"
},
["imguitextselect#31fecfc4"] = {
repo = {
url = "./xmake"
},
version = "1.1.1"
},
["imgui v1.91.0-docking#8ff1f880"] = {
repo = {
branch = "master",
Expand All @@ -382,6 +376,12 @@
},
version = "v1.91.0-docking"
},
["imguitextselect#31fecfc4"] = {
repo = {
url = "./xmake"
},
version = "1.1.1"
},
["ninja#31fecfc4"] = {
repo = {
branch = "master",
Expand Down Expand Up @@ -451,9 +451,6 @@
version = "v1.3.1"
}
},
__meta__ = {
version = "1.0"
},
["windows|x64"] = {
["botan#d6ce37d7"] = {
repo = {
Expand Down Expand Up @@ -495,12 +492,6 @@
},
version = "3.4"
},
["imguitextselect#31fecfc4"] = {
repo = {
url = "./xmake"
},
version = "1.1.1"
},
["imgui v1.91.0-docking#8ff1f880"] = {
repo = {
branch = "master",
Expand All @@ -509,6 +500,12 @@
},
version = "v1.91.0-docking"
},
["imguitextselect#31fecfc4"] = {
repo = {
url = "./xmake"
},
version = "1.1.1"
},
["ninja#31fecfc4"] = {
repo = {
branch = "master",
Expand Down Expand Up @@ -578,4 +575,4 @@
version = "v1.3.1"
}
}
}
}
4 changes: 2 additions & 2 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ target("WhaleConnect")

-- Download font files next to executable on pre-build
before_build(function (target)
import("xmake.download").download_fonts(target:targetdir())
import("xmake.download").downloadFonts(target:targetdir())
end)

after_install(function (target)
import("xmake.download").download_licenses(target:installdir())
import("xmake.download").downloadLicenses(target:installdir())
end)

target("socket-tests")
Expand Down
30 changes: 15 additions & 15 deletions xmake/download.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
-- Copyright 2021-2024 Aidan Sun and the WhaleConnect contributors
-- SPDX-License-Identifier: GPL-3.0-or-later

function download_licenses(installdir)
function downloadLicenses(installdir)
print("Downloading licenses...")

-- Licenses are installed to Resources in macOS bundle
local target_dir = is_plat("macosx") and path.join(installdir, "Contents", "Resources") or installdir
local targetDir = is_plat("macosx") and path.join(installdir, "Contents", "Resources") or installdir

local license_files = {
local licenseFiles = {
-- Libraries
["bluez"] = { "https://raw.githubusercontent.com/bluez/bluez/master/LICENSES/preferred/GPL-2.0" },
["botan"] = { "https://raw.githubusercontent.com/randombit/botan/master/license.txt" },
Expand All @@ -30,28 +30,28 @@ function download_licenses(installdir)
}

local http = import("net.http")
for name, urls in pairs(license_files) do
for name, urls in pairs(licenseFiles) do
for _, url in ipairs(urls) do
local filename = path.filename(url)
local target_path = path.join(target_dir, "3rdparty", name, filename)
local targetPath = path.join(targetDir, "3rdparty", name, filename)

if not os.isfile(target_path) then
print("- %s -> %s", url, target_path)
http.download(url, target_path)
if not os.isfile(targetPath) then
print("- %s -> %s", url, targetPath)
http.download(url, targetPath)
end
end
end
end

function download_fonts(targetdir)
local font_path = path.join(targetdir, "NotoSansMono-Regular.ttf")
local icon_font_path = path.join(targetdir, "remixicon.ttf")
function downloadFonts(targetdir)
local fontPath = path.join(targetdir, "NotoSansMono-Regular.ttf")
local iconFontPath = path.join(targetdir, "remixicon.ttf")

if not os.isfile(font_path) then
os.ln(os.getenv("NOTO_SANS_MONO_PATH"), font_path)
if not os.isfile(fontPath) then
os.ln(os.getenv("NOTO_SANS_MONO_PATH"), fontPath)
end

if not os.isfile(icon_font_path) then
os.ln(os.getenv("REMIX_ICON_PATH"), icon_font_path)
if not os.isfile(iconFontPath) then
os.ln(os.getenv("REMIX_ICON_PATH"), iconFontPath)
end
end
38 changes: 21 additions & 17 deletions xmake/parse_lock_file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,53 @@
import("core.base.json")
import("core.base.semver")

all_packages = {}
allPackages = {}

function record_packages(packages, os_key)
function recordPackages(packages, osKey)
for package, info in pairs(packages) do
local name = package:match("^([%w_%-]+)")
if all_packages[name] == nil then
if allPackages[name] == nil then
local version = info["version"]
local parsed_version = semver.is_valid(version) and semver.new(version):shortstr() or version
local parsedVersion = semver.is_valid(version) and semver.new(version):shortstr() or version

local online = info["repo"]["url"]:match("^https://")

local repo_root = online
local repoRoot = online
and path.join(val("globaldir"), "repositories", "xmake-repo")
or path.join(val("projectdir"), "xmake")

all_packages[name] = {
version = parsed_version,
filepath = path.join(repo_root, "packages", name:sub(1, 1), name, "xmake.lua"),
allPackages[name] = {
filepath = path.join(repoRoot, "packages", name:sub(1, 1), name, "xmake.lua"),
os = {}
}

local prevVersion = allPackages[name]["version"]
if prevVersion == nil or (semver.is_valid(prevVersion) and semver.compare(parsedVersion, prevVersion) == 1) then
allPackages[name]["version"] = parsedVersion
end
end

table.insert(all_packages[name]["os"], os_key)
table.insert(allPackages[name]["os"], osKey)
end
end

function main(...)
package_info = io.load(path.join(os.projectdir(), "xmake-requires.lock"))
for platform, packages in pairs(package_info) do
pkgInfo = io.load(path.join(os.projectdir(), "xmake-requires.lock"))
for platform, packages in pairs(pkgInfo) do
if platform ~= "__meta__" then
local os = platform:match("(.+)|")
local os_key = ""
local osKey = ""
if os == "linux" then
os_key = "L"
osKey = "L"
elseif os == "macosx" then
os_key = "M"
osKey = "M"
elseif os == "windows" then
os_key = "W"
osKey = "W"
end

record_packages(packages, os_key)
recordPackages(packages, osKey)
end
end

json.savefile(path.join(os.projectdir(), "build", "packages.json"), all_packages)
json.savefile(path.join(os.projectdir(), "build", "packages.json"), allPackages)
end

0 comments on commit c29a555

Please sign in to comment.