diff options
author | Colin Cross <ccross@android.com> | 2015-01-30 17:27:36 -0800 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2015-03-13 20:28:16 -0700 |
commit | 3f40fa460d85b10646d383a3b6b01ea6d569b01b (patch) | |
tree | 542d913a3f0f818042b503948869818a77e99ebc /cc/util.go | |
parent | e441b9df9a68595d0dd7b8ed184aecb27c86054b (diff) | |
download | build_soong-3f40fa460d85b10646d383a3b6b01ea6d569b01b.tar.gz build_soong-3f40fa460d85b10646d383a3b6b01ea6d569b01b.tar.bz2 build_soong-3f40fa460d85b10646d383a3b6b01ea6d569b01b.zip |
Add soong_build primary builder
Initial build logic for building android with soong. It can build
a variety of C and C++ files for arm/arm64 and host.
Change-Id: I10eb37c2c2a50be6af1bb5fd568c0962b9476bf0
Diffstat (limited to 'cc/util.go')
-rw-r--r-- | cc/util.go | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/cc/util.go b/cc/util.go new file mode 100644 index 00000000..8703cfb2 --- /dev/null +++ b/cc/util.go @@ -0,0 +1,96 @@ +// Copyright 2015 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cc + +import ( + "fmt" + "regexp" + "strings" +) + +// Efficiently converts a list of include directories to a single string +// of cflags with -I prepended to each directory. +func includeDirsToFlags(dirs []string) string { + return joinWithPrefix(dirs, "-I") +} + +func ldDirsToFlags(dirs []string) string { + return joinWithPrefix(dirs, "-L") +} + +func libNamesToFlags(names []string) string { + return joinWithPrefix(names, "-l") +} + +func joinWithPrefix(strs []string, prefix string) string { + if len(strs) == 0 { + return "" + } + + if len(strs) == 1 { + return prefix + strs[0] + } + + n := len(" ") * (len(strs) - 1) + for _, s := range strs { + n += len(prefix) + len(s) + } + + ret := make([]byte, 0, n) + for i, s := range strs { + if i != 0 { + ret = append(ret, ' ') + } + ret = append(ret, prefix...) + ret = append(ret, s...) + } + return string(ret) +} + +func inList(s string, list []string) bool { + for _, l := range list { + if l == s { + return true + } + } + + return false +} + +var libNameRegexp = regexp.MustCompile(`^lib(.*)$`) + +func moduleToLibName(module string) (string, error) { + matches := libNameRegexp.FindStringSubmatch(module) + if matches == nil { + return "", fmt.Errorf("Library module name %s does not start with lib", module) + } + return matches[1], nil +} + +func ccFlagsToBuilderFlags(in ccFlags) builderFlags { + return builderFlags{ + globalFlags: strings.Join(in.globalFlags, " "), + asFlags: strings.Join(in.asFlags, " "), + cFlags: strings.Join(in.cFlags, " "), + conlyFlags: strings.Join(in.conlyFlags, " "), + cppFlags: strings.Join(in.cppFlags, " "), + ldFlags: strings.Join(in.ldFlags, " "), + ldLibs: strings.Join(in.ldLibs, " "), + incFlags: includeDirsToFlags(in.includeDirs), + nocrt: in.nocrt, + toolchain: in.toolchain, + clang: in.clang, + } +} |