From 9e730aacd4d1ddfd5f2ef7f0977d97e7849b6649 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Tue, 6 Feb 2018 22:46:05 -0800 Subject: [PATCH] Make before_deploy.sh work on FreeBSD --- ci/before_deploy.sh | 41 +++++++++++++++++++------------- src/query.cc | 57 ++++++++++++++++++++++++--------------------- src/query.h | 10 ++++---- 3 files changed, 60 insertions(+), 48 deletions(-) diff --git a/ci/before_deploy.sh b/ci/before_deploy.sh index 2f239d88..6a6a8ad4 100755 --- a/ci/before_deploy.sh +++ b/ci/before_deploy.sh @@ -1,27 +1,36 @@ -#!/bin/bash +#!/usr/bin/env bash root=$(realpath "$(dirname "$0")/..") version=$(TZ=UTC date +v%Y%m%d) +cd "$root/build/release" -case "$TRAVIS_OS_NAME" in - osx) - SO=dylib +case $(uname -s) in + Darwin) + libclang=(lib/clang+llvm-*/lib/libclang.dylib) name=cquery-$version-x86_64-apple-darwin ;; - *) - SO=so + FreeBSD) + libclang=(lib/clang+llvm-*/lib/libclang.so.?) + name=cquery-$version-x86_64-unknown-freebsd10 ;; + Linux) + libclang=(lib/clang+llvm-*/lib/libclang.so.?) name=cquery-$version-x86_64-unknown-linux-gnu ;; + *) + echo Unsupported >&2 + exit 1 ;; esac pkg=$(mktemp -d) - -cd "$root/build/release" -rsync -rtLR bin ./lib/clang+llvm-*/lib/libclang.$SO.? ./lib/clang+llvm-*/lib/clang/*/include "$pkg/" +rsync -rtLR bin "./${libclang[0]}" ./lib/clang+llvm-*/lib/clang/*/include "$pkg/" cd "$pkg" -strip -s bin/cquery lib/clang+llvm*/lib/libclang.$SO.? -if [[ $(uname) == Linux ]]; then - # ./bin/cquery -> $name/bin/cquery - tar -Jcf "$root/build/$name.tar.xz" --owner 0 --group 0 --xform "s,^\./,$name/," . -else - tar -zcf "$root/build/$name.tar.gz" --uid 0 --gid 0 -s ",^\./,$name/," . -fi +strip -s bin/cquery "${libclang[0]}" +case $(uname -s) in + Darwin) + # FIXME + ;; + Linux) + # ./bin/cquery -> $name/bin/cquery + tar -Jcf "$root/build/$name.tar.xz" --owner 0 --group 0 --xform "s,^\./,$name/," . ;; + *) + tar -Jcf "$root/build/$name.tar.xz" --uid 0 --gid 0 -s ",^\./,$name/," . +esac rm -r "$pkg" diff --git a/src/query.cc b/src/query.cc index efb1ba05..b81ed1aa 100644 --- a/src/query.cc +++ b/src/query.cc @@ -128,8 +128,8 @@ void AddMergeableRange( // // Returns true iff |removed| or |added| are non-empty. template -bool ComputeDifferenceForUpdate(std::vector& previous, - std::vector& current, +bool ComputeDifferenceForUpdate(std::vector&& previous, + std::vector&& current, std::vector* removed, std::vector* added) { // We need to sort to use std::set_difference. @@ -140,17 +140,17 @@ bool ComputeDifferenceForUpdate(std::vector& previous, while (it0 != previous.end() && it1 != current.end()) { // Elements in |previous| that are not in |current|. if (*it0 < *it1) - removed->push_back(*it0++); + removed->push_back(std::move(*it0++)); // Elements in |current| that are not in |previous|. else if (*it1 < *it0) - added->push_back(*it1++); + added->push_back(std::move(*it1++)); else ++it0, ++it1; } while (it0 != previous.end()) - removed->push_back(*it0++); + removed->push_back(std::move(*it0++)); while (it1 != current.end()) - added->push_back(*it1++); + added->push_back(std::move(*it1++)); return !removed->empty() || !added->empty(); } @@ -464,18 +464,20 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, // |query_name| is the name of the variable on the query type. // |index_name| is the name of the variable on the index type. // |type| is the type of the variable. -#define PROCESS_UPDATE_DIFF(type_id, query_name, index_name, type) \ - { \ - /* Check for changes. */ \ - std::vector removed, added; \ - auto query_previous = previous_id_map.ToQuery(previous->index_name); \ - auto query_current = current_id_map.ToQuery(current->index_name); \ - bool did_add = ComputeDifferenceForUpdate(query_previous, query_current, \ - &removed, &added); \ - if (did_add) { \ - query_name.push_back(MergeableUpdate( \ - current_id_map.ToQuery(current->id), added, removed)); \ - } \ +#define PROCESS_UPDATE_DIFF(type_id, query_name, index_name, type) \ + { \ + /* Check for changes. */ \ + std::vector removed, added; \ + auto query_previous = previous_id_map.ToQuery(previous->index_name); \ + auto query_current = current_id_map.ToQuery(current->index_name); \ + bool did_add = ComputeDifferenceForUpdate(std::move(query_previous), \ + std::move(query_current), \ + &removed, &added); \ + if (did_add) { \ + query_name.push_back(MergeableUpdate( \ + current_id_map.ToQuery(current->id), std::move(added), \ + std::move(removed))); \ + } \ } // File files_def_update.push_back(BuildFileDefUpdate(current_id_map, current_file)); @@ -513,7 +515,7 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, ToQuery(current_id_map, type->def); if (def_update) types_def_update.push_back( - QueryType::DefUpdate(type->usr, *def_update)); + QueryType::DefUpdate(type->usr, std::move(*def_update))); if (!type->derived.empty()) types_derived.push_back( QueryType::DerivedUpdate(current_id_map.ToQuery(type->id), @@ -537,8 +539,8 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, if (current_remapped_def && previous_remapped_def != current_remapped_def && !current_remapped_def->detailed_name.empty()) { - types_def_update.push_back( - QueryType::DefUpdate(current->usr, *current_remapped_def)); + types_def_update.push_back(QueryType::DefUpdate( + current->usr, std::move(*current_remapped_def))); } PROCESS_UPDATE_DIFF(QueryTypeId, types_derived, derived, QueryTypeId); @@ -575,7 +577,7 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, ToQuery(current_id_map, func->def); if (def_update) funcs_def_update.push_back( - QueryFunc::DefUpdate(func->usr, *def_update)); + QueryFunc::DefUpdate(func->usr, std::move(*def_update))); if (!func->declarations.empty()) funcs_declarations.push_back(QueryFunc::DeclarationsUpdate( current_id_map.ToQuery(func->id), @@ -599,8 +601,8 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, if (current_remapped_def && previous_remapped_def != current_remapped_def && !current_remapped_def->detailed_name.empty()) { - funcs_def_update.push_back( - QueryFunc::DefUpdate(current->usr, *current_remapped_def)); + funcs_def_update.push_back(QueryFunc::DefUpdate( + current->usr, std::move(*current_remapped_def))); } PROCESS_UPDATE_DIFF(QueryFuncId, funcs_declarations, declarations, @@ -631,7 +633,8 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, [this, ¤t_id_map](IndexVar* var) { optional def_update = ToQuery(current_id_map, var->def); if (def_update) - vars_def_update.push_back(QueryVar::DefUpdate(var->usr, *def_update)); + vars_def_update.push_back( + QueryVar::DefUpdate(var->usr, std::move(*def_update))); if (!var->declarations.empty()) vars_declarations.push_back(QueryVar::DeclarationsUpdate( current_id_map.ToQuery(var->id), @@ -651,8 +654,8 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, if (current_remapped_def && previous_remapped_def != current_remapped_def && !current_remapped_def->detailed_name.empty()) - vars_def_update.push_back( - QueryVar::DefUpdate(current->usr, *current_remapped_def)); + vars_def_update.push_back(QueryVar::DefUpdate( + current->usr, std::move(*current_remapped_def))); PROCESS_UPDATE_DIFF(QueryVarId, vars_declarations, declarations, QueryLocation); diff --git a/src/query.h b/src/query.h index 9119a9d1..9d75f39c 100644 --- a/src/query.h +++ b/src/query.h @@ -167,12 +167,12 @@ struct MergeableUpdate { std::vector to_add; std::vector to_remove; - MergeableUpdate(TId id, const std::vector& to_add) - : id(id), to_add(to_add) {} + MergeableUpdate(TId id, std::vector&& to_add) + : id(id), to_add(std::move(to_add)) {} MergeableUpdate(TId id, - const std::vector& to_add, - const std::vector& to_remove) - : id(id), to_add(to_add), to_remove(to_remove) {} + std::vector&& to_add, + std::vector&& to_remove) + : id(id), to_add(std::move(to_add)), to_remove(std::move(to_remove)) {} }; template void Reflect(TVisitor& visitor, MergeableUpdate& value) {