blob: 8c2b2c2ac203b3d707670acf05ad07ded374eb10 [file] [log] [blame]
Dan Albert1a246272020-07-06 14:49:35 -07001// Copyright 2020 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
18 "fmt"
19
20 "android/soong/android"
21)
22
23func minApiForArch(ctx android.BaseModuleContext,
24 arch android.ArchType) android.ApiLevel {
25
26 switch arch {
27 case android.Arm, android.X86:
28 return ctx.Config().MinSupportedSdkVersion()
29 case android.Arm64, android.X86_64:
30 return android.FirstLp64Version
Colin Crossa2aaa2f2022-10-03 12:41:50 -070031 case android.Riscv64:
32 return android.FutureApiLevel
Dan Albert1a246272020-07-06 14:49:35 -070033 default:
34 panic(fmt.Errorf("Unknown arch %q", arch))
35 }
36}
37
38func nativeApiLevelFromUser(ctx android.BaseModuleContext,
39 raw string) (android.ApiLevel, error) {
40
41 min := minApiForArch(ctx, ctx.Arch().ArchType)
42 if raw == "minimum" {
43 return min, nil
44 }
45
46 value, err := android.ApiLevelFromUser(ctx, raw)
47 if err != nil {
48 return android.NoneApiLevel, err
49 }
50
51 if value.LessThan(min) {
52 return min, nil
53 }
54
55 return value, nil
56}
57
Dan Albert1a246272020-07-06 14:49:35 -070058func nativeApiLevelOrPanic(ctx android.BaseModuleContext,
59 raw string) android.ApiLevel {
60 value, err := nativeApiLevelFromUser(ctx, raw)
61 if err != nil {
62 panic(err.Error())
63 }
64 return value
65}