LibreOffice Module desktop (master) 1
dp_platform.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
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>
27
28constexpr OUStringLiteral PLATFORM_ALL = u"all";
29
30
31namespace dp_misc
32{
33namespace
34{
35 const OUString & StrOperatingSystem()
36 {
37 static const OUString theOS = []()
38 {
39 OUString os( "$_OS" );
40 ::rtl::Bootstrap::expandMacros( os );
41 return os;
42 }();
43 return theOS;
44 };
45
46 const OUString & StrCPU()
47 {
48 static const OUString theCPU = []()
49 {
50 OUString arch( "$_ARCH" );
51 ::rtl::Bootstrap::expandMacros( arch );
52 return arch;
53 }();
54 return theCPU;
55 };
56
57
58 const OUString & StrPlatform()
59 {
60 static const OUString thePlatform = StrOperatingSystem() + "_" + StrCPU();
61 return thePlatform;
62 };
63
64 bool checkOSandCPU(std::u16string_view os, std::u16string_view cpu)
65 {
66 return (os == StrOperatingSystem())
67 && (cpu == StrCPU());
68 }
69
70 bool isPlatformSupported( std::u16string_view token )
71 {
72 bool ret = false;
73 if (token == PLATFORM_ALL)
74 ret = true;
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");
157 else
158 {
159 OSL_FAIL("Extension Manager: The extension supports an unknown platform. "
160 "Check the platform in the description.xml");
161 ret = false;
162 }
163 return ret;
164 }
165
166} // anon namespace
167
168
169OUString const & getPlatformString()
170{
171 return StrPlatform();
172}
173
174bool platform_fits( std::u16string_view platform_string )
175{
176 sal_Int32 index = 0;
177 for (;;)
178 {
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() )))
185 {
186 return true;
187 }
188 if (index < 0)
189 break;
190 }
191 return false;
192}
193
194bool hasValidPlatform( css::uno::Sequence<OUString> const & platformStrings)
195{
196 bool ret = false;
197 for (const OUString& s : platformStrings)
198 {
199 if ( isPlatformSupported( s ) )
200 {
201 ret = true;
202 break;
203 }
204 }
205 return ret;
206}
207
208}
209
210/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral PLATFORM_ALL
Definition: dp_platform.cxx:28
float u
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool platform_fits(std::u16string_view platform_string)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool hasValidPlatform(css::uno::Sequence< OUString > const &platformStrings)
determines if the current platform corresponds to one of the platform strings.
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC OUString const & getPlatformString()
index
std::basic_string_view< charT, traits > trim(std::basic_string_view< charT, traits > str)
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)