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/ustrbuf.hxx>
24 #include <rtl/instance.hxx>
25 #include <rtl/bootstrap.hxx>
26 #include <osl/diagnose.h>
27 
28 constexpr OUStringLiteral PLATFORM_ALL = u"all";
29 
30 
31 namespace dp_misc
32 {
33 namespace
34 {
35  struct StrOperatingSystem :
36  public rtl::StaticWithInit<OUString, StrOperatingSystem> {
37  OUString operator () () {
38  OUString os( "$_OS" );
39  ::rtl::Bootstrap::expandMacros( os );
40  return os;
41  }
42  };
43 
44  struct StrCPU :
45  public rtl::StaticWithInit<OUString, StrCPU> {
46  OUString operator () () {
47  OUString arch( "$_ARCH" );
48  ::rtl::Bootstrap::expandMacros( arch );
49  return arch;
50  }
51  };
52 
53 
54  struct StrPlatform : public rtl::StaticWithInit<
55  OUString, StrPlatform> {
56  OUString operator () () {
57  OUStringBuffer buf;
58  buf.append( StrOperatingSystem::get() );
59  buf.append( '_' );
60  buf.append( StrCPU::get() );
61  return buf.makeStringAndClear();
62  }
63  };
64 
65  bool checkOSandCPU(std::u16string_view os, std::u16string_view cpu)
66  {
67  return (os == StrOperatingSystem::get())
68  && (cpu == StrCPU::get());
69  }
70 
71  bool isPlatformSupported( std::u16string_view token )
72  {
73  bool ret = false;
74  if (token == PLATFORM_ALL)
75  ret = true;
76  else if (token == u"windows_x86")
77  ret = checkOSandCPU(u"Windows", u"x86");
78  else if (token == u"windows_x86_64")
79  ret = checkOSandCPU(u"Windows", u"X86_64");
80  else if (token == u"windows_aarch64")
81  ret = checkOSandCPU(u"Windows", u"AARCH64");
82  else if (token == u"solaris_sparc")
83  ret = checkOSandCPU(u"Solaris", u"SPARC");
84  else if (token == u"solaris_sparc64")
85  ret = checkOSandCPU(u"Solaris", u"SPARC64");
86  else if (token == u"solaris_x86")
87  ret = checkOSandCPU(u"Solaris", u"x86");
88  else if (token == u"aix_powerpc")
89  ret = checkOSandCPU(u"AIX", u"PowerPC");
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_s390")
125  ret = checkOSandCPU(u"Linux", u"S390");
126  else if (token == u"linux_s390x")
127  ret = checkOSandCPU(u"Linux", u"S390x");
128  else if (token == u"linux_hppa")
129  ret = checkOSandCPU(u"Linux", u"HPPA");
130  else if (token == u"linux_alpha")
131  ret = checkOSandCPU(u"Linux", u"ALPHA");
132  else if (token == u"linux_aarch64")
133  ret = checkOSandCPU(u"Linux", u"AARCH64");
134  else if (token == u"freebsd_x86")
135  ret = checkOSandCPU(u"FreeBSD", u"x86");
136  else if (token == u"freebsd_x86_64")
137  ret = checkOSandCPU(u"FreeBSD", u"X86_64");
138  else if (token == u"freebsd_powerpc")
139  ret = checkOSandCPU(u"FreeBSD", u"PowerPC");
140  else if (token == u"freebsd_powerpc64")
141  ret = checkOSandCPU(u"FreeBSD", u"PowerPC64");
142  else if (token == u"kfreebsd_x86")
143  ret = checkOSandCPU(u"kFreeBSD", u"x86");
144  else if (token == u"kfreebsd_x86_64")
145  ret = checkOSandCPU(u"kFreeBSD", u"X86_64");
146  else if (token == u"netbsd_x86")
147  ret = checkOSandCPU(u"NetBSD", u"x86");
148  else if (token == u"netbsd_x86_64")
149  ret = checkOSandCPU(u"NetBSD", u"X86_64");
150  else if (token == u"openbsd_x86")
151  ret = checkOSandCPU(u"OpenBSD", u"x86");
152  else if (token == u"openbsd_x86_64")
153  ret = checkOSandCPU(u"OpenBSD", u"X86_64");
154  else if (token == u"dragonfly_x86")
155  ret = checkOSandCPU(u"DragonFly", u"x86");
156  else if (token == u"dragonfly_x86_64")
157  ret = checkOSandCPU(u"DragonFly", u"X86_64");
158  else
159  {
160  OSL_FAIL("Extension Manager: The extension supports an unknown platform. "
161  "Check the platform in the description.xml");
162  ret = false;
163  }
164  return ret;
165  }
166 
167 } // anon namespace
168 
169 
170 OUString const & getPlatformString()
171 {
172  return StrPlatform::get();
173 }
174 
175 bool platform_fits( OUString const & platform_string )
176 {
177  sal_Int32 index = 0;
178  for (;;)
179  {
180  const OUString token(
181  platform_string.getToken( 0, ',', index ).trim() );
182  // check if this platform:
183  if (token.equalsIgnoreAsciiCase( StrPlatform::get() ) ||
184  (token.indexOf( '_' ) < 0 && /* check OS part only */
185  token.equalsIgnoreAsciiCase( StrOperatingSystem::get() )))
186  {
187  return true;
188  }
189  if (index < 0)
190  break;
191  }
192  return false;
193 }
194 
195 bool hasValidPlatform( css::uno::Sequence<OUString> const & platformStrings)
196 {
197  bool ret = false;
198  for (const OUString& s : platformStrings)
199  {
200  if ( isPlatformSupported( s ) )
201  {
202  ret = true;
203  break;
204  }
205  }
206  return ret;
207 }
208 
209 }
210 
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC OUString const & getPlatformString()
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool platform_fits(OUString const &platform_string)
constexpr OUStringLiteral PLATFORM_ALL
Definition: dp_platform.cxx:28
float u
tuple index
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool hasValidPlatform(css::uno::Sequence< OUString > const &platformStrings)
determines if the current platform corresponds to one of the platform strings.