-
-
Notifications
You must be signed in to change notification settings - Fork 763
/
package.lua
2906 lines (2642 loc) · 92.1 KB
/
package.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--!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, TBOOX Open Source Group.
--
-- @author ruki
-- @file package.lua
--
-- define module
local package = {}
local _instance = {}
-- load modules
local os = require("base/os")
local io = require("base/io")
local path = require("base/path")
local utils = require("base/utils")
local table = require("base/table")
local global = require("base/global")
local semver = require("base/semver")
local option = require("base/option")
local hashset = require("base/hashset")
local scopeinfo = require("base/scopeinfo")
local interpreter = require("base/interpreter")
local select_script = require("base/private/select_script")
local is_cross = require("base/private/is_cross")
local memcache = require("cache/memcache")
local toolchain = require("tool/toolchain")
local compiler = require("tool/compiler")
local linker = require("tool/linker")
local sandbox = require("sandbox/sandbox")
local config = require("project/config")
local policy = require("project/policy")
local platform = require("platform/platform")
local platform_menu = require("platform/menu")
local component = require("package/component")
local language = require("language/language")
local language_menu = require("language/menu")
local sandbox = require("sandbox/sandbox")
local sandbox_os = require("sandbox/modules/os")
local sandbox_module = require("sandbox/modules/import/core/sandbox/module")
-- new an instance
function _instance.new(name, info, opt)
opt = opt or {}
local instance = table.inherit(_instance)
instance._NAME = name
instance._INFO = info
instance._REPO = opt.repo
instance._SCRIPTDIR = opt.scriptdir and path.absolute(opt.scriptdir)
return instance
end
-- get memcache
function _instance:_memcache()
local cache = self._MEMCACHE
if not cache then
cache = memcache.cache("core.package.package." .. tostring(self))
self._MEMCACHE = cache
end
return cache
end
-- get the package name
function _instance:name()
return self._NAME
end
-- get the type: package
function _instance:type()
return "package"
end
-- get the base package
function _instance:base()
return self._BASE
end
-- get the package configuration
function _instance:get(name)
local value = self._INFO:get(name)
if name == "configs" then
-- we need to merge it, because current builtin configs always exists
if self:base() then
local configs_base = self:base():get("configs")
if configs_base then
value = table.unique(table.join(value or {}, configs_base))
end
end
elseif value == nil and self:base() then
value = self:base():get(name)
end
if value ~= nil then
return value
end
end
-- set the value to the package info
function _instance:set(name, ...)
self._INFO:apival_set(name, ...)
end
-- add the value to the package info
function _instance:add(name, ...)
self._INFO:apival_add(name, ...)
end
-- get the extra configuration
function _instance:extraconf(name, item, key)
local conf = self._INFO:extraconf(name, item, key)
if conf == nil and self:base() then
conf = self:base():extraconf(name, item, key)
end
return conf
end
-- set the extra configuration
function _instance:extraconf_set(name, item, key, value)
return self._INFO:extraconf_set(name, item, key, value)
end
-- get configuration source information of the given api item
function _instance:sourceinfo(name, item)
return self._INFO:sourceinfo(name, item)
end
-- get the package license
function _instance:license()
return self:get("license")
end
-- get the package description
function _instance:description()
return self:get("description")
end
-- get the platform of package
function _instance:plat()
if self._PLAT then
return self._PLAT
end
-- @note we uses os.host() instead of them for the binary package
if self:is_binary() then
return os.subhost()
end
local requireinfo = self:requireinfo()
if requireinfo and requireinfo.plat then
return requireinfo.plat
end
return package.targetplat()
end
-- get the architecture of package
function _instance:arch()
if self._ARCH then
return self._ARCH
end
-- @note we uses os.arch() instead of them for the binary package
if self:is_binary() then
return os.subarch()
end
return self:targetarch()
end
-- set the package platform
function _instance:plat_set(plat)
self._PLAT = plat
end
-- set the package architecture
function _instance:arch_set(arch)
self._ARCH = arch
end
-- get the target os
function _instance:targetos()
local requireinfo = self:requireinfo()
if requireinfo and requireinfo.targetos then
return requireinfo.targetos
end
return config.get("target_os") or platform.os()
end
-- get the target architecture
function _instance:targetarch()
local requireinfo = self:requireinfo()
if requireinfo and requireinfo.arch then
return requireinfo.arch
end
return package.targetarch()
end
-- get the build mode
function _instance:mode()
return self:is_debug() and "debug" or "release"
end
-- get the repository of this package
function _instance:repo()
return self._REPO
end
-- the current platform is belong to the given platforms?
function _instance:is_plat(...)
local plat = self:plat()
for _, v in ipairs(table.pack(...)) do
if v and plat == v then
return true
end
end
end
-- the current architecture is belong to the given architectures?
function _instance:is_arch(...)
local arch = self:arch()
for _, v in ipairs(table.pack(...)) do
if v and arch:find("^" .. v:gsub("%-", "%%-") .. "$") then
return true
end
end
end
-- is 64bits architecture?
function _instance:is_arch64()
return self:is_arch(".+64.*")
end
-- the current platform is belong to the given target os?
function _instance:is_targetos(...)
local targetos = self:targetos()
for _, v in ipairs(table.join(...)) do
if v and targetos == v then
return true
end
end
end
-- the current architecture is belong to the given target architectures?
function _instance:is_targetarch(...)
local targetarch = self:targetarch()
for _, v in ipairs(table.pack(...)) do
if v and targetarch:find("^" .. v:gsub("%-", "%%-") .. "$") then
return true
end
end
end
-- get the package alias
function _instance:alias()
local requireinfo = self:requireinfo()
if requireinfo then
return requireinfo.alias
end
end
-- get external package sources, e.g. pkgconfig::xxx, system::xxx, conan::xxx
-- we can use it to improve self:fetch() for find_package
function _instance:extsources()
return self:get("extsources")
end
-- get urls
function _instance:urls()
local urls = self._URLS
if urls == nil then
urls = table.wrap(self:get("urls"))
if #urls == 1 and urls[1] == "" then
urls = {}
end
end
return urls
end
-- get urls
function _instance:urls_set(urls)
self._URLS = urls
end
-- get the alias of url, @note need raw url
function _instance:url_alias(url)
return self:extraconf("urls", url, "alias")
end
-- get the version filter of url, @note need raw url
function _instance:url_version(url)
return self:extraconf("urls", url, "version")
end
-- get the excludes list of url for the archive extractor, @note need raw url
function _instance:url_excludes(url)
return self:extraconf("urls", url, "excludes")
end
-- get the http headers of url, @note need raw url
function _instance:url_http_headers(url)
return self:extraconf("urls", url, "http_headers")
end
-- set artifacts info
function _instance:artifacts_set(artifacts_info)
local versions = self:_versions_list()
if versions then
-- backup previous package configuration
self._ARTIFACTS_BACKUP = {
urls = table.copy(self:urls()),
versions = table.copy(versions),
install = self:script("install")} -- self:get() will get a table, it will be broken when call self:set()
-- we switch to urls of the precompiled artifacts
self:urls_set(table.wrap(artifacts_info.urls))
versions[self:version_str()] = artifacts_info.sha256
self:set("install", function (package)
sandbox_module.import("lib.detect.find_path")
local rootdir = find_path("manifest.txt", path.join(os.curdir(), "*", "*", "*"))
if not rootdir then
os.raise("package(%s): manifest.txt not found when installing artifacts!", package:displayname())
end
os.cp(path.join(rootdir, "*"), package:installdir(), {symlink = true})
local manifest = package:manifest_load()
if not manifest then
os.raise("package(%s): load manifest.txt failed when installing artifacts!", package:displayname())
end
if manifest.vars then
for k, v in pairs(manifest.vars) do
package:set(k, v)
end
end
if manifest.components then
local vars = manifest.components.vars
if vars then
for component_name, component_vars in pairs(vars) do
local comp = package:component(component_name)
if comp then
for k, v in pairs(component_vars) do
comp:set(k, v)
end
end
end
end
end
if manifest.envs then
local envs = self:_rawenvs()
for k, v in pairs(manifest.envs) do
envs[k] = v
end
end
-- save the remote install directory to fix the install path in .cmake/.pc files for precompiled artifacts
--
-- @see https://github.com/xmake-io/xmake/issues/2210
--
manifest.artifacts = manifest.artifacts or {}
manifest.artifacts.remotedir = manifest.artifacts.installdir
end)
self._IS_PRECOMPILED = true
end
end
-- is this package built?
function _instance:is_built()
return not self:is_precompiled()
end
-- is this package precompiled?
function _instance:is_precompiled()
return self._IS_PRECOMPILED
end
-- fallback to source code build
function _instance:fallback_build()
if self:is_precompiled() then
local artifacts_backup = self._ARTIFACTS_BACKUP
if artifacts_backup then
if artifacts_backup.urls then
self:urls_set(artifacts_backup.urls)
end
if artifacts_backup.versions then
self:set("versions", artifacts_backup.versions)
end
if artifacts_backup.install then
self:set("install", artifacts_backup.install)
end
self._MANIFEST = nil
end
self._IS_PRECOMPILED = false
end
end
-- get the given dependent package
function _instance:dep(name)
local deps = self:deps()
if deps then
return deps[name]
end
end
-- get deps
function _instance:deps()
return self._DEPS
end
-- get order deps
function _instance:orderdeps()
return self._ORDERDEPS
end
-- get plain deps
function _instance:plaindeps()
return self._PLAINDEPS
end
-- get library deps with correct link order
function _instance:librarydeps(opt)
if opt and opt.private then
return self._LIBRARYDEPS_WITH_PRIVATE
else
return self._LIBRARYDEPS
end
end
-- get parents
function _instance:parents(packagename)
local parents = self._PARENTS
if parents then
if packagename then
return parents[packagename]
else
local results = self._PARENTS_PLAIN
if not results then
results = {}
for _, parentpkgs in pairs(parents) do
table.join2(results, parentpkgs)
end
results = table.unique(results)
self._PARENTS_PLAIN = results
end
if #results > 0 then
return results
end
end
end
end
-- add parents
function _instance:parents_add(...)
self._PARENTS = self._PARENTS or {}
for _, parent in ipairs({...}) do
-- maybe multiple parents will depend on it
-- @see https://github.com/xmake-io/xmake/issues/3065
local parentpkgs = self._PARENTS[parent:name()]
if not parentpkgs then
parentpkgs = {}
self._PARENTS[parent:name()] = parentpkgs
end
table.insert(parentpkgs, parent)
self._PARENTS_PLAIN = nil
end
end
-- get hash of the source package for the url_alias@version_str
function _instance:sourcehash(url_alias)
local versions = self:_versions_list()
local version_str = self:version_str()
if versions and version_str then
local sourcehash = nil
if url_alias then
sourcehash = versions[url_alias .. ":" ..version_str]
end
if not sourcehash then
sourcehash = versions[version_str]
end
if sourcehash and #sourcehash == 40 then
sourcehash = sourcehash:lower()
end
return sourcehash
end
end
-- get revision(commit, tag, branch) of the url_alias@version_str, only for git url
function _instance:revision(url_alias)
local revision = self:sourcehash(url_alias)
if revision and #revision <= 40 then
-- it will be sha256 of tar/gz file, not commit number if longer than 40 characters
return revision
end
end
-- get the package policy
function _instance:policy(name)
local policies = self._POLICIES
if not policies then
policies = self:get("policy")
self._POLICIES = policies
if policies then
local defined_policies = policy.policies()
for name, _ in pairs(policies) do
if not defined_policies[name] then
utils.warning("unknown policy(%s), please run `xmake l core.project.policy.policies` if you want to all policies", name)
end
end
end
end
return policy.check(name, policies and policies[name])
end
-- get the package kind
--
-- - binary
-- - toolchain (is also binary)
-- - library(default)
--
function _instance:kind()
local kind
local requireinfo = self:requireinfo()
if requireinfo then
kind = requireinfo.kind
end
if not kind then
kind = self:get("kind")
end
return kind
end
-- is binary package?
function _instance:is_binary()
return self:kind() == "binary" or self:kind() == "toolchain"
end
-- is toolchain package?
function _instance:is_toolchain()
return self:kind() == "toolchain"
end
-- is library package?
function _instance:is_library()
return self:kind() == nil or self:kind() == "library"
end
-- is template package?
function _instance:is_template()
return self:kind() == "template"
end
-- is header only?
function _instance:is_headeronly()
return self:is_library() and self:extraconf("kind", "library", "headeronly")
end
-- is top level? user top requires in xmake.lua
function _instance:is_toplevel()
local requireinfo = self:requireinfo()
return requireinfo and requireinfo.is_toplevel
end
-- is the system package?
function _instance:is_system()
return self._is_system
end
-- is the third-party package? e.g. brew::pcre2/libpcre2-8, conan::OpenSSL/1.0.2n@conan/stable
-- we need to install and find package by third-party package manager directly
--
function _instance:is_thirdparty()
return self._is_thirdparty
end
-- is fetch only?
function _instance:is_fetchonly()
local project = package._project()
if project and project.policy("package.fetch_only") then
return true
end
-- only fetch script
if self:get("fetch") and not self:get("install") then
return true
end
-- only from system
local requireinfo = self:requireinfo()
if requireinfo and requireinfo.system then
return true
end
return false
end
-- is optional package?
function _instance:is_optional()
local requireinfo = self:requireinfo()
return requireinfo and requireinfo.optional or false
end
-- is private package?
function _instance:is_private()
local requireinfo = self:requireinfo()
return requireinfo and requireinfo.private or false
end
-- verify sha256sum and versions?
function _instance:is_verify()
local requireinfo = self:requireinfo()
local verify = requireinfo and requireinfo.verify
if verify == nil then
verify = true
end
return verify
end
-- is debug package?
function _instance:is_debug()
return self:config("debug") or self:config("asan")
end
-- is the supported package?
function _instance:is_supported()
-- attempt to get the install script with the current plat/arch
return self:script("install") ~= nil
end
-- support parallelize for installation?
function _instance:is_parallelize()
return self:get("parallelize") ~= false
end
-- is local embed source code package?
-- we install directly from the local source code instead of downloading it remotely
function _instance:is_source_embed()
return self:get("sourcedir") and #self:urls() == 0 and self:script("install")
end
-- is local embed binary package? it's come from `xmake package`
function _instance:is_binary_embed()
return self:get("installdir") and #self:urls() == 0 and not self:script("install") and self:script("fetch")
end
-- is local package?
-- we will use local installdir and cachedir in current project
function _instance:is_local()
return self._IS_LOCAL or self:is_source_embed() or self:is_binary_embed() or self:is_thirdparty()
end
-- mark it as local package
function _instance:_mark_as_local(is_local)
if self:is_local() ~= is_local then
self._INSTALLDIR = nil
self._IS_LOCAL = is_local
end
end
-- use external includes?
function _instance:use_external_includes()
local external = self:requireinfo().external
if external == nil then
local project = package._project()
if project then
external = project.policy("package.include_external_headers")
end
end
if external == nil then
external = self:policy("package.include_external_headers")
end
-- disable -Isystem for external packages as it seems to break. e.g. assimp
-- @see https://github.com/msys2/MINGW-packages/issues/10761
if external == nil and self:is_plat("mingw") and os.is_subhost("msys") then
external = false
end
if external == nil then
external = true
end
return external
end
-- is debug package? (deprecated)
function _instance:debug()
return self:is_debug()
end
-- is cross-compilation?
function _instance:is_cross()
return is_cross(self:plat(), self:arch())
end
-- get the filelock of the whole package directory
function _instance:filelock()
local filelock = self._FILELOCK
if filelock == nil then
filelock = io.openlock(path.join(self:cachedir(), "package.lock"))
if not filelock then
os.raise("cannot create filelock for package(%s)!", self:name())
end
self._FILELOCK = filelock
end
return filelock
end
-- lock the whole package
function _instance:lock(opt)
if self:filelock():trylock(opt) then
return true
else
utils.cprint("${color.warning}package(%s) is being accessed by other processes, please wait!", self:name())
end
local ok, errors = self:filelock():lock(opt)
if not ok then
os.raise(errors)
end
end
-- unlock the whole package
function _instance:unlock()
local ok, errors = self:filelock():unlock()
if not ok then
os.raise(errors)
end
end
-- get the source directory
function _instance:sourcedir()
return self:get("sourcedir")
end
-- get the build directory
function _instance:buildir()
local buildir = self._BUILDIR
if not buildir then
if self:is_local() then
local name = self:name():lower():gsub("::", "_")
local rootdir = path.join(config.buildir({absolute = true}), ".packages", name:sub(1, 1):lower(), name, self:version_str())
buildir = path.join(rootdir, "cache", "build_" .. self:buildhash():sub(1, 8))
else
buildir = "build_" .. self:buildhash():sub(1, 8)
end
self._BUILDIR = buildir
end
return buildir
end
-- get the cached directory of this package
function _instance:cachedir()
local cachedir = self._CACHEDIR
if not cachedir then
cachedir = self:get("cachedir")
if not cachedir then
-- we need to use displayname (with package id) to avoid
-- multiple processes accessing it at the same time.
--
-- @see https://github.com/libbpf/libbpf-bootstrap/pull/259#issuecomment-1994914188
--
-- e.g.
--
-- lock elfutils#1 /home/runner/.xmake/cache/packages/2403/e/elfutils/0.189
-- lock elfutils /home/runner/.xmake/cache/packages/2403/e/elfutils/0.189
-- package(elfutils) is being accessed by other processes, please wait!
--
local name = self:displayname():lower():gsub("::", "_"):gsub("#", "_")
local version_str = self:version_str()
if self:is_thirdparty() then
-- strip `>= <=`
version_str = version_str:gsub("[>=<]", "")
end
if self:is_local() then
cachedir = path.join(config.buildir({absolute = true}), ".packages", name:sub(1, 1):lower(), name, version_str, "cache")
else
cachedir = path.join(package.cachedir(), name:sub(1, 1):lower(), name, version_str)
end
end
self._CACHEDIR = cachedir
end
return cachedir
end
-- get the installed directory of this package
function _instance:installdir(...)
local installdir = self._INSTALLDIR
if not installdir then
installdir = self:get("installdir")
if not installdir then
local name = self:name():lower():gsub("::", "_")
if self:is_local() then
installdir = path.join(config.buildir({absolute = true}), ".packages", name:sub(1, 1):lower(), name)
else
installdir = path.join(package.installdir(), name:sub(1, 1):lower(), name)
end
local version_str = self:version_str()
if version_str then
if self:is_thirdparty() then
-- strip `>= <=`
version_str = version_str:gsub("[>=<]", "")
end
installdir = path.join(installdir, version_str)
end
installdir = path.join(installdir, self:buildhash())
end
self._INSTALLDIR = installdir
end
local dirs = table.pack(...)
local opt = dirs[dirs.n]
if table.is_dictionary(opt) then
table.remove(dirs)
else
opt = nil
end
local dir = path.join(installdir, table.unpack(dirs))
if opt and opt.readonly then
return dir
end
if not os.isdir(dir)then
os.mkdir(dir)
end
return dir
end
-- get the script directory
function _instance:scriptdir()
return self._SCRIPTDIR
end
-- get the rules directory
function _instance:rulesdir()
local rulesdir = self._RULESDIR
if rulesdir == nil then
rulesdir = path.join(self:scriptdir(), "rules")
if not os.isdir(rulesdir) and self:base() then
rulesdir = self:base():rulesdir()
end
if rulesdir == nil or not os.isdir(rulesdir) then
rulesdir = false
end
self._RULESDIR = rulesdir
end
return rulesdir or nil
end
-- get the references info of this package
function _instance:references()
local references_file = path.join(self:installdir({readonly = true}), "references.txt")
if os.isfile(references_file) then
local references, errors = io.load(references_file)
if not references then
os.raise(errors)
end
return references
end
end
-- get the manifest file of this package
function _instance:manifest_file()
return path.join(self:installdir({readonly = true}), "manifest.txt")
end
-- load the manifest file of this package
function _instance:manifest_load()
local manifest = self._MANIFEST
if not manifest then
local manifest_file = self:manifest_file()
if os.isfile(manifest_file) then
local errors = nil
manifest, errors = io.load(manifest_file)
if not manifest then
os.raise(errors)
end
self._MANIFEST = manifest
end
end
return manifest
end
-- save the manifest file of this package
function _instance:manifest_save()
-- make manifest
local manifest = {}
manifest.name = self:name()
manifest.license = self:license()
manifest.description = self:description()
manifest.version = self:version_str()
manifest.kind = self:kind()
manifest.plat = self:plat()
manifest.arch = self:arch()
manifest.mode = self:mode()
manifest.configs = self:configs()
manifest.envs = self:_rawenvs()
-- save enabled library deps
if self:librarydeps() then
manifest.librarydeps = {}
for _, dep in ipairs(self:librarydeps()) do
if dep:exists() then
table.insert(manifest.librarydeps, dep:name())
end
end
end
-- save deps
if self:librarydeps() then
manifest.deps = {}
for _, dep in ipairs(self:librarydeps()) do
manifest.deps[dep:name()] = {
version = dep:version_str(),
buildhash = dep:buildhash()
}
end
end
-- save global variables and component variables
local vars
local extras
local components
local apis = language.apis()
for _, apiname in ipairs(table.join(apis.values, apis.paths, apis.groups)) do
if apiname:startswith("package.add_") or apiname:startswith("package.set_") then
local name = apiname:sub(13)
local values = self:get(name)
if values ~= nil then
vars = vars or {}
vars[name] = values
local extra = self:extraconf(name)
if extra then
extras = extras or {}
extras[name] = extra
end
end
for _, component_name in ipairs(table.wrap(self:get("components"))) do
local comp = self:component(component_name)
if comp then
local component_values = comp:get(name)
if component_values ~= nil then
components = components or {}
components.vars = components.vars or {}
components.vars[component_name] = components.vars[component_name] or {}
components.vars[component_name][name] = component_values
end
end
end
end
end
manifest.vars = vars
manifest.extras = extras
manifest.components = components
-- save repository
local repo = self:repo()
if repo then
manifest.repo = {}
manifest.repo.name = repo:name()
manifest.repo.url = repo:url()
manifest.repo.branch = repo:branch()
manifest.repo.commit = repo:commit()
end
-- save artifacts information to fix the install path in .cmake/.pc files for precompiled artifacts
--
-- @see https://github.com/xmake-io/xmake/issues/2210
--
manifest.artifacts = {}
manifest.artifacts.installdir = self:installdir()
local current_manifest = self:manifest_load()
if current_manifest and current_manifest.artifacts then
manifest.artifacts.remotedir = current_manifest.artifacts.remotedir
end
-- save manifest
local ok, errors = io.save(self:manifest_file(), manifest, { orderkeys = true })
if not ok then
os.raise(errors)
end
end
-- get the raw environments
function _instance:_rawenvs()
local envs = self._RAWENVS
if not envs then
envs = {}
-- add bin PATH
if self:is_binary() or self:is_plat("windows", "mingw") then -- bin/*.dll for windows
envs.PATH = {"bin"}
end
-- add LD_LIBRARY_PATH to load *.so directory
if os.host() ~= "windows" and self:is_plat(os.host()) and self:is_arch(os.arch()) then
envs.LD_LIBRARY_PATH = {"lib"}
if os.host() == "macosx" then
envs.DYLD_LIBRARY_PATH = {"lib"}
end
end
self._RAWENVS = envs
end
return envs
end