How to use Arch method of compiler Package

Best Syzkaller code snippet using compiler.Arch

bp2build.go

Source:bp2build.go Github

copy

Full Screen

...49 allDeps = append(allDeps, baseLinkerProps.Static_libs...)50 allDeps = append(allDeps, baseLinkerProps.Whole_static_libs...)51 }52 }53 for _, p := range module.GetArchProperties(ctx, &BaseLinkerProperties{}) {54 // arch specific linker props55 if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {56 allDeps = append(allDeps, baseLinkerProps.Header_libs...)57 allDeps = append(allDeps, baseLinkerProps.Export_header_lib_headers...)58 allDeps = append(allDeps, baseLinkerProps.Static_libs...)59 allDeps = append(allDeps, baseLinkerProps.Whole_static_libs...)60 }61 }62 // Deps in the static: { .. } and shared: { .. } props of a cc_library.63 if lib, ok := module.compiler.(*libraryDecorator); ok {64 allDeps = append(allDeps, lib.SharedProperties.Shared.Static_libs...)65 allDeps = append(allDeps, lib.SharedProperties.Shared.Whole_static_libs...)66 allDeps = append(allDeps, lib.SharedProperties.Shared.Shared_libs...)67 allDeps = append(allDeps, lib.SharedProperties.Shared.System_shared_libs...)68 allDeps = append(allDeps, lib.StaticProperties.Static.Static_libs...)69 allDeps = append(allDeps, lib.StaticProperties.Static.Whole_static_libs...)70 allDeps = append(allDeps, lib.StaticProperties.Static.Shared_libs...)71 allDeps = append(allDeps, lib.StaticProperties.Static.System_shared_libs...)72 }73 ctx.AddDependency(module, nil, android.SortedUniqueStrings(allDeps)...)74}75type sharedAttributes struct {76 copts bazel.StringListAttribute77 srcs bazel.LabelListAttribute78 staticDeps bazel.LabelListAttribute79 dynamicDeps bazel.LabelListAttribute80 wholeArchiveDeps bazel.LabelListAttribute81}82// bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library.83func bp2BuildParseSharedProps(ctx android.TopDownMutatorContext, module *Module) sharedAttributes {84 lib, ok := module.compiler.(*libraryDecorator)85 if !ok {86 return sharedAttributes{}87 }88 copts := bazel.StringListAttribute{Value: lib.SharedProperties.Shared.Cflags}89 srcs := bazel.LabelListAttribute{90 Value: android.BazelLabelForModuleSrc(ctx, lib.SharedProperties.Shared.Srcs)}91 staticDeps := bazel.LabelListAttribute{92 Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Static_libs)}93 dynamicDeps := bazel.LabelListAttribute{94 Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Shared_libs)}95 wholeArchiveDeps := bazel.LabelListAttribute{96 Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Whole_static_libs)}97 return sharedAttributes{98 copts: copts,99 srcs: srcs,100 staticDeps: staticDeps,101 dynamicDeps: dynamicDeps,102 wholeArchiveDeps: wholeArchiveDeps,103 }104}105type staticAttributes struct {106 copts bazel.StringListAttribute107 srcs bazel.LabelListAttribute108 staticDeps bazel.LabelListAttribute109 dynamicDeps bazel.LabelListAttribute110 wholeArchiveDeps bazel.LabelListAttribute111}112// bp2buildParseStaticProps returns the attributes for the static variant of a cc_library.113func bp2BuildParseStaticProps(ctx android.TopDownMutatorContext, module *Module) staticAttributes {114 lib, ok := module.compiler.(*libraryDecorator)115 if !ok {116 return staticAttributes{}117 }118 copts := bazel.StringListAttribute{Value: lib.StaticProperties.Static.Cflags}119 srcs := bazel.LabelListAttribute{120 Value: android.BazelLabelForModuleSrc(ctx, lib.StaticProperties.Static.Srcs)}121 staticDeps := bazel.LabelListAttribute{122 Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Static_libs)}123 dynamicDeps := bazel.LabelListAttribute{124 Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Shared_libs)}125 wholeArchiveDeps := bazel.LabelListAttribute{126 Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Whole_static_libs)}127 return staticAttributes{128 copts: copts,129 srcs: srcs,130 staticDeps: staticDeps,131 dynamicDeps: dynamicDeps,132 wholeArchiveDeps: wholeArchiveDeps,133 }134}135// Convenience struct to hold all attributes parsed from compiler properties.136type compilerAttributes struct {137 copts bazel.StringListAttribute138 srcs bazel.LabelListAttribute139 includes bazel.StringListAttribute140}141// bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes.142func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Module) compilerAttributes {143 var srcs bazel.LabelListAttribute144 var copts bazel.StringListAttribute145 // Creates the -I flag for a directory, while making the directory relative146 // to the exec root for Bazel to work.147 includeFlag := func(dir string) string {148 // filepath.Join canonicalizes the path, i.e. it takes care of . or .. elements.149 return "-I" + filepath.Join(ctx.ModuleDir(), dir)150 }151 // Parse the list of module-relative include directories (-I).152 parseLocalIncludeDirs := func(baseCompilerProps *BaseCompilerProperties) []string {153 // include_dirs are root-relative, not module-relative.154 includeDirs := bp2BuildMakePathsRelativeToModule(ctx, baseCompilerProps.Include_dirs)155 return append(includeDirs, baseCompilerProps.Local_include_dirs...)156 }157 // Parse the list of copts.158 parseCopts := func(baseCompilerProps *BaseCompilerProperties) []string {159 var copts []string160 for _, flag := range append(baseCompilerProps.Cflags, baseCompilerProps.Cppflags...) {161 // Soong's cflags can contain spaces, like `-include header.h`. For162 // Bazel's copts, split them up to be compatible with the163 // no_copts_tokenization feature.164 copts = append(copts, strings.Split(flag, " ")...)165 }166 for _, dir := range parseLocalIncludeDirs(baseCompilerProps) {167 copts = append(copts, includeFlag(dir))168 }169 return copts170 }171 // baseSrcs contain the list of src files that are used for every configuration.172 var baseSrcs []string173 // baseExcludeSrcs contain the list of src files that are excluded for every configuration.174 var baseExcludeSrcs []string175 // baseSrcsLabelList is a clone of the base srcs LabelList, used for computing the176 // arch or os specific srcs later.177 var baseSrcsLabelList bazel.LabelList178 // Parse srcs from an arch or OS's props value, taking the base srcs and179 // exclude srcs into account.180 parseSrcs := func(baseCompilerProps *BaseCompilerProperties) bazel.LabelList {181 // Combine the base srcs and arch-specific srcs182 allSrcs := append(baseSrcs, baseCompilerProps.Srcs...)183 // Combine the base exclude_srcs and configuration-specific exclude_srcs184 allExcludeSrcs := append(baseExcludeSrcs, baseCompilerProps.Exclude_srcs...)185 return android.BazelLabelForModuleSrcExcludes(ctx, allSrcs, allExcludeSrcs)186 }187 for _, props := range module.compiler.compilerProps() {188 if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {189 srcs.Value = parseSrcs(baseCompilerProps)190 copts.Value = parseCopts(baseCompilerProps)191 // Used for arch-specific srcs later.192 baseSrcs = baseCompilerProps.Srcs193 baseExcludeSrcs = baseCompilerProps.Exclude_srcs194 baseSrcsLabelList = parseSrcs(baseCompilerProps)195 break196 }197 }198 // Handle include_build_directory prop. If the property is true, then the199 // target has access to all headers recursively in the package, and has200 // "-I<module-dir>" in its copts.201 if c, ok := module.compiler.(*baseCompiler); ok && c.includeBuildDirectory() {202 copts.Value = append(copts.Value, includeFlag("."))203 } else if c, ok := module.compiler.(*libraryDecorator); ok && c.includeBuildDirectory() {204 copts.Value = append(copts.Value, includeFlag("."))205 }206 for arch, props := range module.GetArchProperties(ctx, &BaseCompilerProperties{}) {207 if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {208 // If there's arch specific srcs or exclude_srcs, generate a select entry for it.209 // TODO(b/186153868): do this for OS specific srcs and exclude_srcs too.210 if len(baseCompilerProps.Srcs) > 0 || len(baseCompilerProps.Exclude_srcs) > 0 {211 srcsList := parseSrcs(baseCompilerProps)212 srcs.SetValueForArch(arch.Name, srcsList)213 // The base srcs value should not contain any arch-specific excludes.214 srcs.Value = bazel.SubtractBazelLabelList(srcs.Value, bazel.LabelList{Includes: srcsList.Excludes})215 }216 copts.SetValueForArch(arch.Name, parseCopts(baseCompilerProps))217 }218 }219 // After going through all archs, delete the duplicate files in the arch220 // values that are already in the base srcs.Value.221 for arch, props := range module.GetArchProperties(ctx, &BaseCompilerProperties{}) {222 if _, ok := props.(*BaseCompilerProperties); ok {223 srcs.SetValueForArch(arch.Name, bazel.SubtractBazelLabelList(srcs.GetValueForArch(arch.Name), srcs.Value))224 }225 }226 // Now that the srcs.Value list is finalized, compare it with the original227 // list, and put the difference into the default condition for the arch228 // select.229 defaultsSrcs := bazel.SubtractBazelLabelList(baseSrcsLabelList, srcs.Value)230 // TODO(b/186153868): handle the case with multiple variant types, e.g. when arch and os are both used.231 srcs.SetValueForArch(bazel.CONDITIONS_DEFAULT, defaultsSrcs)232 // Handle OS specific props.233 for os, props := range module.GetTargetProperties(&BaseCompilerProperties{}) {234 if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {235 srcsList := parseSrcs(baseCompilerProps)236 // TODO(b/186153868): add support for os-specific srcs and exclude_srcs237 srcs.SetValueForOS(os.Name, bazel.SubtractBazelLabelList(srcsList, baseSrcsLabelList))238 copts.SetValueForOS(os.Name, parseCopts(baseCompilerProps))239 }240 }241 return compilerAttributes{242 srcs: srcs,243 copts: copts,244 }245}246// Convenience struct to hold all attributes parsed from linker properties.247type linkerAttributes struct {248 deps bazel.LabelListAttribute249 dynamicDeps bazel.LabelListAttribute250 wholeArchiveDeps bazel.LabelListAttribute251 linkopts bazel.StringListAttribute252 versionScript bazel.LabelAttribute253}254// FIXME(b/187655838): Use the existing linkerFlags() function instead of duplicating logic here255func getBp2BuildLinkerFlags(linkerProperties *BaseLinkerProperties) []string {256 flags := linkerProperties.Ldflags257 if !BoolDefault(linkerProperties.Pack_relocations, true) {258 flags = append(flags, "-Wl,--pack-dyn-relocs=none")259 }260 return flags261}262// bp2BuildParseLinkerProps parses the linker properties of a module, including263// configurable attribute values.264func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes {265 var deps bazel.LabelListAttribute266 var dynamicDeps bazel.LabelListAttribute267 var wholeArchiveDeps bazel.LabelListAttribute268 var linkopts bazel.StringListAttribute269 var versionScript bazel.LabelAttribute270 for _, linkerProps := range module.linker.linkerProps() {271 if baseLinkerProps, ok := linkerProps.(*BaseLinkerProperties); ok {272 libs := baseLinkerProps.Header_libs273 libs = append(libs, baseLinkerProps.Export_header_lib_headers...)274 libs = append(libs, baseLinkerProps.Static_libs...)275 wholeArchiveLibs := baseLinkerProps.Whole_static_libs276 libs = android.SortedUniqueStrings(libs)277 deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, libs))278 linkopts.Value = getBp2BuildLinkerFlags(baseLinkerProps)279 wholeArchiveDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs))280 if baseLinkerProps.Version_script != nil {281 versionScript.Value = android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script)282 }283 sharedLibs := baseLinkerProps.Shared_libs284 dynamicDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, sharedLibs))285 break286 }287 }288 for arch, p := range module.GetArchProperties(ctx, &BaseLinkerProperties{}) {289 if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {290 libs := baseLinkerProps.Header_libs291 libs = append(libs, baseLinkerProps.Export_header_lib_headers...)292 libs = append(libs, baseLinkerProps.Static_libs...)293 wholeArchiveLibs := baseLinkerProps.Whole_static_libs294 libs = android.SortedUniqueStrings(libs)295 deps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, libs))296 linkopts.SetValueForArch(arch.Name, getBp2BuildLinkerFlags(baseLinkerProps))297 wholeArchiveDeps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs))298 if baseLinkerProps.Version_script != nil {299 versionScript.SetValueForArch(arch.Name,300 android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script))301 }302 sharedLibs := baseLinkerProps.Shared_libs303 dynamicDeps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs))304 }305 }306 for os, p := range module.GetTargetProperties(&BaseLinkerProperties{}) {307 if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {308 libs := baseLinkerProps.Header_libs309 libs = append(libs, baseLinkerProps.Export_header_lib_headers...)310 libs = append(libs, baseLinkerProps.Static_libs...)311 wholeArchiveLibs := baseLinkerProps.Whole_static_libs312 libs = android.SortedUniqueStrings(libs)313 wholeArchiveDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs))314 deps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, libs))315 linkopts.SetValueForOS(os.Name, getBp2BuildLinkerFlags(baseLinkerProps))316 sharedLibs := baseLinkerProps.Shared_libs317 dynamicDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs))318 }319 }320 return linkerAttributes{321 deps: deps,322 dynamicDeps: dynamicDeps,323 wholeArchiveDeps: wholeArchiveDeps,324 linkopts: linkopts,325 versionScript: versionScript,326 }327}328// Relativize a list of root-relative paths with respect to the module's329// directory.330//331// include_dirs Soong prop are root-relative (b/183742505), but332// local_include_dirs, export_include_dirs and export_system_include_dirs are333// module dir relative. This function makes a list of paths entirely module dir334// relative.335//336// For the `include` attribute, Bazel wants the paths to be relative to the337// module.338func bp2BuildMakePathsRelativeToModule(ctx android.BazelConversionPathContext, paths []string) []string {339 var relativePaths []string340 for _, path := range paths {341 // Semantics of filepath.Rel: join(ModuleDir, rel(ModuleDir, path)) == path342 relativePath, err := filepath.Rel(ctx.ModuleDir(), path)343 if err != nil {344 panic(err)345 }346 relativePaths = append(relativePaths, relativePath)347 }348 return relativePaths349}350// bp2BuildParseExportedIncludes creates a string list attribute contains the351// exported included directories of a module.352func bp2BuildParseExportedIncludes(ctx android.TopDownMutatorContext, module *Module) bazel.StringListAttribute {353 libraryDecorator := module.linker.(*libraryDecorator)354 // Export_system_include_dirs and export_include_dirs are already module dir355 // relative, so they don't need to be relativized like include_dirs, which356 // are root-relative.357 includeDirs := libraryDecorator.flagExporter.Properties.Export_system_include_dirs358 includeDirs = append(includeDirs, libraryDecorator.flagExporter.Properties.Export_include_dirs...)359 includeDirsAttribute := bazel.MakeStringListAttribute(includeDirs)360 for arch, props := range module.GetArchProperties(ctx, &FlagExporterProperties{}) {361 if flagExporterProperties, ok := props.(*FlagExporterProperties); ok {362 archIncludeDirs := flagExporterProperties.Export_system_include_dirs363 archIncludeDirs = append(archIncludeDirs, flagExporterProperties.Export_include_dirs...)364 // To avoid duplicate includes when base includes + arch includes are combined365 // FIXME: This doesn't take conflicts between arch and os includes into account366 archIncludeDirs = bazel.SubtractStrings(archIncludeDirs, includeDirs)367 if len(archIncludeDirs) > 0 {368 includeDirsAttribute.SetValueForArch(arch.Name, archIncludeDirs)369 }370 }371 }372 for os, props := range module.GetTargetProperties(&FlagExporterProperties{}) {373 if flagExporterProperties, ok := props.(*FlagExporterProperties); ok {374 osIncludeDirs := flagExporterProperties.Export_system_include_dirs375 osIncludeDirs = append(osIncludeDirs, flagExporterProperties.Export_include_dirs...)376 // To avoid duplicate includes when base includes + os includes are combined377 // FIXME: This doesn't take conflicts between arch and os includes into account378 osIncludeDirs = bazel.SubtractStrings(osIncludeDirs, includeDirs)379 if len(osIncludeDirs) > 0 {380 includeDirsAttribute.SetValueForOS(os.Name, osIncludeDirs)381 }382 }...

Full Screen

Full Screen

compiler.go

Source:compiler.go Github

copy

Full Screen

...285 }286 if ctx.Target().NativeBridge == android.NativeBridgeEnabled {287 dir = filepath.Join(dir, ctx.Target().NativeBridgeRelativePath)288 }289 if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {290 dir = filepath.Join(dir, ctx.Arch().ArchType.String())291 }292 if compiler.location == InstallInData && ctx.RustModule().UseVndk() {293 dir = filepath.Join(dir, "vendor")294 }295 return android.PathForModuleInstall(ctx, dir, compiler.subDir,296 compiler.relativeInstallPath(), compiler.relative)297}298func (compiler *baseCompiler) nativeCoverage() bool {299 return false300}301func (compiler *baseCompiler) install(ctx ModuleContext) {302 path := ctx.RustModule().OutputFile()303 compiler.path = ctx.InstallFile(compiler.installDir(ctx), path.Path().Base(), path.Path())304}...

Full Screen

Full Screen

Arch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Go runs on")4 switch os := runtime.GOOS; os {5 fmt.Println("OS X.")6 fmt.Println("Linux.")7 fmt.Printf("%s.", os)8 }9}10import (11func main() {12 fmt.Print("Go runs on ")13 switch os := runtime.GOOS; os {14 fmt.Println("OS X.")15 fmt.Println("Linux.")16 fmt.Printf("%s.", os)17 }18}19import (20func main() {21 fmt.Print("Go runs on ")22 switch os := runtime.GOOS; os {23 fmt.Println("OS X.")24 fmt.Println("Linux.")25 fmt.Printf("%s.", os)26 }27}28import (29func main() {30 fmt.Print("Go runs on ")31 switch os := runtime.GOOS; os {32 fmt.Println("OS X.")33 fmt.Println("Linux.")34 fmt.Printf("%s.", os)35 }36}37import (38func main() {39 fmt.Print("Go runs on ")40 switch os := runtime.GOOS; os {41 fmt.Println("OS X.")42 fmt.Println("Linux.")43 fmt.Printf("%s.", os)44 }45}46import (47func main() {48 fmt.Print("Go runs on ")49 switch os := runtime.GOOS; os {50 fmt.Println("OS X.")

Full Screen

Full Screen

Arch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(runtime.Compiler)4 fmt.Println(runtime.GOARCH)5}6import (7func main() {8 fmt.Println(runtime.GOMAXPROCS(0))9}10import (11func main() {12 fmt.Println(runtime.NumCPU())13}14import (15func main() {16 fmt.Println(runtime.NumGoroutine())17}18import (19func main() {20 fmt.Println(runtime.Version())21}

Full Screen

Full Screen

Arch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(runtime.GOARCH)4}5import (6func main() {7 fmt.Println(runtime.GOOS)8}9import (10func main() {11 fmt.Println(runtime.NumCPU())12}13import (14func main() {15 fmt.Println(runtime.NumGoroutine())16}17import (18func main() {19 fmt.Println(runtime.NumCgoCall())20}21import (22func main() {23 fmt.Println(os.Executable())24}

Full Screen

Full Screen

Arch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("System Architecture:", compiler.Arch)4}5import (6func main() {7 fmt.Println("Go Version:", compiler.Version)8}9import (10func main() {11 fmt.Println("Compiler:", compiler.Compiler)12}13import (14func main() {15 fmt.Println("Compiler Directory:", compiler.CompilerDir)16}17import (18func main() {19 fmt.Println("Object Directory:", compiler.ObjectDir)20}21import (22func main() {23 fmt.Println("Operating System:", compiler.Goos)24}25import (26func main() {27 fmt.Println("System Architecture:", compiler.Goarch)28}29import (30func main() {31 fmt.Println("Maximum Alignment:", compiler.MaxAlign)32}33import (34func main() {35 fmt.Println("Build Tags:", compiler.BuildTags)36}37import (38func main() {39 fmt.Println("Cgo Enabled:", compiler.C

Full Screen

Full Screen

Arch

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "runtime"3func main() {4 fmt.Println(runtime.Compiler)5 fmt.Println(runtime.GOARCH)6}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful