Skip to content

Commit

Permalink
templates namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
msdobrescu committed Oct 12, 2023
1 parent 59a8c09 commit c19fd47
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion packages/apps/build.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{ template "build" . }}
{{ template "community.build" . }}
2 changes: 1 addition & 1 deletion packages/layers/build.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{ template "build" . }}
{{ template "community.build" . }}
24 changes: 12 additions & 12 deletions packages/templates/build.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ define "build" }}
{{ define "community.build" }}

env:
{{ if .Values.labels }}
Expand All @@ -24,22 +24,22 @@ unpack: {{ .Values.unpack }}
{{ end }}

prelude:
{{ $packages_list := include "cr.list_packages_with_deps" .Values }}
{{ $packages_list := include "community.list_packages_with_deps" .Values }}
- echo "Packages:" {{ $packages_list }}
{{ $packages := include "cr.map_packages_with_deps" .Values | fromJson }}
{{ $packages := include "community.map_packages_with_deps" .Values | fromJson }}

{{/* debug */}}
{{/* depends on which comes first out of the below debug functions, only the first one will be executed */}}
{{/* if eq .Values.name "kaffeine-tde" }}
{{ template "cr.dump" ( include "cr.merge_shell_commands" ( include "cr.prereqs" ( list .Values $packages "" ) ) ) }}
{{ template "cr.dumpList" ( include "cr.prereqs" ( list .Values $packages "" ) ) }}
{{ include "cr.dumpJson" ( get ( ( printf "debug:\n %s" ( include "cr.prereqs" ( list .Values $packages "" ) ) ) | fromYaml ) "debug" ) }}
{{ template "community.dump" ( include "community.merge_shell_commands" ( include "community.prereqs" ( list .Values $packages "" ) ) ) }}
{{ template "community.dumpList" ( include "community.prereqs" ( list .Values $packages "" ) ) }}
{{ include "community.dumpJson" ( get ( ( printf "debug:\n %s" ( include "community.prereqs" ( list .Values $packages "" ) ) ) | fromYaml ) "debug" ) }}
{{ end */}}
{{/* end debug */}}

{{ $prereqs := include "cr.prereqs" ( list .Values $packages "" ) }}
{{ $prereqs := include "community.prereqs" ( list .Values $packages "" ) }}
- |
{{ ( include "cr.merge_shell_commands" $prereqs ) | indent 2 }}
{{ ( include "community.merge_shell_commands" $prereqs ) | indent 2 }}

{{ if eq .Values.category "layerbase" }}
- |
Expand All @@ -52,17 +52,17 @@ prelude:
{{/* debug */}}
{{/* depends on which comes first out of the below debug functions, only the first one will be executed */}}
{{/* if eq .Values.name "blender" }}
{{ template "cr.dumpList" ( include "cr.package_setup" .Values ) }}
{{ include "cr.dumpJson" ( get ( ( printf "debug:\n %s" ( include "cr.package_setup" .Values ) ) | fromYaml ) "debug" ) }}
{{ template "community.dumpList" ( include "community.package_setup" .Values ) }}
{{ include "community.dumpJson" ( get ( ( printf "debug:\n %s" ( include "community.package_setup" .Values ) ) | fromYaml ) "debug" ) }}
{{ end */}}
{{/* end debug */}}

{{ include "cr.package_setup" .Values }}
{{ include "community.package_setup" .Values }}

{{ end }}

steps:
{{- include "cr.emerge_atom" ( list .Values $packages "" true ) }}
{{- include "community.emerge_atom" ( list .Values $packages "" true ) }}

# {{ if eq .Values.category "layerbase" }}
# includes:
Expand Down
78 changes: 39 additions & 39 deletions packages/templates/functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## cr.list_packages_with_deps ###
################################################################################

{{- define "cr.list_packages_with_deps" }}
{{- define "community.list_packages_with_deps" }}

{{- if not ( default .skip false ) }}

Expand All @@ -15,7 +15,7 @@
{{- if ( index $dep . ) }}
{{- range ( index $dep . ) }}

{{- range ( include "cr.list_packages_with_deps" . ) | splitList " " }}
{{- range ( include "community.list_packages_with_deps" . ) | splitList " " }}
{{- if not ( has . $packages ) }}
{{- $packages = . | append $packages }}
{{- end }}
Expand Down Expand Up @@ -57,7 +57,7 @@
## cr.map_packages_with_deps ###
################################################################################

{{- define "cr.map_packages_with_deps" }}
{{- define "community.map_packages_with_deps" }}

{{- $packages := dict }}

Expand All @@ -72,7 +72,7 @@

{{- $required := printf "%s-%s" .category .name }}

{{- range $k, $v := ( ( include "cr.map_packages_with_deps" . ) | fromJson ) }}
{{- range $k, $v := ( ( include "community.map_packages_with_deps" . ) | fromJson ) }}
{{- $_ := set $packages $k $v }}
{{- end }}

Expand Down Expand Up @@ -108,7 +108,7 @@
## cr.copy_package_setup_files ###
################################################################################

{{- define "cr.copy_package_setup_files" }}
{{- define "community.copy_package_setup_files" }}
{{- $package := . }}
- |
set -x; \
Expand All @@ -134,9 +134,9 @@
## cr.package_setup ###
################################################################################

{{- define "cr.package_setup" }}
{{- define "community.package_setup" }}

{{- include "cr.copy_package_setup_files" ( printf "%s-%s" ( .category | replace "layerbase" "layers" | replace "buildbase" "layers" ) .name ) }}
{{- include "community.copy_package_setup_files" ( printf "%s-%s" ( .category | replace "layerbase" "layers" | replace "buildbase" "layers" ) .name ) }}

{{- $filepath := "/etc/portage/package" }}
{{- $filename := printf "%s-%s" .category .name }}
Expand Down Expand Up @@ -215,7 +215,7 @@
## cr.prereqs ###
################################################################################

{{- define "cr.prereqs" }}
{{- define "community.prereqs" }}

{{- $packages := index . 1 }}
{{- $previous_package := index . 2 }}
Expand All @@ -230,9 +230,9 @@

{{/*- debug */}}
{{/*- if $enqueue }}
- set -x; echo "cr.prereqs ({{ $current_package }} required by {{ $previous_package | default "itself" }})"
- set -x; echo "community.prereqs ({{ $current_package }} required by {{ $previous_package | default "itself" }})"
{{- else }}
- set -x; echo "cr.prereqs ({{ $current_package }} required by {{ $previous_package | default "itself" }}, skipping, should be required by {{ get $packages $current_package }})"
- set -x; echo "community.prereqs ({{ $current_package }} required by {{ $previous_package | default "itself" }}, skipping, should be required by {{ get $packages $current_package }})"
{{- end */}}
{{/*- end debug */}}

Expand All @@ -243,7 +243,7 @@
{{- if .requires }}
{{- range .requires }}

{{- include "cr.prereqs_emerge" ( list . $packages $current_package ) }}
{{- include "community.prereqs_emerge" ( list . $packages $current_package ) }}

{{- end }}
{{- end }}
Expand All @@ -252,7 +252,7 @@
{{- if ( index $package . ) }}
{{- range ( index $package . ) }}

{{- include "cr.prereqs_emerge" ( list . $packages $current_package ) }}
{{- include "community.prereqs_emerge" ( list . $packages $current_package ) }}

{{- end }}
{{- end }}
Expand All @@ -276,23 +276,23 @@
{{- if .prepare }}
{{- range .prepare }}
{{- if . }}
{{- include "cr.get_single_or_multi_line_item" . }}
{{- include "community.get_single_or_multi_line_item" . }}
{{- end }}
{{- end }}
{{- end }}

{{- if .prereqs }}
{{- range .prereqs }}
{{- if . }}
{{ include "cr.emerge" . }}
{{ include "community.emerge" . }}
{{- end }}
{{- end }}
{{- end }}

{{- if .ready }}
{{- range .ready }}
{{- if . }}
{{- include "cr.get_single_or_multi_line_item" . }}
{{- include "community.get_single_or_multi_line_item" . }}
{{- end }}
{{- end }}
{{- end }}
Expand All @@ -309,7 +309,7 @@
## cr.prereqs_emerge ###
################################################################################

{{- define "cr.prereqs_emerge" }}
{{- define "community.prereqs_emerge" }}

{{- $packages := index . 1 }}
{{- $previous_package := index . 2 }}
Expand All @@ -324,17 +324,17 @@

{{/*- debug */}}
{{/*- if $enqueue }}
- set -x; echo "cr.prereqs_emerge ({{ $current_package }} required by {{ $previous_package | default "itself" }})"
- set -x; echo "community.prereqs_emerge ({{ $current_package }} required by {{ $previous_package | default "itself" }})"
{{- else }}
- set -x; echo "cr.prereqs_emerge ({{ $current_package }} required by {{ $previous_package | default "itself" }}, skipping, should be required by {{ get $packages $current_package }})"
- set -x; echo "community.prereqs_emerge ({{ $current_package }} required by {{ $previous_package | default "itself" }}, skipping, should be required by {{ get $packages $current_package }})"
{{- end */}}
{{/*- end debug */}}

{{- if $enqueue }}

{{- include "cr.prereqs" ( list . $packages $previous_package ) }}
{{- include "community.prereqs" ( list . $packages $previous_package ) }}

{{- include "cr.emerge_atom" ( list . $packages $previous_package ) }}
{{- include "community.emerge_atom" ( list . $packages $previous_package ) }}

{{- end }}

Expand All @@ -348,7 +348,7 @@
## cr.emerge_atom ###
################################################################################

{{- define "cr.emerge_atom" }}
{{- define "community.emerge_atom" }}

{{- $packages := index . 1 }}
{{- $previous_package := index . 2 }}
Expand All @@ -367,25 +367,25 @@
{{- if .setup }}
{{- range .setup }}
{{- if . }}
{{- include "cr.get_single_or_multi_line_item" . }}
{{- include "community.get_single_or_multi_line_item" . }}
{{- end }}
{{- end }}
{{- end }}

{{- if .preemerge }}
{{- range .preemerge }}
{{- include "cr.emerge" . }}
{{- include "community.emerge" . }}
{{- end }}
{{- end }}

{{- if .labels }}
{{- if ( index .labels "emerge.packages" ) }}

{{- if or ( not $layerbase_package_setup_only ) ( and ( $layerbase_package_setup_only ) ( eq .category "layerbase" ) ) }}
{{- include "cr.package_setup" . }}
{{- include "community.package_setup" . }}
{{- end }}

{{- include "cr.emerge" ( index .labels "emerge.packages" ) }}
{{- include "community.emerge" ( index .labels "emerge.packages" ) }}

{{- end }}
{{- end }}
Expand All @@ -404,7 +404,7 @@
{{- if .completion }}
{{- range .completion }}
{{- if . }}
{{- include "cr.get_single_or_multi_line_item" . }}
{{- include "community.get_single_or_multi_line_item" . }}
{{- end }}
{{- end }}
{{- end }}
Expand All @@ -419,7 +419,7 @@
## cr.emerge ###
################################################################################

{{- define "cr.emerge" }}
{{- define "community.emerge" }}

{{- $tokens := . | splitList ";" }}
{{- if eq ( len $tokens ) 1 }}
Expand All @@ -435,7 +435,7 @@
## cr.get_single_or_multi_line_item ###
################################################################################

{{- define "cr.get_single_or_multi_line_item" }}
{{- define "community.get_single_or_multi_line_item" }}

{{- if contains "\n" . }}
- |
Expand All @@ -450,7 +450,7 @@
## cr.merge_shell_commands ###
################################################################################

{{- define "cr.merge_shell_commands" }}
{{- define "community.merge_shell_commands" }}

{{- $command := "" }}
{{- range ( get ( ( printf "list:\n %s" . ) | fromYaml ) "list" ) }}
Expand All @@ -466,29 +466,29 @@
## flatten ###
################################################################################

{{- define "cr.flatten_list" -}}
{{- define "community.flatten_list" -}}
{{- $output := list -}}
{{- range . -}}
{{- if ( kindIs "slice" . ) -}}
{{- $output = ( concat $output ( get (fromYaml ( include "cr.flatten_list" . ) ) "list" ) ) -}}
{{- $output = ( concat $output ( get (fromYaml ( include "community.flatten_list" . ) ) "list" ) ) -}}
{{- else -}}
{{- $output = ( append $output . ) -}}
{{- end -}}
{{- end -}}
{{- toYaml ( dict "list" $output ) -}}
{{- end -}}

{{- define "cr.flatten" -}}
{{- get ( fromYaml ( include "cr.flatten_list" . ) ) "list" | toYaml }}
{{- define "community.flatten" -}}
{{- get ( fromYaml ( include "community.flatten_list" . ) ) "list" | toYaml }}
{{- end -}}

{{- define "cr.flatten_map" -}}
{{- define "community.flatten_map" -}}
{{- $map := first . -}}
{{- $label := last . -}}
{{- range $key, $val := $map -}}
{{- $sublabel := list $label $key | join "_" | upper -}}
{{- if kindOf $val | eq "map" -}}
{{- list $val $sublabel | include "cr.flatten_map" -}}
{{- list $val $sublabel | include "community.flatten_map" -}}
{{- else -}}
- name: {{ $sublabel | quote }}
value: {{ $val | quote }}
Expand All @@ -500,21 +500,21 @@
## debug ###
################################################################################

{{- define "cr.dump" }}
{{- define "community.dump" }}
{{- . | printf "\nThe output of the dumped var is: \n%s" | fail }}
{{- end }}

{{- define "cr.dumpJson" }}
{{- define "community.dumpJson" }}
{{- . | toPrettyJson | printf "\nThe JSON output of the dumped var is: \n%s" | fail }}
{{- end }}

{{- define "cr.dumpList" }}
{{- define "community.dumpList" }}

{{- $debug := "" }}
{{- range ( get ( ( printf "list:\n %s" . ) | fromYaml ) "list" ) }}
{{- $debug = printf "%s\n%s" $debug . }}
{{- end }}
{{- template "cr.dump" $debug }}
{{- template "community.dump" $debug }}

{{- end }}

0 comments on commit c19fd47

Please sign in to comment.