#!/bin/bash -e # 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. # # update_modules.sh updates the repositories for external code (to the precise # revisions used for testing). # # If the single argument `--git_only` is passed, the repositories will be # updated to the pinned versions without configuring or building them. # If the argument `--build_only` is passed, the script will assume that the # repositories are at the correct version and will configure and build them. proc git_maybe_clone { var repo = $1 var dir = $2 if [[ ! -d "$dir/.git" ]] { git clone $repo $dir } } proc git_checkout_sha { var repo = $1 var sha = $2 cd $repo if [[ "$sha" != "$(git rev-parse HEAD)" ]] { git fetch origin master git checkout -f $sha } cd - >/dev/null } cd "$[dirname $0]/../.." global ROOT := $PWD bazel build //tools/modules:compiler_info eval $[ /dev/null !2 > /dev/null { global CMAKE_GEN := 'Ninja' } cmake "-G$CMAKE_GEN" \ -DCMAKE_INSTALL_PREFIX="$LLVM_REPO/build-install" \ -DCMAKE_BUILD_TYPE="Release" \ -DCMAKE_C_COMPILER="$(BAZEL_CC)" \ -DCMAKE_CXX_COMPILER="$(CXX)" \ -DCLANG_BUILD_TOOLS="OFF" \ -DCLANG_INCLUDE_DOCS="OFF" \ -DCLANG_INCLUDE_TESTS="OFF" \ -DLIBCLANG_BUILD_STATIC="ON" \ -DLLVM_BUILD_TOOLS="OFF" \ -DLLVM_BUILD_UTILS="OFF" \ -DLLVM_BUILD_RUNTIME="OFF" \ -DLLVM_DYLIB_COMPONENTS="" \ -DLLVM_ENABLE_OCAMLDOC="OFF" \ -DLLVM_INCLUDE_DOCS="OFF" \ -DLLVM_INCLUDE_EXAMPLES="OFF" \ -DLLVM_INCLUDE_GO_TESTS="OFF" \ -DLLVM_INCLUDE_TESTS="OFF" \ -DLLVM_INCLUDE_TOOLS="ON" \ -DLLVM_INCLUDE_UTILS="OFF" \ -DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD="OFF" \ -DLLVM_TARGETS_TO_BUILD="X86;PowerPC;ARM;AArch64;Mips" \ -DBUILD_SHARED_LIBS="OFF" \ -DLLVM_BUILD_LLVM_DYLIB="OFF" \ -DCMAKE_CXX_FLAGS="$(CMAKE_CXX_FLAGS)" \ .. if [[ $(uname) == 'Darwin' ]] { global cores := $[sysctl -n hw.ncpu] } else { global cores := $[nproc] } cmake --build . -- "-j$(cores)" \ clangAnalysis clangAST clangBasic clangDriver clangEdit \ clangFrontend clang-headers clangLex clangParse clangRewrite clangSema \ clangSerialization clangTooling LLVMAArch64Info LLVMARMInfo \ LLVMBitReader LLVMCore LLVMMC LLVMMCParser LLVMMipsInfo LLVMOption \ LLVMBinaryFormat \ LLVMPowerPCInfo LLVMProfileData LLVMX86Info clangFormat clangToolingCore cd .. } rm -f build if [[ $(uname) == 'Darwin' ]] { ln -sf $vbuild_dir build } else { ln -sfT $vbuild_dir build } } (CommandList children: [ (FuncDef name: git_maybe_clone body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:repo) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [76] ) ] spids: [74] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:dir) op: Equal rhs: {(DQ ($ VSub_Number "$2"))} spids: [84] ) ] spids: [82] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalNot child: (BoolUnary op_id: BoolUnary_d child: {(DQ ($ VSub_Name "$dir") (/.git))} ) ) ) terminator: ) ] action: [ (C {(git)} {(clone)} {(DQ ($ VSub_Name "$repo"))} {(DQ ($ VSub_Name "$dir"))}) ] spids: [-1 106] ) ] spids: [-1 122] ) ] spids: [71] ) spids: [67 70] ) (FuncDef name: git_checkout_sha body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:repo) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [136] ) ] spids: [134] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:sha) op: Equal rhs: {(DQ ($ VSub_Number "$2"))} spids: [144] ) ] spids: [142] ) (C {(cd)} {(DQ ($ VSub_Name "$repo"))}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {(DQ ($ VSub_Name "$sha"))} right: { (DQ (CommandSubPart command_list: (CommandList children: [(C {(git)} {(rev-parse)} {(HEAD)})] ) left_token: spids: [168 174] ) ) } ) ) terminator: ) ] action: [ (C {(git)} {(fetch)} {(origin)} {(master)}) (C {(git)} {(checkout)} {(-f)} {(DQ ($ VSub_Name "$sha"))}) ] spids: [-1 180] ) ] spids: [-1 203] ) (SimpleCommand words: [{(cd)} {(-)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[210])] ) ] spids: [131] ) spids: [127 130] ) (C {(cd)} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(dirname)} {($ VSub_Number "$0")})]) left_token: spids: [219 223] ) (/../..) ) } ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ROOT) op: Equal rhs: {(DQ ($ VSub_Name "$PWD"))} spids: [227] ) ] spids: [227] ) (C {(bazel)} {(build)} {(//tools/modules) (Lit_Other ":") (compiler_info)}) (C {(eval)} { (DQ (CommandSubPart command_list: (CommandList children: [ (SimpleCommand redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {(bazel-genfiles/tools/modules/compiler_info.txt)} spids: [245] ) ] ) ] ) left_token: spids: [244 247] ) ) } ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LLVM_REPO) op: Equal rhs: {(DQ ($ VSub_Name "$ROOT") (/third_party/llvm/llvm))} spids: [251] ) ] spids: [251] ) (C {(mkdir)} {(-p)} {(DQ ($ VSub_Name "$LLVM_REPO"))}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalAnd left: (BoolUnary op_id: BoolUnary_d child: {(DQ ($ VSub_Name "$LLVM_REPO") (/build))} ) right: (LogicalNot child: (BoolUnary op_id: BoolUnary_h child: {(DQ ($ VSub_Name "$LLVM_REPO") (/build))} ) ) ) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Your checkout has a directory at:"))}) (C {(echo)} {(DQ (" ") ($ VSub_Name "$LLVM_REPO") (/build))}) (C {(echo)} {(DQ ("update_modules expects this to be a symlink that it will overwrite."))}) (C {(echo)} {(DQ ("Please remove this directory if you want update_modules to manage LLVM."))} ) (C {(exit)} {(1)}) ] spids: [-1 291] ) ] spids: [-1 328] ) (C {(.)} {(./tools/modules/versions.sh)}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalOr left: (BoolUnary op_id:BoolUnary_z child:{(DQ ($ VSub_Number "$1"))}) right: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Number "$1"))} right: {(DQ (--git_only))} ) ) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Using repository in ") ($ VSub_Name "$LLVM_REPO"))}) (C {(git_maybe_clone)} {(https) (Lit_Other ":") (//github.com/llvm-mirror/llvm)} {(DQ ($ VSub_Name "$LLVM_REPO"))} ) (C {(git_maybe_clone)} {(https) (Lit_Other ":") (//github.com/llvm-mirror/clang)} {(DQ ($ VSub_Name "$LLVM_REPO") (/tools/clang))} ) (C {(rm)} {(-rf)} {(DQ ($ VSub_Name "$LLVM_REPO") (/tools/clang/tools/extra))}) (C {(git_checkout_sha)} {(DQ ($ VSub_Name "$LLVM_REPO"))} {(DQ ($ VSub_Name "$MIN_LLVM_SHA"))} ) (C {(git_checkout_sha)} {(DQ ($ VSub_Name "$LLVM_REPO") (/tools/clang))} {(DQ ($ VSub_Name "$MIN_CLANG_SHA"))} ) ] spids: [-1 360] ) ] spids: [-1 428] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalOr left: (BoolUnary op_id:BoolUnary_z child:{(DQ ($ VSub_Number "$1"))}) right: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Number "$1"))} right: {(DQ (--build_only))} ) ) ) terminator: ) ] action: [ (C {(cd)} {(DQ ($ VSub_Name "$LLVM_REPO"))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:vbuild_dir) op: Equal rhs: {(DQ (build.) (${ VSub_Name MIN_LLVM_SHA) (.) (${ VSub_Name MIN_CLANG_SHA))} spids: [466] ) ] spids: [466] ) (C {(find)} {(DQ (${ VSub_Name LLVM_REPO))} {(-maxdepth)} {(1)} {(-type)} {(d)} {(KW_Bang "!")} {(-name)} {(DQ (${ VSub_Name vbuild_dir))} {(-name)} {(SQ <"build.*.*">)} {(-exec)} {(rm)} {(-rf)} {(EscapedLiteralPart token:) (Lit_RBrace "}")} {(EscapedLiteralPart token:)} ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalNot child: (BoolUnary op_id: BoolUnary_d child: {(DQ ($ VSub_Name "$vbuild_dir"))} ) ) ) terminator: ) ] action: [ (C {(mkdir)} {(-p)} {(DQ ($ VSub_Name "$vbuild_dir"))}) (C {(trap)} { (DQ ("rm -rf '") ($ VSub_Name "$LLVM_REPO") (/) ($ VSub_Name "$vbuild_dir") ("'")) } {(ERR)} {(INT)} ) (C {(cd)} {(DQ ($ VSub_Name "$vbuild_dir"))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CXX) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(basename)} {(DQ (${ VSub_Name BAZEL_CC))}) (C {(sed)} {(-E)} {(SQ <"s/(cc)?(-.*)?$/++\\2/">)}) ] negated: False ) ] ) left_token: spids: [577 595] ) } spids: [576] ) ] spids: [576] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(KW_Bang "!")} {(-z)} { (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(DQ (${ VSub_Name BAZEL_CC))})] ) left_token: spids: [606 614] ) } {(Lit_Other "]")} ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CXX) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(DQ (${ VSub_Name BAZEL_CC))})] ) left_token: spids: [624 632] ) (/) (${ VSub_Name CXX) ) } spids: [622] ) ] spids: [622] ) ] spids: [-1 619] ) ] spids: [-1 640] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(KW_Bang "!")} {(-x)} {(DQ ($ VSub_Name "$CXX"))} {(Lit_Other "]")} ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CXX) op: Equal rhs: {(DQ ($ VSub_Name "$BAZEL_CC"))} spids: [661] ) ] spids: [661] ) ] spids: [-1 658] ) ] spids: [-1 670] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: { (CommandSubPart command_list: (CommandList children:[(C {(uname)})]) left_token: spids: [677 679] ) } right: {(SQ )} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CMAKE_CXX_FLAGS) op: Equal rhs: {(DQ ("-lstdc++"))} spids: [693] ) ] spids: [693] ) ] spids: [-1 690] ) ] spids: [-1 699] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CMAKE_GEN) op: Equal rhs: {(DQ ("Unix Makefiles"))} spids: [702] ) ] spids: [702] ) (If arms: [ (if_arm cond: [ (Sentence child: (SimpleCommand words: [{(which)} {(ninja)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [714] ) (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [718] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CMAKE_GEN) op: Equal rhs: {(Ninja)} spids: [726] ) ] spids: [726] ) ] spids: [-1 723] ) ] spids: [-1 730] ) (C {(cmake)} {(DQ (-G) ($ VSub_Name "$CMAKE_GEN"))} {(-DCMAKE_INSTALL_PREFIX) (Lit_Other "=") (DQ ($ VSub_Name "$LLVM_REPO") (/build-install)) } {(-DCMAKE_BUILD_TYPE) (Lit_Other "=") (DQ (Release))} {(-DCMAKE_C_COMPILER) (Lit_Other "=") (DQ (${ VSub_Name BAZEL_CC))} {(-DCMAKE_CXX_COMPILER) (Lit_Other "=") (DQ (${ VSub_Name CXX))} {(-DCLANG_BUILD_TOOLS) (Lit_Other "=") (DQ (OFF))} {(-DCLANG_INCLUDE_DOCS) (Lit_Other "=") (DQ (OFF))} {(-DCLANG_INCLUDE_TESTS) (Lit_Other "=") (DQ (OFF))} {(-DLIBCLANG_BUILD_STATIC) (Lit_Other "=") (DQ (ON))} {(-DLLVM_BUILD_TOOLS) (Lit_Other "=") (DQ (OFF))} {(-DLLVM_BUILD_UTILS) (Lit_Other "=") (DQ (OFF))} {(-DLLVM_BUILD_RUNTIME) (Lit_Other "=") (DQ (OFF))} {(-DLLVM_DYLIB_COMPONENTS) (Lit_Other "=") (DQ )} {(-DLLVM_ENABLE_OCAMLDOC) (Lit_Other "=") (DQ (OFF))} {(-DLLVM_INCLUDE_DOCS) (Lit_Other "=") (DQ (OFF))} {(-DLLVM_INCLUDE_EXAMPLES) (Lit_Other "=") (DQ (OFF))} {(-DLLVM_INCLUDE_GO_TESTS) (Lit_Other "=") (DQ (OFF))} {(-DLLVM_INCLUDE_TESTS) (Lit_Other "=") (DQ (OFF))} {(-DLLVM_INCLUDE_TOOLS) (Lit_Other "=") (DQ (ON))} {(-DLLVM_INCLUDE_UTILS) (Lit_Other "=") (DQ (OFF))} {(-DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD) (Lit_Other "=") (DQ (OFF))} {(-DLLVM_TARGETS_TO_BUILD) (Lit_Other "=") (DQ ("X86;PowerPC;ARM;AArch64;Mips"))} {(-DBUILD_SHARED_LIBS) (Lit_Other "=") (DQ (OFF))} {(-DLLVM_BUILD_LLVM_DYLIB) (Lit_Other "=") (DQ (OFF))} {(-DCMAKE_CXX_FLAGS) (Lit_Other "=") (DQ (${ VSub_Name CMAKE_CXX_FLAGS))} {(..)} ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: { (CommandSubPart command_list: (CommandList children:[(C {(uname)})]) left_token: spids: [947 949] ) } right: {(SQ )} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:cores) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [(C {(sysctl)} {(-n)} {(hw.ncpu)})] ) left_token: spids: [965 971] ) ) } spids: [963] ) ] spids: [963] ) ] spids: [-1 960] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:cores) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children:[(C {(nproc)})]) left_token: spids: [980 982] ) ) } spids: [978] ) ] spids: [978] ) ] spids: [975 986] ) (C {(cmake)} {(--build)} {(.)} {(--)} {(DQ (-j) (${ VSub_Name cores))} {(clangAnalysis)} {(clangAST)} {(clangBasic)} {(clangDriver)} {(clangEdit)} {(clangFrontend)} {(clang-headers)} {(clangLex)} {(clangParse)} {(clangRewrite)} {(clangSema)} {(clangSerialization)} {(clangTooling)} {(LLVMAArch64Info)} {(LLVMARMInfo)} {(LLVMBitReader)} {(LLVMCore)} {(LLVMMC)} {(LLVMMCParser)} {(LLVMMipsInfo)} {(LLVMOption)} {(LLVMBinaryFormat)} {(LLVMPowerPCInfo)} {(LLVMProfileData)} {(LLVMX86Info)} {(clangFormat)} {(clangToolingCore)} ) (C {(cd)} {(..)}) ] spids: [-1 542] ) ] spids: [-1 1076] ) (C {(rm)} {(-f)} {(build)}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: { (CommandSubPart command_list: (CommandList children:[(C {(uname)})]) left_token: spids: [1090 1092] ) } right: {(SQ )} ) ) terminator: ) ] action: [(C {(ln)} {(-sf)} {(DQ ($ VSub_Name "$vbuild_dir"))} {(build)})] spids: [-1 1103] ) ] else_action: [(C {(ln)} {(-sfT)} {(DQ ($ VSub_Name "$vbuild_dir"))} {(build)})] spids: [1117 1131] ) ] spids: [-1 456] ) ] spids: [-1 1133] ) ] )