1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <dp_platform.hxx>
22 #include <rtl/ustring.hxx>
23 #include <rtl/instance.hxx>
24 #include <rtl/bootstrap.hxx>
25 #include <osl/diagnose.h>
26 #include <o3tl/string_view.hxx>
28 constexpr OUStringLiteral PLATFORM_ALL
= u
"all";
35 const OUString
& StrOperatingSystem()
37 static const OUString theOS
= []()
39 OUString
os( "$_OS" );
40 ::rtl::Bootstrap::expandMacros( os
);
46 const OUString
& StrCPU()
48 static const OUString theCPU
= []()
50 OUString
arch( "$_ARCH" );
51 ::rtl::Bootstrap::expandMacros( arch
);
58 const OUString
& StrPlatform()
60 static const OUString thePlatform
= StrOperatingSystem() + "_" + StrCPU();
64 bool checkOSandCPU(std::u16string_view os
, std::u16string_view cpu
)
66 return (os
== StrOperatingSystem())
70 bool isPlatformSupported( std::u16string_view token
)
73 if (token
== PLATFORM_ALL
)
75 else if (token
== u
"windows_x86")
76 ret
= checkOSandCPU(u
"Windows", u
"x86");
77 else if (token
== u
"windows_x86_64")
78 ret
= checkOSandCPU(u
"Windows", u
"X86_64");
79 else if (token
== u
"windows_aarch64")
80 ret
= checkOSandCPU(u
"Windows", u
"AARCH64");
81 else if (token
== u
"solaris_sparc")
82 ret
= checkOSandCPU(u
"Solaris", u
"SPARC");
83 else if (token
== u
"solaris_sparc64")
84 ret
= checkOSandCPU(u
"Solaris", u
"SPARC64");
85 else if (token
== u
"solaris_x86")
86 ret
= checkOSandCPU(u
"Solaris", u
"x86");
87 else if (token
== u
"macosx_aarch64")
88 ret
= checkOSandCPU(u
"MacOSX", u
"AARCH64");
89 else if (token
== u
"macosx_x86_64")
90 ret
= checkOSandCPU(u
"MacOSX", u
"X86_64");
91 else if (token
== u
"linux_x86")
92 ret
= checkOSandCPU(u
"Linux", u
"x86");
93 else if (token
== u
"linux_x86_64")
94 ret
= checkOSandCPU(u
"Linux", u
"X86_64");
95 else if (token
== u
"linux_sparc")
96 ret
= checkOSandCPU(u
"Linux", u
"SPARC");
97 else if (token
== u
"linux_sparc64")
98 ret
= checkOSandCPU(u
"Linux", u
"SPARC64");
99 else if (token
== u
"linux_powerpc")
100 ret
= checkOSandCPU(u
"Linux", u
"PowerPC");
101 else if (token
== u
"linux_powerpc64")
102 ret
= checkOSandCPU(u
"Linux", u
"PowerPC_64");
103 else if (token
== u
"linux_powerpc64_le")
104 ret
= checkOSandCPU(u
"Linux", u
"PowerPC_64_LE");
105 else if (token
== u
"linux_arm_eabi")
106 ret
= checkOSandCPU(u
"Linux", u
"ARM_EABI");
107 else if (token
== u
"linux_arm_oabi")
108 ret
= checkOSandCPU(u
"Linux", u
"ARM_OABI");
109 else if (token
== u
"linux_mips_el")
110 ret
= checkOSandCPU(u
"Linux", u
"MIPS_EL");
111 else if (token
== u
"linux_mips64_el")
112 ret
= checkOSandCPU(u
"Linux", u
"MIPS64_EL");
113 else if (token
== u
"linux_mips_eb")
114 ret
= checkOSandCPU(u
"Linux", u
"MIPS_EB");
115 else if (token
== u
"linux_mips64_eb")
116 ret
= checkOSandCPU(u
"Linux", u
"MIPS64_EB");
117 else if (token
== u
"linux_ia64")
118 ret
= checkOSandCPU(u
"Linux", u
"IA64");
119 else if (token
== u
"linux_m68k")
120 ret
= checkOSandCPU(u
"Linux", u
"M68K");
121 else if (token
== u
"linux_s390x")
122 ret
= checkOSandCPU(u
"Linux", u
"S390x");
123 else if (token
== u
"linux_hppa")
124 ret
= checkOSandCPU(u
"Linux", u
"HPPA");
125 else if (token
== u
"linux_alpha")
126 ret
= checkOSandCPU(u
"Linux", u
"ALPHA");
127 else if (token
== u
"linux_aarch64")
128 ret
= checkOSandCPU(u
"Linux", u
"AARCH64");
129 else if (token
== u
"linux_riscv64")
130 ret
= checkOSandCPU(u
"Linux", u
"RISCV64");
131 else if (token
== u
"linux_loongarch64")
132 ret
= checkOSandCPU(u
"Linux", u
"LOONGARCH64");
133 else if (token
== u
"freebsd_x86")
134 ret
= checkOSandCPU(u
"FreeBSD", u
"x86");
135 else if (token
== u
"freebsd_x86_64")
136 ret
= checkOSandCPU(u
"FreeBSD", u
"X86_64");
137 else if (token
== u
"freebsd_powerpc")
138 ret
= checkOSandCPU(u
"FreeBSD", u
"PowerPC");
139 else if (token
== u
"freebsd_powerpc64")
140 ret
= checkOSandCPU(u
"FreeBSD", u
"PowerPC64");
141 else if (token
== u
"kfreebsd_x86")
142 ret
= checkOSandCPU(u
"kFreeBSD", u
"x86");
143 else if (token
== u
"kfreebsd_x86_64")
144 ret
= checkOSandCPU(u
"kFreeBSD", u
"X86_64");
145 else if (token
== u
"netbsd_x86")
146 ret
= checkOSandCPU(u
"NetBSD", u
"x86");
147 else if (token
== u
"netbsd_x86_64")
148 ret
= checkOSandCPU(u
"NetBSD", u
"X86_64");
149 else if (token
== u
"openbsd_x86")
150 ret
= checkOSandCPU(u
"OpenBSD", u
"x86");
151 else if (token
== u
"openbsd_x86_64")
152 ret
= checkOSandCPU(u
"OpenBSD", u
"X86_64");
153 else if (token
== u
"dragonfly_x86")
154 ret
= checkOSandCPU(u
"DragonFly", u
"x86");
155 else if (token
== u
"dragonfly_x86_64")
156 ret
= checkOSandCPU(u
"DragonFly", u
"X86_64");
159 OSL_FAIL("Extension Manager: The extension supports an unknown platform. "
160 "Check the platform in the description.xml");
169 OUString
const & getPlatformString()
171 return StrPlatform();
174 bool platform_fits( std::u16string_view platform_string
)
179 const std::u16string_view
token(
180 o3tl::trim(o3tl::getToken(platform_string
, 0, ',', index
)) );
181 // check if this platform:
182 if (o3tl::equalsIgnoreAsciiCase( token
, StrPlatform() ) ||
183 (token
.find( '_' ) == std::u16string_view::npos
&& /* check OS part only */
184 o3tl::equalsIgnoreAsciiCase( token
, StrOperatingSystem() )))
194 bool hasValidPlatform( css::uno::Sequence
<OUString
> const & platformStrings
)
197 for (const OUString
& s
: platformStrings
)
199 if ( isPlatformSupported( s
) )
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */