summaryrefslogtreecommitdiff
path: root/soong/ca_certificates.go
blob: 0cddd227ec6828ca130327cea1b18c5aa88d8734 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package ca_certificates

import (
	"path"
	"path/filepath"

	"github.com/google/blueprint/proptools"

	"android/soong/android"
	"android/soong/etc"
	"android/soong/phony"
)

func init() {
	android.RegisterModuleType("ca_certificates", caCertificatesFactory)
	android.RegisterModuleType("ca_certificates_host", caCertificatesHostFactory)
}

type caCertificatesProperties struct {
	Src_dir            *string
	Dest_dir           *string
	Module_name_prefix *string
}

func caCertificatesLoadHook(
	ctx android.LoadHookContext, factory android.ModuleFactory, c *caCertificatesProperties) {
	// Find all files in src_dir.
	srcs, err := ctx.GlobWithDeps(path.Join(ctx.ModuleDir(), *c.Src_dir, "*"), nil)
	if err != nil || len(srcs) == 0 {
		ctx.PropertyErrorf("src_dir", "cannot find files to install")
		return
	}

	// Scan through the found files to create a prebuilt_etc module for each of them.
	requiredModuleNames := make([]string, len(srcs))
	for i, src := range srcs {
		etcProps := struct {
			Name     *string
			Src      *string
			Sub_dir  *string
			Filename *string
		}{}
		filename := filepath.Base(src)
		moduleName := *c.Module_name_prefix + filename
		etcProps.Name = proptools.StringPtr(moduleName)
		etcProps.Src = proptools.StringPtr(path.Join(*c.Src_dir, filename))
		etcProps.Sub_dir = c.Dest_dir
		etcProps.Filename = proptools.StringPtr(filename)
		ctx.CreateModule(factory, &etcProps)

		// Add it to the required module list of the parent phony rule.
		requiredModuleNames[i] = moduleName
	}

	phonyProps := struct {
		Required []string
	}{}
	phonyProps.Required = requiredModuleNames
	ctx.AppendProperties(&phonyProps)
}

func caCertificatesFactory() android.Module {
	p := phony.PhonyFactory()
	c := &caCertificatesProperties{}
	android.AddLoadHook(p, func(ctx android.LoadHookContext) {
		caCertificatesLoadHook(ctx, etc.PrebuiltEtcFactory, c)
	})
	p.AddProperties(c)

	return p
}

func caCertificatesHostFactory() android.Module {
	p := phony.PhonyFactory()
	c := &caCertificatesProperties{}
	android.AddLoadHook(p, func(ctx android.LoadHookContext) {
		caCertificatesLoadHook(ctx, etc.PrebuiltEtcHostFactory, c)
	})
	p.AddProperties(c)

	return p
}