forked from Xpra-org/xpra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·2459 lines (2239 loc) · 104 KB
/
setup.py
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
863
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
#!/usr/bin/env python3
# This file is part of Xpra.
# Copyright (C) 2010-2021 Antoine Martin <[email protected]>
# Copyright (C) 2008, 2009, 2010 Nathaniel Smith <[email protected]>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.
##############################################################################
# FIXME: Cython.Distutils.build_ext leaves crud in the source directory.
import sys
if sys.version_info<(3, 6):
raise Exception("xpra no longer supports Python versions older than 3.6")
import glob
import shlex
import shutil
import os.path
import subprocess
from distutils.core import setup
from distutils.extension import Extension
from distutils.command.build import build
from distutils.command.install_data import install_data
import xpra
from xpra.os_util import (
get_status_output, load_binary_file, get_distribution_version_id,
BITS, WIN32, OSX, LINUX, POSIX, NETBSD, FREEBSD, OPENBSD,
is_Ubuntu, is_Debian, is_Fedora, is_CentOS, is_RedHat,
)
#*******************************************************************************
print(" ".join(sys.argv))
#*******************************************************************************
# build options, these may get modified further down..
#
data_files = []
modules = []
packages = [] #used by py2app
excludes = [] #only used by cx_freeze on win32
ext_modules = []
cmdclass = {}
scripts = []
description = "multi-platform screen and application forwarding system"
long_description = "Xpra is a multi platform persistent remote display server and client for " \
"forwarding applications and desktop screens. Also known as 'screen for X11'."
url = "https://xpra.org/"
XPRA_VERSION = xpra.__version__ #@UndefinedVariable
setup_options = {
"name" : "xpra",
"version" : XPRA_VERSION,
"license" : "GPLv2 ",
"author" : "Antoine Martin",
"author_email" : "[email protected]",
"url" : url,
"download_url" : "https://xpra.org/src/",
"description" : description,
"long_description" : long_description,
"data_files" : data_files,
"py_modules" : modules,
}
if "pkg-info" in sys.argv:
with open("PKG-INFO", "wb") as f:
pkg_info_values = setup_options.copy()
pkg_info_values.update({
"metadata_version" : "1.1",
"summary" : description,
"home_page" : url,
})
for k in ("Metadata-Version", "Name", "Version", "Summary", "Home-page",
"Author", "Author-email", "License", "Download-URL", "Description"):
v = pkg_info_values[k.lower().replace("-", "_")]
f.write(("%s: %s\n" % (k, v)).encode())
sys.exit(0)
print("Xpra version %s" % XPRA_VERSION)
#*******************************************************************************
# Most of the options below can be modified on the command line
# using --with-OPTION or --without-OPTION
# only the default values are specified here:
#*******************************************************************************
PKG_CONFIG = os.environ.get("PKG_CONFIG", "pkg-config")
has_pkg_config = False
if PKG_CONFIG:
v = get_status_output([PKG_CONFIG, "--version"])
has_pkg_config = v[0]==0 and v[1]
if has_pkg_config:
print("found pkg-config version: %s" % v[1].strip("\n\r"))
else:
print("WARNING: pkg-config not found!")
for arg in list(sys.argv):
if arg.startswith("--pkg-config-path="):
pcp = arg[len("--pkg-config-path="):]
pcps = [pcp] os.environ.get("PKG_CONFIG_PATH", "").split(os.path.pathsep)
os.environ["PKG_CONFIG_PATH"] = os.path.pathsep.join([x for x in pcps if x])
print("using PKG_CONFIG_PATH=%s" % (os.environ["PKG_CONFIG_PATH"], ))
sys.argv.remove(arg)
def no_pkgconfig(*_pkgs_options, **_ekw):
return {}
def pkg_config_ok(*args):
return get_status_output([PKG_CONFIG] [str(x) for x in args])[0]==0
def pkg_config_version(req_version, pkgname):
cmd = [PKG_CONFIG, "--modversion", pkgname]
r, out, _ = get_status_output(cmd)
if r!=0 or not out:
return False
from distutils.version import LooseVersion
return LooseVersion(out)>=LooseVersion(req_version)
def is_RH():
try:
with open("/etc/redhat-release", mode='rb') as rel:
data = rel.read()
return data.startswith(b"CentOS") or data.startswith(b"RedHat")
except (FileNotFoundError, OSError):
pass
return False
DEFAULT = True
if "--minimal" in sys.argv:
sys.argv.remove("--minimal")
DEFAULT = False
skip_build = "--skip-build" in sys.argv
ARCH = get_status_output(["uname", "-m"])[1]
ARM = ARCH.startswith("arm") or ARCH.startswith("aarch")
print("ARCH=%s" % (ARCH,))
INCLUDE_DIRS = os.environ.get("INCLUDE_DIRS", os.path.join(sys.prefix, "include")).split(os.pathsep)
from xpra.platform.features import LOCAL_SERVERS_SUPPORTED, SHADOW_SUPPORTED
shadow_ENABLED = SHADOW_SUPPORTED and DEFAULT
server_ENABLED = (LOCAL_SERVERS_SUPPORTED or shadow_ENABLED) and DEFAULT
rfb_ENABLED = DEFAULT
service_ENABLED = LINUX and server_ENABLED
sd_listen_ENABLED = POSIX and pkg_config_ok("--exists", "libsystemd")
proxy_ENABLED = DEFAULT
client_ENABLED = DEFAULT
scripts_ENABLED = not WIN32
cython_ENABLED = DEFAULT
cython_tracing_ENABLED = False
modules_ENABLED = DEFAULT
data_ENABLED = DEFAULT
x11_ENABLED = DEFAULT and not WIN32 and not OSX
xinput_ENABLED = x11_ENABLED
uinput_ENABLED = x11_ENABLED
dbus_ENABLED = DEFAULT and x11_ENABLED and not (OSX or WIN32)
gtk_x11_ENABLED = DEFAULT and not WIN32 and not OSX
gtk3_ENABLED = DEFAULT and client_ENABLED
opengl_ENABLED = DEFAULT and client_ENABLED
pam_ENABLED = DEFAULT and (server_ENABLED or proxy_ENABLED) and POSIX and not OSX and any(
(os.path.exists(d "/pam/pam_misc.h") or os.path.exists(d "/security/pam_misc.h")) for d in INCLUDE_DIRS)
xdg_open_ENABLED = (LINUX or FREEBSD) and DEFAULT
netdev_ENABLED = LINUX and DEFAULT
vsock_ENABLED = LINUX and any(os.path.exists(d "/linux/vm_sockets.h") for d in INCLUDE_DIRS)
bencode_ENABLED = DEFAULT
cython_bencode_ENABLED = DEFAULT
rencodeplus_ENABLED = DEFAULT
clipboard_ENABLED = DEFAULT
Xdummy_ENABLED = None if POSIX else False #None means auto-detect
Xdummy_wrapper_ENABLED = None if POSIX else False #None means auto-detect
if WIN32 or OSX:
Xdummy_ENABLED = False
sound_ENABLED = DEFAULT
printing_ENABLED = DEFAULT
crypto_ENABLED = DEFAULT
mdns_ENABLED = DEFAULT
websockets_ENABLED = DEFAULT
enc_proxy_ENABLED = DEFAULT
enc_x264_ENABLED = DEFAULT and pkg_config_version("0.155", "x264")
#crashes on 32-bit windows:
enc_x265_ENABLED = (not WIN32) and pkg_config_ok("--exists", "x265")
pillow_ENABLED = DEFAULT
spng_decoder_ENABLED = DEFAULT and pkg_config_version("0.6", "spng")
spng_encoder_ENABLED = DEFAULT and pkg_config_version("0.7", "spng")
webp_ENABLED = DEFAULT and pkg_config_version("0.5", "libwebp")
jpeg_encoder_ENABLED = DEFAULT and pkg_config_version("1.2", "libturbojpeg")
jpeg_decoder_ENABLED = DEFAULT and pkg_config_version("1.4", "libturbojpeg")
vpx_ENABLED = DEFAULT and pkg_config_version("1.4", "vpx")
enc_ffmpeg_ENABLED = DEFAULT and BITS==64 and pkg_config_version("58.18", "libavcodec")
#opencv currently broken on 32-bit windows (crashes on load):
webcam_ENABLED = DEFAULT and not OSX and not WIN32
notifications_ENABLED = DEFAULT
keyboard_ENABLED = DEFAULT
v4l2_ENABLED = DEFAULT and (not WIN32 and not OSX and not FREEBSD and not OPENBSD)
#ffmpeg 3.1 or later is required
dec_avcodec2_ENABLED = DEFAULT and BITS==64 and pkg_config_version("57", "libavcodec")
csc_swscale_ENABLED = DEFAULT and BITS==64 and pkg_config_ok("--exists", "libswscale")
csc_cython_ENABLED = DEFAULT
nvjpeg_ENABLED = DEFAULT and not OSX and not ARM and BITS==64 and pkg_config_ok("--exists", "nvjpeg")
nvenc_ENABLED = DEFAULT and not OSX and not ARM and BITS==64 and pkg_config_version("10", "nvenc")
nvfbc_ENABLED = DEFAULT and not OSX and not ARM and BITS==64 and pkg_config_ok("--exists", "nvfbc")
cuda_kernels_ENABLED = DEFAULT and not OSX
cuda_rebuild_ENABLED = DEFAULT
csc_libyuv_ENABLED = DEFAULT and pkg_config_ok("--exists", "libyuv")
example_ENABLED = DEFAULT
#Cython / gcc / packaging build options:
docs_ENABLED = DEFAULT
annotate_ENABLED = DEFAULT
warn_ENABLED = True
strict_ENABLED = True
PIC_ENABLED = not WIN32 #ming32 moans that it is always enabled already
debug_ENABLED = False
verbose_ENABLED = False
bundle_tests_ENABLED = False
tests_ENABLED = False
rebuild_ENABLED = not skip_build
#allow some of these flags to be modified on the command line:
SWITCHES = [
"cython", "cython_tracing",
"modules", "data",
"enc_x264", "enc_x265", "enc_ffmpeg",
"nvenc", "cuda_kernels", "cuda_rebuild", "nvfbc",
"vpx", "webp", "pillow", "spng_decoder", "spng_encoder", "jpeg_encoder", "jpeg_decoder",
"nvjpeg",
"v4l2",
"dec_avcodec2", "csc_swscale",
"csc_cython", "csc_libyuv",
"bencode", "cython_bencode", "rencodeplus",
"vsock", "netdev", "mdns",
"clipboard",
"scripts",
"server", "client", "dbus", "x11", "xinput", "uinput", "sd_listen",
"gtk_x11", "service",
"gtk3", "example",
"pam", "xdg_open",
"sound", "opengl", "printing", "webcam", "notifications", "keyboard",
"rebuild",
"docs",
"annotate", "warn", "strict",
"shadow", "proxy", "rfb",
"debug", "PIC",
"Xdummy", "Xdummy_wrapper", "verbose", "tests", "bundle_tests",
]
HELP = "-h" in sys.argv or "--help" in sys.argv
if HELP:
setup()
print("Xpra specific build and install switches:")
for x in SWITCHES:
d = vars()["%s_ENABLED" % x]
with_str = " --with-%s" % x
without_str = " --without-%s" % x
if d is True or d is False:
default_str = str(d)
else:
default_str = "auto-detect"
print("%s or %s (default: %s)" % (with_str.ljust(25), without_str.ljust(30), default_str))
print(" --pkg-config-path=PATH")
print(" --rpath=PATH")
sys.exit(0)
install = None
rpath = None
ssl_cert = None
ssl_key = None
minifier = None
share_xpra = None
filtered_args = []
for arg in sys.argv:
matched = False
for x in ("rpath", "ssl-cert", "ssl-key", "install", "share-xpra"):
varg = "--%s=" % x
if arg.startswith(varg):
value = arg[len(varg):]
globals()[x.replace("-", "_")] = value
#remove these arguments from sys.argv,
#except for --install=PATH
matched = x!="install"
break
if matched:
continue
for x in SWITCHES:
with_str = "--with-%s" % x
without_str = "--without-%s" % x
if arg.startswith(with_str "="):
vars()["%s_ENABLED" % x] = arg[len(with_str) 1:]
matched = True
break
elif arg==with_str:
vars()["%s_ENABLED" % x] = True
matched = True
break
elif arg==without_str:
vars()["%s_ENABLED" % x] = False
matched = True
break
if not matched:
filtered_args.append(arg)
sys.argv = filtered_args
if "clean" not in sys.argv:
switches_info = {}
for x in SWITCHES:
switches_info[x] = vars()["%s_ENABLED" % x]
print("build switches:")
for k in sorted(SWITCHES):
v = switches_info[k]
print("* %s : %s" % (str(k).ljust(20), {None : "Auto", True : "Y", False : "N"}.get(v, v)))
if not cython_ENABLED:
enc_ffmpeg_ENABLED = enc_x264_ENABLED = enc_x265_ENABLED = nvenc_ENABLED = False
csc_swscale_ENABLED = csc_libyuv_ENABLED = csc_cython_ENABLED = False
vpx_ENABLED = nvfbc_ENABLED = dec_avcodec2_ENABLED = False
spng_decoder_ENABLED = spng_encoder_ENABLED = False
webp_ENABLED = jpeg_encoder_ENABLED = jpeg_decoder_ENABLED = False
server_ENABLED = client_ENABLED = shadow_ENABLED = False
cython_bencode_ENABLED = rencodeplus_ENABLED = False
gtk3_ENABLED = False
x11_ENABLED = False
#sanity check the flags:
if clipboard_ENABLED and not server_ENABLED and not gtk3_ENABLED:
print("Warning: clipboard can only be used with the server or one of the gtk clients!")
clipboard_ENABLED = False
if x11_ENABLED and WIN32:
print("Warning: enabling x11 on MS Windows is unlikely to work!")
if gtk_x11_ENABLED and not x11_ENABLED:
print("Error: you must enable x11 to support gtk_x11!")
exit(1)
if client_ENABLED and not gtk3_ENABLED:
print("Warning: client is enabled but none of the client toolkits are!?")
if DEFAULT and (not client_ENABLED and not server_ENABLED):
print("Warning: you probably want to build at least the client or server!")
if DEFAULT and not pillow_ENABLED:
print("Warning: including Python Pillow is VERY STRONGLY recommended")
if DEFAULT and (not enc_x264_ENABLED and not vpx_ENABLED):
print("Warning: no x264 and no vpx support!")
print(" you should enable at least one of these two video encodings")
if install is None and WIN32:
install = os.environ.get("MINGW_PREFIX", sys.prefix or "dist")
if share_xpra is None:
share_xpra = os.path.join("share", "xpra")
def should_rebuild(src_file, bin_file):
if not os.path.exists(bin_file):
return "no file"
if rebuild_ENABLED:
if os.path.getctime(bin_file)<os.path.getctime(src_file):
return "binary file out of date"
if os.path.getctime(bin_file)<os.path.getctime(__file__):
return "newer build file"
return None
def convert_doc(fsrc, fdst, fmt="html", force=False):
bsrc = os.path.basename(fsrc)
bdst = os.path.basename(fdst)
if not force and not should_rebuild(fsrc, fdst):
return
print(" %-20s -> %s" % (bsrc, bdst))
pandoc = os.environ.get("PANDOC", "pandoc")
cmd = [pandoc, "--from", "markdown", "--to", fmt, "-o", fdst, fsrc]
if fmt=="html":
if is_Ubuntu() and get_distribution_version_id()<="18.04":
print("pandoc is missing the lua-filter option")
print(" cannot preserve HTML links in documentation")
else:
cmd = ["--lua-filter", "./fs/bin/links-to-html.lua"]
r = subprocess.Popen(cmd).wait(30)
assert r==0, "'%s' returned %s" % (" ".join(cmd), r)
def convert_doc_dir(src, dst, fmt="html", force=False):
print("%-20s -> %s" % (src, dst))
if not os.path.exists(dst):
os.makedirs(dst, mode=0o755)
for x in os.listdir(src):
fsrc = os.path.join(src, x)
if os.path.isdir(fsrc):
fdst = os.path.join(dst, x)
convert_doc_dir(fsrc, fdst, fmt, force)
elif fsrc.endswith(".md"):
fdst = os.path.join(dst, x.replace("README", "index")[:-3] "." fmt)
convert_doc(fsrc, fdst, fmt, force)
elif fsrc.endswith(".png"):
fdst = os.path.join(dst, x)
print("copying %s -> %s (%s)" % (fsrc, fdst, oct(0o644)))
os.makedirs(name=dst, mode=0o755, exist_ok=True)
data = load_binary_file(fsrc)
with open(fdst, "wb") as f:
f.write(data)
os.chmod(fdst, 0o644)
else:
print("ignoring '%s'" % fsrc)
def convert_docs(fmt="html"):
paths = [x for x in sys.argv[2:] if not x.startswith("--")]
if len(paths)==1 and os.path.isdir(paths[0]):
convert_doc_dir("docs", paths[0])
elif paths:
for x in paths:
convert_doc(x, "build/%s" % x)
else:
convert_doc_dir("docs", "build/docs")
if "doc" in sys.argv:
convert_docs("html")
sys.exit(0)
if "pdf-doc" in sys.argv:
convert_docs("pdf")
sys.exit(0)
if "unittests" in sys.argv:
os.execv("./tests/unittests/run", ["run"])
#*******************************************************************************
# default sets:
external_includes = ["hashlib",
"ctypes", "platform"]
if gtk3_ENABLED or sound_ENABLED:
external_includes = ["gi"]
external_excludes = [
#Tcl/Tk
"Tkconstants", "tkinter", "tcl",
#PIL bits that import TK:
"PIL._tkinter_finder", "_imagingtk", "PIL._imagingtk", "ImageTk", "PIL.ImageTk", "FixTk",
#formats we don't use:
"GimpGradientFile", "GimpPaletteFile", "BmpImagePlugin", "TiffImagePlugin",
#not used:
"curses", "pdb",
"tty",
"setuptools", "doctest"
"nose", "pytest", "_pytest", "pluggy", "more_itertools", "apipkg", "py", "funcsigs",
"Cython", "cython", "pyximport",
"pydoc_data",
]
if not crypto_ENABLED:
external_excludes = ["ssl", "_ssl"]
if not client_ENABLED:
external_excludes = ["mimetools"]
if not client_ENABLED and not server_ENABLED:
excludes = ["PIL"]
if not dbus_ENABLED:
excludes = ["dbus"]
#because of differences in how we specify packages and modules
#for distutils / py2app and cx_freeze
#use the following functions, which should get the right
#data in the global variables "packages", "modules" and "excludes"
def remove_packages(*mods):
""" ensures that the given packages are not included:
removes them from the "modules" and "packages" list and adds them to "excludes" list
"""
global packages, modules, excludes
for m in list(modules):
for x in mods:
if m.startswith(x):
modules.remove(m)
break
for x in mods:
if x in packages:
packages.remove(x)
if x not in excludes:
excludes.append(x)
def add_packages(*pkgs):
""" adds the given packages to the packages list,
and adds all the modules found in this package (including the package itself)
"""
global packages
for x in pkgs:
if x not in packages:
packages.append(x)
add_modules(*pkgs)
def add_modules(*mods):
def add(v):
global modules
if v not in modules:
modules.append(v)
do_add_modules(add, *mods)
def do_add_modules(op, *mods):
""" adds the packages and any .py module found in the packages to the "modules" list
"""
global modules
for x in mods:
#ugly path stripping:
if x.startswith("./"):
x = x[2:]
if x.endswith(".py"):
x = x[:-3]
x = x.replace("/", ".") #.replace("\\", ".")
pathname = os.path.sep.join(x.split("."))
#is this a file module?
f = "%s.py" % pathname
if os.path.exists(f) and os.path.isfile(f):
op(x)
if os.path.exists(pathname) and os.path.isdir(pathname):
#add all file modules found in this directory
for f in os.listdir(pathname):
#make sure we only include python files,
#and ignore eclipse copies
if f.endswith(".py") and not f.startswith("Copy ")<0:
fname = os.path.join(pathname, f)
if os.path.isfile(fname):
modname = "%s.%s" % (x, f.replace(".py", ""))
op(modname)
def toggle_packages(enabled, *module_names):
if enabled:
add_packages(*module_names)
else:
remove_packages(*module_names)
def toggle_modules(enabled, *module_names):
if enabled:
def op(v):
global modules
if v not in modules:
modules.append(v)
do_add_modules(op, *module_names)
else:
remove_packages(*module_names)
#always included:
if modules_ENABLED:
add_modules("xpra", "xpra.platform", "xpra.net")
add_modules("xpra.scripts.main")
def add_data_files(target_dir, files):
#this is overriden below because cx_freeze uses the opposite structure (files first...). sigh.
assert isinstance(target_dir, str)
assert isinstance(files, (list, tuple))
data_files.append((target_dir, files))
#for pretty printing of options:
def print_option(prefix, k, v):
if isinstance(v, dict):
print("%s* %s:" % (prefix, k))
for kk,vv in v.items():
print_option(" " prefix, kk, vv)
else:
print("%s* %s=%s" % (prefix, k, v))
#*******************************************************************************
# Utility methods for building with Cython
compiler_directives = {
"auto_pickle" : False,
"language_level" : 3,
"cdivision" : True,
"always_allow_keywords" : False,
"unraisable_tracebacks" : True,
}
if strict_ENABLED and verbose_ENABLED:
compiler_directives.update({
#"warn.undeclared" : True,
#"warn.maybe_uninitialized" : True,
"warn.unused" : True,
"warn.unused_result" : True,
})
if cython_tracing_ENABLED:
compiler_directives.update({
"linetrace" : True,
"binding" : True,
"profile" : True,
})
def add_cython_ext(*args, **kwargs):
if "--no-compile" in sys.argv and not ("build" in sys.argv and "install" in sys.argv):
return
assert cython_ENABLED, "cython compilation is disabled"
if cython_tracing_ENABLED:
kwargs["define_macros"] = [
('CYTHON_TRACE', 1),
('CYTHON_TRACE_NOGIL', 1),
]
extra_compile_args = kwargs.setdefault("extra_compile_args", [])
extra_compile_args = ["-fpermissive", "-Wno-error"]
from Cython.Distutils import build_ext
global cmdclass, ext_modules
ext_modules.append(Extension(*args, **kwargs))
cmdclass['build_ext'] = build_ext
def insert_into_keywords(kw, key, *args):
values = kw.setdefault(key, [])
for arg in args:
values.insert(0, arg)
def add_to_keywords(kw, key, *args):
values = kw.setdefault(key, [])
for arg in args:
values.append(arg)
def remove_from_keywords(kw, key, value):
values = kw.get(key)
while values and value in values:
values.remove(value)
def checkdirs(*dirs):
for d in dirs:
if not os.path.exists(d) or not os.path.isdir(d):
raise Exception("cannot find a directory which is required for building: '%s'" % d)
GCC_VERSION = []
def get_gcc_version():
global GCC_VERSION
if not GCC_VERSION:
cc = os.environ.get("CC", "gcc")
r, _, err = get_status_output([cc] ["-v"])
if r==0:
V_LINE = "gcc version "
for line in err.splitlines():
if line.startswith(V_LINE):
v_str = line[len(V_LINE):].split(" ")[0]
for p in v_str.split("."):
try:
GCC_VERSION.append(int(p))
except ValueError:
break
print("found gcc version: %s" % ".".join([str(x) for x in GCC_VERSION]))
break
return GCC_VERSION
# Tweaked from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/502261
def exec_pkgconfig(*pkgs_options, **ekw):
kw = dict(ekw)
optimize = kw.pop("optimize", None)
if "INCLUDE_DIRS" in os.environ:
for d in INCLUDE_DIRS:
add_to_keywords(kw, 'extra_compile_args', "-I", d)
if optimize and not debug_ENABLED and not cython_tracing_ENABLED:
if isinstance(optimize, bool):
optimize = int(optimize)*3
add_to_keywords(kw, 'extra_compile_args', "-O%i" % optimize)
ignored_flags = kw.pop("ignored_flags", [])
ignored_tokens = kw.pop("ignored_tokens", [])
#for distros that don't patch distutils,
#we have to add the python cflags:
if not (is_Fedora() or is_Debian() or is_CentOS() or is_RedHat()):
import sysconfig
for cflag in shlex.split(sysconfig.get_config_var('CFLAGS') or ''):
add_to_keywords(kw, 'extra_compile_args', cflag)
def add_tokens(s, extra="extra_link_args", extra_map={"-W" : "extra_compile_args"}):
if not s:
return
flag_map = {'-I': 'include_dirs',
'-L': 'library_dirs',
'-l': 'libraries'}
for token in shlex.split(s):
if token in ignored_tokens:
pass
elif token[:2] in ignored_flags:
pass
elif token[:2] in flag_map:
if len(token)>2:
add_to_keywords(kw, flag_map.get(token[:2]), token[2:])
else:
print("Warning: invalid token '%s'" % token)
else:
extra_name = extra_map.get(token, extra)
add_to_keywords(kw, extra_name, token)
if pkgs_options:
pkg_config_cmd = ["pkg-config", "--libs", "--cflags", "%s" % (" ".join(pkgs_options),)]
if verbose_ENABLED:
print("pkg_config_cmd=%s" % (pkg_config_cmd,))
r, pkg_config_out, err = get_status_output(pkg_config_cmd)
if r!=0:
sys.exit("ERROR: call to '%s' failed (err=%s)" % (" ".join(pkg_config_cmd), err))
add_tokens(pkg_config_out)
if warn_ENABLED:
add_to_keywords(kw, 'extra_compile_args', "-Wall")
add_to_keywords(kw, 'extra_link_args', "-Wall")
if strict_ENABLED:
if os.environ.get("CC", "").find("clang")>=0:
#clang emits too many warnings with cython code,
#so we can't enable Werror without turning off some warnings:
#this list of flags should allow clang to build the whole source tree,
#as of Cython 0.26 clang 4.0. Other version combinations may require
#(un)commenting other switches.
eifd = ["-Werror",
#"-Wno-unneeded-internal-declaration",
#"-Wno-unknown-attributes",
#"-Wno-unused-function",
#"-Wno-self-assign",
#"-Wno-sometimes-uninitialized",
#cython adds rpath to the compilation command??
#and the "-specs=/usr/lib/rpm/redhat/redhat-hardened-cc1" is also ignored by clang:
"-Wno-deprecated-register",
"-Wno-unused-command-line-argument",
]
elif get_gcc_version()>=[4, 4]:
eifd = ["-Werror"]
if NETBSD:
#see: http://trac.cython.org/ticket/395
eifd = ["-fno-strict-aliasing"]
elif FREEBSD:
eifd = ["-Wno-error=unused-function"]
else:
#older versions of OSX ship an old gcc,
#not much we can do with this:
eifd = []
for eif in eifd:
add_to_keywords(kw, 'extra_compile_args', eif)
remove_from_keywords(kw, 'extra_compile_args', "-fpermissive")
if PIC_ENABLED:
add_to_keywords(kw, 'extra_compile_args', "-fPIC")
if debug_ENABLED:
add_to_keywords(kw, 'extra_compile_args', '-g')
add_to_keywords(kw, 'extra_compile_args', '-ggdb')
if get_gcc_version()>=[4, 8] and not WIN32:
add_to_keywords(kw, 'extra_compile_args', '-fsanitize=address')
add_to_keywords(kw, 'extra_link_args', '-fsanitize=address')
if rpath and kw.get("libraries"):
insert_into_keywords(kw, "library_dirs", rpath)
insert_into_keywords(kw, "extra_link_args", "-Wl,-rpath=%s" % rpath)
add_tokens(os.environ.get("CFLAGS"), "extra_compile_args", {})
add_tokens(os.environ.get("LDFLAGS"), "extra_link_args", {})
#add_to_keywords(kw, 'include_dirs', '.')
if verbose_ENABLED:
print("exec_pkgconfig(%s,%s)=%s" % (pkgs_options, ekw, kw))
return kw
pkgconfig = exec_pkgconfig
#*******************************************************************************
def get_base_conf_dir(install_dir, stripbuildroot=True):
#in some cases we want to strip the buildroot (to generate paths in the config file)
#but in other cases we want the buildroot path (when writing out the config files)
#and in some cases, we don't have the install_dir specified (called from detect_xorg_setup, and that's fine too)
#this is a bit hackish, but I can't think of a better way of detecting it
#(ie: "$HOME/rpmbuild/BUILDROOT/xpra-0.15.0-0.fc21.x86_64/usr")
dirs = (install_dir or sys.prefix).split(os.path.sep)
if install_dir and stripbuildroot:
pkgdir = os.environ.get("pkgdir")
if "debian" in dirs and "tmp" in dirs:
#ugly fix for stripping the debian tmp dir:
#ie: "???/tmp/???/tags/v0.15.x/src/debian/tmp/" -> ""
while "tmp" in dirs:
dirs = dirs[dirs.index("tmp") 1:]
elif "debian" in dirs:
#same for recent debian versions:
#ie: "xpra-2.0.2/debian/xpra/usr" -> "usr"
i = dirs.index("debian")
while i>=0 and len(dirs)>i 1:
if dirs[i 1] == "xpra":
dirs = dirs[i 2:]
i = dirs.index("debian")
elif "BUILDROOT" in dirs:
#strip rpm style build root:
#[$HOME, "rpmbuild", "BUILDROOT", "xpra-$VERSION"] -> []
dirs = dirs[dirs.index("BUILDROOT") 2:]
elif "pkg" in dirs:
#archlinux
#ie: "/build/xpra/pkg/xpra/etc" -> "etc"
#find the last 'pkg' from the list of directories:
i = max(loc for loc, val in enumerate(dirs) if val == "pkg")
if len(dirs)>i 1 and dirs[i 1] in ("xpra", "xpra-git"):
dirs = dirs[i 2:]
elif pkgdir and install_dir.startswith(pkgdir):
#arch build dir:
dirs = install_dir.lstrip(pkgdir).split(os.path.sep)
elif "usr" in dirs:
#ie: ["some", "path", "to", "usr"] -> ["usr"]
#assume "/usr" or "/usr/local" is the build root
while "usr" in dirs[1:]:
dirs = dirs[dirs[1:].index("usr") 1:]
elif "image" in dirs:
# Gentoo's "${PORTAGE_TMPDIR}/portage/${CATEGORY}/${PF}/image/_python2.7" -> ""
while "image" in dirs:
dirs = dirs[dirs.index("image") 2:]
#now deal with the fact that "/etc" is used for the "/usr" prefix
#but "/usr/local/etc" is used for the "/usr/local" prefix..
if dirs and dirs[-1]=="usr":
dirs = dirs[:-1]
#is this an absolute path?
if not dirs or dirs[0]=="usr" or (install_dir or sys.prefix).startswith(os.path.sep):
#ie: ["/", "usr"] or ["/", "usr", "local"]
dirs.insert(0, os.path.sep)
return dirs
def get_conf_dir(install_dir, stripbuildroot=True):
dirs = get_base_conf_dir(install_dir, stripbuildroot)
if "etc" not in dirs:
dirs.append("etc")
dirs.append("xpra")
return os.path.join(*dirs)
def detect_xorg_setup(install_dir=None):
from xpra.scripts import config
config.debug = config.warn
conf_dir = get_conf_dir(install_dir)
return config.detect_xvfb_command(conf_dir, None, Xdummy_ENABLED, Xdummy_wrapper_ENABLED)
def build_xpra_conf(install_dir):
print("build_xpra_conf(%s)" % install_dir)
#generates an actual config file from the template
xvfb_command = detect_xorg_setup(install_dir)
fake_xinerama = "no"
if POSIX and not OSX and not (is_Debian() or is_Ubuntu()):
from xpra.x11.fakeXinerama import find_libfakeXinerama
fake_xinerama = find_libfakeXinerama() or "auto"
from xpra.platform.features import DEFAULT_ENV, SOURCE
def bstr(b):
if b is None:
return "auto"
return "yes" if int(b) else "no"
start_env = "\n".join("start-env = %s" % x for x in DEFAULT_ENV)
source = "\n".join("source = %s" % x for x in SOURCE)
conf_dir = get_conf_dir(install_dir)
print("get_conf_dir(%s)=%s" % (install_dir, conf_dir))
from xpra.platform.features import DEFAULT_PULSEAUDIO_CONFIGURE_COMMANDS
from xpra.platform.paths import get_socket_dirs
from xpra.scripts.config import (
xvfb_cmd_str,
get_default_key_shortcuts, get_default_systemd_run, get_default_pulseaudio_command,
DEFAULT_POSTSCRIPT_PRINTER, DEFAULT_PULSEAUDIO,
)
#remove build paths and user specific paths with UID ("/run/user/UID/Xpra"):
socket_dirs = get_socket_dirs()
if POSIX and os.getuid()>0:
#remove any paths containing the uid,
#osx uses /var/tmp/$UID-Xpra,
#but this should not be included in the default config for all users!
#(the buildbot's uid!)
socket_dirs = [x for x in socket_dirs if x.find(str(os.getuid()))<0]
#FIXME: we should probably get these values from the default config instead
pdf, postscript = "", ""
if POSIX and printing_ENABLED:
try:
if "/usr/sbin" not in sys.path:
sys.path.append("/usr/sbin")
from xpra.platform.pycups_printing import get_printer_definition
print("probing cups printer definitions")
pdf = get_printer_definition("pdf")
postscript = get_printer_definition("postscript") or DEFAULT_POSTSCRIPT_PRINTER
print("pdf=%s, postscript=%s" % (pdf, postscript))
except Exception as e:
print("could not probe for pdf/postscript printers: %s" % e)
def pretty_cmd(cmd):
return " ".join(cmd)
#OSX doesn't have webcam support yet (no opencv builds on 10.5.x)
webcam = webcam_ENABLED and not (OSX or WIN32)
#no python-avahi on RH / CentOS, need dbus module on *nix:
mdns = mdns_ENABLED and (OSX or WIN32 or (not is_RH() and dbus_ENABLED))
SUBS = {
'xvfb_command' : xvfb_cmd_str(xvfb_command, wrap=True),
'fake_xinerama' : fake_xinerama,
'ssh_command' : "auto",
'key_shortcuts' : "".join(("key-shortcut = %s\n" % x) for x in get_default_key_shortcuts()),
'remote_logging' : "both",
'start_env' : start_env,
'pulseaudio' : bstr(DEFAULT_PULSEAUDIO),
'pulseaudio_command' : pretty_cmd(get_default_pulseaudio_command()),
'pulseaudio_configure_commands' : "\n".join(("pulseaudio-configure-commands = %s" % pretty_cmd(x)) for x in DEFAULT_PULSEAUDIO_CONFIGURE_COMMANDS),
'conf_dir' : conf_dir,
'bind' : "auto",
'ssl_cert' : ssl_cert or "",
'ssl_key' : ssl_key or "",
'systemd_run' : get_default_systemd_run(),
'socket_dirs' : "".join(("socket-dirs = %s\n" % x) for x in socket_dirs),
'log_dir' : "auto",
"source" : source,
'mdns' : bstr(mdns),
'notifications' : bstr(OSX or WIN32 or dbus_ENABLED),
'dbus_proxy' : bstr(not OSX and not WIN32 and dbus_ENABLED),
'pdf_printer' : pdf,
'postscript_printer' : postscript,
'webcam' : ["no", "auto"][webcam],
'mousewheel' : "on",
'printing' : bstr(printing_ENABLED),
'dbus_control' : bstr(dbus_ENABLED),
'mmap' : bstr(True),
'opengl' : "probe",
'headerbar' : ["auto", "no"][OSX or WIN32],
}
def convert_templates(subdirs):
dirname = os.path.join(*(["fs", "etc", "xpra"] subdirs))
#get conf dir for install, without stripping the build root
target_dir = os.path.join(get_conf_dir(install_dir, stripbuildroot=False), *subdirs)
print("convert_templates(%s) dirname=%s, target_dir=%s" % (subdirs, dirname, target_dir))
if not os.path.exists(target_dir):
try:
os.makedirs(target_dir)
except Exception as e:
print("cannot create target dir '%s': %s" % (target_dir, e))
for f in sorted(os.listdir(dirname)):
if f.endswith("osx.conf.in") and not OSX:
continue
filename = os.path.join(dirname, f)
if os.path.isdir(filename):
convert_templates(subdirs [f])
continue
if not f.endswith(".in"):
continue
with open(filename, "r") as f_in:
template = f_in.read()
target_file = os.path.join(target_dir, f[:-len(".in")])
print("generating %s from %s" % (target_file, f))
with open(target_file, "w") as f_out:
config_data = template % SUBS
f_out.write(config_data)
convert_templates([])
#*******************************************************************************
def clean():
#clean and sdist don't actually use cython,
#so skip this (and avoid errors)
global pkgconfig
pkgconfig = no_pkgconfig
#always include everything in this case:
add_packages("xpra")
#ensure we remove the files we generate:
CLEAN_FILES = [
"xpra/build_info.py",
"xpra/gtk_common/gtk3/gdk_atoms.c",
"xpra/gtk_common/gtk3/gdk_bindings.c",
"xpra/x11/gtk3/gdk_bindings.c",
"xpra/x11/gtk3/gdk_display_source.c",
"xpra/x11/bindings/wait_for_x_server.c",
"xpra/x11/bindings/keyboard_bindings.c",
"xpra/x11/bindings/display_source.c",
"xpra/x11/bindings/window_bindings.c",
"xpra/x11/bindings/randr_bindings.c",
"xpra/x11/bindings/res_bindings.c",
"xpra/x11/bindings/core_bindings.c",
"xpra/x11/bindings/posix_display_source.c",
"xpra/x11/bindings/ximage.c",
"xpra/x11/bindings/xi2_bindings.c",
"xpra/platform/win32/propsys.cpp",
"xpra/platform/darwin/gdk_bindings.c",
"xpra/platform/xposix/sd_listen.c",
"xpra/platform/xposix/netdev_query.c",
"xpra/net/bencode/cython_bencode.c",
"xpra/net/rencodeplus/rencodeplus.c",
"xpra/net/websockets/mask.c",
"xpra/net/vsock.c",
"xpra/buffers/membuf.c",
"xpra/buffers/xxh.c",
"xpra/buffers/cyxor.c",
"xpra/codecs/vpx/encoder.c",
"xpra/codecs/vpx/decoder.c",
"xpra/codecs/nvenc/encoder.c",
"xpra/codecs/nvfbc/fbc_capture_linux.cpp",
"xpra/codecs/nvfbc/fbc_capture_win.cpp",
"xpra/codecs/enc_x264/encoder.c",
"xpra/codecs/enc_x265/encoder.c",
"xpra/codecs/spng/decoder.c",
"xpra/codecs/jpeg/encoder.c",
"xpra/codecs/jpeg/decoder.c",
"xpra/codecs/enc_ffmpeg/encoder.c",
"xpra/codecs/v4l2/pusher.c",
"xpra/codecs/v4l2/constants.pxi",
"xpra/codecs/libav_common/av_log.c",
"xpra/codecs/webp/encoder.c",
"xpra/codecs/webp/decoder.c",
"xpra/codecs/dec_avcodec2/decoder.c",
"xpra/codecs/csc_libyuv/colorspace_converter.cpp",
"xpra/codecs/csc_swscale/colorspace_converter.c",
"xpra/codecs/csc_cython/colorspace_converter.c",
"xpra/codecs/argb/argb.c",
"xpra/codecs/nvapi_version.c",
"xpra/gtk_common/gdk_atoms.c",
"xpra/client/gtk3/cairo_workaround.c",
"xpra/server/cystats.c",
"xpra/rectangle.c",
"xpra/server/window/motion.c",
"xpra/server/pam.c",
"fs/etc/xpra/xpra.conf",