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/bootstrap.hxx>
24 #include <osl/diagnose.h>
25 #include <o3tl/string_view.hxx>
27 constexpr OUStringLiteral PLATFORM_ALL
= u
"all";
34 OUString
StrOperatingSystemInit()
36 OUString
os( u
"$_OS"_ustr
);
37 ::rtl::Bootstrap::expandMacros( os
);
41 const OUString
& StrOperatingSystem()
43 static const OUString theOS
= StrOperatingSystemInit();
49 OUString
arch( u
"$_ARCH"_ustr
);
50 ::rtl::Bootstrap::expandMacros( arch
);
54 const OUString
& StrCPU()
56 static const OUString theCPU
= StrCPUInit();
61 const OUString
& StrPlatform()
63 static const OUString thePlatform
= StrOperatingSystem() + "_" + StrCPU();
67 bool checkOSandCPU(std::u16string_view os
, std::u16string_view cpu
)
69 return (os
== StrOperatingSystem())
73 bool isPlatformSupported( std::u16string_view token
)
76 if (token
== PLATFORM_ALL
)
78 else if (token
== u
"windows_x86")
79 ret
= checkOSandCPU(u
"Windows", u
"x86");
80 else if (token
== u
"windows_x86_64")
81 ret
= checkOSandCPU(u
"Windows", u
"X86_64");
82 else if (token
== u
"windows_aarch64")
83 ret
= checkOSandCPU(u
"Windows", u
"AARCH64");
84 else if (token
== u
"solaris_sparc")
85 ret
= checkOSandCPU(u
"Solaris", u
"SPARC");
86 else if (token
== u
"solaris_sparc64")
87 ret
= checkOSandCPU(u
"Solaris", u
"SPARC64");
88 else if (token
== u
"solaris_x86")
89 ret
= checkOSandCPU(u
"Solaris", u
"x86");
90 else if (token
== u
"macosx_aarch64")
91 ret
= checkOSandCPU(u
"MacOSX", u
"AARCH64");
92 else if (token
== u
"macosx_x86_64")
93 ret
= checkOSandCPU(u
"MacOSX", u
"X86_64");
94 else if (token
== u
"linux_x86")
95 ret
= checkOSandCPU(u
"Linux", u
"x86");
96 else if (token
== u
"linux_x86_64")
97 ret
= checkOSandCPU(u
"Linux", u
"X86_64");
98 else if (token
== u
"linux_sparc")
99 ret
= checkOSandCPU(u
"Linux", u
"SPARC");
100 else if (token
== u
"linux_sparc64")
101 ret
= checkOSandCPU(u
"Linux", u
"SPARC64");
102 else if (token
== u
"linux_powerpc")
103 ret
= checkOSandCPU(u
"Linux", u
"PowerPC");
104 else if (token
== u
"linux_powerpc64")
105 ret
= checkOSandCPU(u
"Linux", u
"PowerPC_64");
106 else if (token
== u
"linux_powerpc64_le")
107 ret
= checkOSandCPU(u
"Linux", u
"PowerPC_64_LE");
108 else if (token
== u
"linux_arm_eabi")
109 ret
= checkOSandCPU(u
"Linux", u
"ARM_EABI");
110 else if (token
== u
"linux_arm_oabi")
111 ret
= checkOSandCPU(u
"Linux", u
"ARM_OABI");
112 else if (token
== u
"linux_mips_el")
113 ret
= checkOSandCPU(u
"Linux", u
"MIPS_EL");
114 else if (token
== u
"linux_mips64_el")
115 ret
= checkOSandCPU(u
"Linux", u
"MIPS64_EL");
116 else if (token
== u
"linux_mips_eb")
117 ret
= checkOSandCPU(u
"Linux", u
"MIPS_EB");
118 else if (token
== u
"linux_mips64_eb")
119 ret
= checkOSandCPU(u
"Linux", u
"MIPS64_EB");
120 else if (token
== u
"linux_ia64")
121 ret
= checkOSandCPU(u
"Linux", u
"IA64");
122 else if (token
== u
"linux_m68k")
123 ret
= checkOSandCPU(u
"Linux", u
"M68K");
124 else if (token
== u
"linux_s390x")
125 ret
= checkOSandCPU(u
"Linux", u
"S390x");
126 else if (token
== u
"linux_hppa")
127 ret
= checkOSandCPU(u
"Linux", u
"HPPA");
128 else if (token
== u
"linux_alpha")
129 ret
= checkOSandCPU(u
"Linux", u
"ALPHA");
130 else if (token
== u
"linux_aarch64")
131 ret
= checkOSandCPU(u
"Linux", u
"AARCH64");
132 else if (token
== u
"linux_riscv64")
133 ret
= checkOSandCPU(u
"Linux", u
"RISCV64");
134 else if (token
== u
"linux_loongarch64")
135 ret
= checkOSandCPU(u
"Linux", u
"LOONGARCH64");
136 else if (token
== u
"freebsd_x86")
137 ret
= checkOSandCPU(u
"FreeBSD", u
"x86");
138 else if (token
== u
"freebsd_x86_64")
139 ret
= checkOSandCPU(u
"FreeBSD", u
"X86_64");
140 else if (token
== u
"freebsd_powerpc")
141 ret
= checkOSandCPU(u
"FreeBSD", u
"PowerPC");
142 else if (token
== u
"freebsd_powerpc64")
143 ret
= checkOSandCPU(u
"FreeBSD", u
"PowerPC64");
144 else if (token
== u
"kfreebsd_x86")
145 ret
= checkOSandCPU(u
"kFreeBSD", u
"x86");
146 else if (token
== u
"kfreebsd_x86_64")
147 ret
= checkOSandCPU(u
"kFreeBSD", u
"X86_64");
148 else if (token
== u
"netbsd_x86")
149 ret
= checkOSandCPU(u
"NetBSD", u
"x86");
150 else if (token
== u
"netbsd_x86_64")
151 ret
= checkOSandCPU(u
"NetBSD", u
"X86_64");
152 else if (token
== u
"openbsd_x86")
153 ret
= checkOSandCPU(u
"OpenBSD", u
"x86");
154 else if (token
== u
"openbsd_x86_64")
155 ret
= checkOSandCPU(u
"OpenBSD", u
"X86_64");
156 else if (token
== u
"dragonfly_x86")
157 ret
= checkOSandCPU(u
"DragonFly", u
"x86");
158 else if (token
== u
"dragonfly_x86_64")
159 ret
= checkOSandCPU(u
"DragonFly", u
"X86_64");
162 OSL_FAIL("Extension Manager: The extension supports an unknown platform. "
163 "Check the platform in the description.xml");
172 OUString
const & getPlatformString()
174 return StrPlatform();
177 bool platform_fits( std::u16string_view platform_string
)
182 const std::u16string_view
token(
183 o3tl::trim(o3tl::getToken(platform_string
, 0, ',', index
)) );
184 // check if this platform:
185 if (o3tl::equalsIgnoreAsciiCase( token
, StrPlatform() ) ||
186 (token
.find( '_' ) == std::u16string_view::npos
&& /* check OS part only */
187 o3tl::equalsIgnoreAsciiCase( token
, StrOperatingSystem() )))
197 bool hasValidPlatform( css::uno::Sequence
<OUString
> const & platformStrings
)
200 for (const OUString
& s
: platformStrings
)
202 if ( isPlatformSupported( s
) )
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */