diff mbox series

[kirkstone,15/16] goarch: Move Go architecture mapping to a library

Message ID 8726ae02d760270f9e7fe7ef5715d8f7553371ce.1700620126.git.steve@sakoman.com
State New, archived
Delegated to: Steve Sakoman
Headers show
Series [kirkstone,01/16] tiff: Backport fix for CVE-2023-41175 | expand

Commit Message

Steve Sakoman Nov. 22, 2023, 2:31 a.m. UTC
From: Peter Marko <peter.marko@siemens.com>

Other spaces uses the Go architecture definitions as their own (for
example, container arches are defined to be Go arches). To make it
easier for other places to use this mapping, move the code that does the
translation of OpenEmbedded arches to Go arches to a library.

(From oe-core rev: 3e86f72fc2e1cc2e5ea4b4499722d736941167ce)

This commit together with meta-virtualization commit
115f6367f37095415f289fb6981cda9608ac72ff
broke meta-virtualization master used with
meta-lts-mixins kirkstone/go which is our primary
usecase for having kirkstone/go mixin layer

Manually crafted since cherry-pick had too many conflicts:
* different path to classes
* additional architecture loongarch64
* different way how to import library

Signed-off-by: Peter Marko <peter.marko@siemens.com>
Cc: Joshua Watt <JPEWhacker@gmail.com>
Cc: Bruce Ashfield <bruce.ashfield@gmail.com>
Cc: Jose Quaresma <jose.quaresma@foundries.io>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
---
 meta/classes/base.bbclass   |  2 +-
 meta/classes/goarch.bbclass | 27 +++------------------------
 meta/lib/oe/go.py           | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 25 deletions(-)
 create mode 100644 meta/lib/oe/go.py

Comments

Richard Purdie Nov. 23, 2023, 12:40 p.m. UTC | #1
On Tue, 2023-11-21 at 16:31 -1000, Steve Sakoman wrote:
> From: Peter Marko <peter.marko@siemens.com>
> 
> Other spaces uses the Go architecture definitions as their own (for
> example, container arches are defined to be Go arches). To make it
> easier for other places to use this mapping, move the code that does the
> translation of OpenEmbedded arches to Go arches to a library.
> 
> (From oe-core rev: 3e86f72fc2e1cc2e5ea4b4499722d736941167ce)
> 
> This commit together with meta-virtualization commit
> 115f6367f37095415f289fb6981cda9608ac72ff
> broke meta-virtualization master used with
> meta-lts-mixins kirkstone/go which is our primary
> usecase for having kirkstone/go mixin layer
> 
> Manually crafted since cherry-pick had too many conflicts:
> * different path to classes
> * additional architecture loongarch64
> * different way how to import library
> 
> Signed-off-by: Peter Marko <peter.marko@siemens.com>
> Cc: Joshua Watt <JPEWhacker@gmail.com>
> Cc: Bruce Ashfield <bruce.ashfield@gmail.com>
> Cc: Jose Quaresma <jose.quaresma@foundries.io>
> Signed-off-by: Steve Sakoman <steve@sakoman.com>
> ---
>  meta/classes/base.bbclass   |  2 +-
>  meta/classes/goarch.bbclass | 27 +++------------------------
>  meta/lib/oe/go.py           | 32 ++++++++++++++++++++++++++++++++
>  3 files changed, 36 insertions(+), 25 deletions(-)
>  create mode 100644 meta/lib/oe/go.py

This did cause problems for some layers such as meta-virtualization so
I'd want to check those layers are ok with this?

Cheers,

Richard
Bruce Ashfield Nov. 23, 2023, 1:45 p.m. UTC | #2
On Thu, Nov 23, 2023 at 7:40 AM Richard Purdie
<richard.purdie@linuxfoundation.org> wrote:
>
> On Tue, 2023-11-21 at 16:31 -1000, Steve Sakoman wrote:
> > From: Peter Marko <peter.marko@siemens.com>
> >
> > Other spaces uses the Go architecture definitions as their own (for
> > example, container arches are defined to be Go arches). To make it
> > easier for other places to use this mapping, move the code that does the
> > translation of OpenEmbedded arches to Go arches to a library.
> >
> > (From oe-core rev: 3e86f72fc2e1cc2e5ea4b4499722d736941167ce)
> >
> > This commit together with meta-virtualization commit
> > 115f6367f37095415f289fb6981cda9608ac72ff
> > broke meta-virtualization master used with
> > meta-lts-mixins kirkstone/go which is our primary
> > usecase for having kirkstone/go mixin layer
> >
> > Manually crafted since cherry-pick had too many conflicts:
> > * different path to classes
> > * additional architecture loongarch64
> > * different way how to import library
> >
> > Signed-off-by: Peter Marko <peter.marko@siemens.com>
> > Cc: Joshua Watt <JPEWhacker@gmail.com>
> > Cc: Bruce Ashfield <bruce.ashfield@gmail.com>
> > Cc: Jose Quaresma <jose.quaresma@foundries.io>
> > Signed-off-by: Steve Sakoman <steve@sakoman.com>
> > ---
> >  meta/classes/base.bbclass   |  2 +-
> >  meta/classes/goarch.bbclass | 27 +++------------------------
> >  meta/lib/oe/go.py           | 32 ++++++++++++++++++++++++++++++++
> >  3 files changed, 36 insertions(+), 25 deletions(-)
> >  create mode 100644 meta/lib/oe/go.py
>
> This did cause problems for some layers such as meta-virtualization so
> I'd want to check those layers are ok with this?
>

It should be fine, the issues were around it not being present and recipes
trying to use the mapping directly without the go.bbclass being inherited.

It won't be used in kirkstone, so is a no-op there (for meta-virt), but that
does mean some mixin and multi release compatible layers can more
easily to backports.

Bruce


> Cheers,
>
> Richard
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#191144): https://lists.openembedded.org/g/openembedded-core/message/191144
> Mute This Topic: https://lists.openembedded.org/mt/102742416/1050810
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [bruce.ashfield@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Steve Sakoman Nov. 23, 2023, 2:53 p.m. UTC | #3
On Thu, Nov 23, 2023 at 3:45 AM Bruce Ashfield <bruce.ashfield@gmail.com> wrote:
>
> On Thu, Nov 23, 2023 at 7:40 AM Richard Purdie
> <richard.purdie@linuxfoundation.org> wrote:
> >
> > On Tue, 2023-11-21 at 16:31 -1000, Steve Sakoman wrote:
> > > From: Peter Marko <peter.marko@siemens.com>
> > >
> > > Other spaces uses the Go architecture definitions as their own (for
> > > example, container arches are defined to be Go arches). To make it
> > > easier for other places to use this mapping, move the code that does the
> > > translation of OpenEmbedded arches to Go arches to a library.
> > >
> > > (From oe-core rev: 3e86f72fc2e1cc2e5ea4b4499722d736941167ce)
> > >
> > > This commit together with meta-virtualization commit
> > > 115f6367f37095415f289fb6981cda9608ac72ff
> > > broke meta-virtualization master used with
> > > meta-lts-mixins kirkstone/go which is our primary
> > > usecase for having kirkstone/go mixin layer
> > >
> > > Manually crafted since cherry-pick had too many conflicts:
> > > * different path to classes
> > > * additional architecture loongarch64
> > > * different way how to import library
> > >
> > > Signed-off-by: Peter Marko <peter.marko@siemens.com>
> > > Cc: Joshua Watt <JPEWhacker@gmail.com>
> > > Cc: Bruce Ashfield <bruce.ashfield@gmail.com>
> > > Cc: Jose Quaresma <jose.quaresma@foundries.io>
> > > Signed-off-by: Steve Sakoman <steve@sakoman.com>
> > > ---
> > >  meta/classes/base.bbclass   |  2 +-
> > >  meta/classes/goarch.bbclass | 27 +++------------------------
> > >  meta/lib/oe/go.py           | 32 ++++++++++++++++++++++++++++++++
> > >  3 files changed, 36 insertions(+), 25 deletions(-)
> > >  create mode 100644 meta/lib/oe/go.py
> >
> > This did cause problems for some layers such as meta-virtualization so
> > I'd want to check those layers are ok with this?
> >
>
> It should be fine, the issues were around it not being present and recipes
> trying to use the mapping directly without the go.bbclass being inherited.
>
> It won't be used in kirkstone, so is a no-op there (for meta-virt), but that
> does mean some mixin and multi release compatible layers can more
> easily to backports.

Thanks for reviewing Richard and Bruce!

Since Bruce confirms there are no issues with meta-virt I'll leave
this in the series.

Steve
diff mbox series

Patch

diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass
index b15c5839b6..ee26ee5597 100644
--- a/meta/classes/base.bbclass
+++ b/meta/classes/base.bbclass
@@ -12,7 +12,7 @@  inherit logging
 
 OE_EXTRA_IMPORTS ?= ""
 
-OE_IMPORTS += "os sys time oe.path oe.utils oe.types oe.package oe.packagegroup oe.sstatesig oe.lsb oe.cachedpath oe.license oe.qa oe.reproducible oe.rust ${OE_EXTRA_IMPORTS}"
+OE_IMPORTS += "os sys time oe.path oe.utils oe.types oe.package oe.packagegroup oe.sstatesig oe.lsb oe.cachedpath oe.license oe.qa oe.reproducible oe.rust oe.go ${OE_EXTRA_IMPORTS}"
 OE_IMPORTS[type] = "list"
 
 PACKAGECONFIG_CONFARGS ??= ""
diff --git a/meta/classes/goarch.bbclass b/meta/classes/goarch.bbclass
index 92fec16b82..394c0c5d84 100644
--- a/meta/classes/goarch.bbclass
+++ b/meta/classes/goarch.bbclass
@@ -61,31 +61,10 @@  SECURITY_NOPIE_CFLAGS ??= ""
 CCACHE_DISABLE ?= "1"
 
 def go_map_arch(a, d):
-    import re
-    if re.match('i.86', a):
-        return '386'
-    elif a == 'x86_64':
-        return 'amd64'
-    elif re.match('arm.*', a):
-        return 'arm'
-    elif re.match('aarch64.*', a):
-        return 'arm64'
-    elif re.match('mips64el.*', a):
-        return 'mips64le'
-    elif re.match('mips64.*', a):
-        return 'mips64'
-    elif a == 'mips':
-        return 'mips'
-    elif a == 'mipsel':
-        return 'mipsle'
-    elif re.match('p(pc|owerpc)(64le)', a):
-        return 'ppc64le'
-    elif re.match('p(pc|owerpc)(64)', a):
-        return 'ppc64'
-    elif a == 'riscv64':
-        return 'riscv64'
-    else:
+    arch = oe.go.map_arch(a)
+    if not arch:
         raise bb.parse.SkipRecipe("Unsupported CPU architecture: %s" % a)
+    return arch
 
 def go_map_arm(a, d):
     if a.startswith("arm"):
diff --git a/meta/lib/oe/go.py b/meta/lib/oe/go.py
new file mode 100644
index 0000000000..9996057f12
--- /dev/null
+++ b/meta/lib/oe/go.py
@@ -0,0 +1,32 @@ 
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+import re
+
+def map_arch(a):
+    if re.match('i.86', a):
+        return '386'
+    elif a == 'x86_64':
+        return 'amd64'
+    elif re.match('arm.*', a):
+        return 'arm'
+    elif re.match('aarch64.*', a):
+        return 'arm64'
+    elif re.match('mips64el.*', a):
+        return 'mips64le'
+    elif re.match('mips64.*', a):
+        return 'mips64'
+    elif a == 'mips':
+        return 'mips'
+    elif a == 'mipsel':
+        return 'mipsle'
+    elif re.match('p(pc|owerpc)(64le)', a):
+        return 'ppc64le'
+    elif re.match('p(pc|owerpc)(64)', a):
+        return 'ppc64'
+    elif a == 'riscv64':
+        return 'riscv64'
+    return ''