Skip to content

Commit

Permalink
Merge pull request #8 from arenadata/ADBDEV-2818
Browse files Browse the repository at this point in the history
ADBDEV-2818: Provide upgrade scripts for diskquota extension
  • Loading branch information
deart2k authored Aug 25, 2022
2 parents 23d9dc9 + a20709b commit 5835af2
Show file tree
Hide file tree
Showing 251 changed files with 19,590 additions and 3,712 deletions.
40 changes: 40 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
BasedOnStyle: Google

ColumnLimit: 120

# How much whitespace?
UseTab: ForIndentation
TabWidth: 4
IndentWidth: 4
ContinuationIndentWidth: 8

SpacesBeforeTrailingComments: 1

# Line things up
AccessModifierOffset: -4 # outdent `public:`, etc

DerivePointerAlignment: false
PointerAlignment: Right # char *foo, char &bar

AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true

# Braces
AlwaysBreakAfterReturnType: TopLevelDefinitions
AllowShortFunctionsOnASingleLine: Inline
BreakBeforeBraces: Custom
BraceWrapping:
AfterStruct: true
AfterClass: true
AfterEnum: true
AfterFunction: true
AfterControlStatement: true
AfterNamespace: false
AfterExternBlock: false
BeforeCatch: true
SplitEmptyFunction: false
SplitEmptyRecord: false
BeforeElse: true

SortIncludes: false
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
root = true

[*.{c,cpp,h,y}]
indent_style = tab
indent_size = 4

[{GNUmakefile,Makefile}*]
indent_style = tab
indent_size = 4

[*.mk]
indent_style = tab
indent_size = 4

[*.py]
indent_style = space
indent_size = 4

[{*.cmake,CMakeLists.txt}]
indent_style = space
indent_size = 2

22 changes: 22 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Check

on:
pull_request:
paths-ignore:
- "docs/**"
- "cmake/**"
- "test/**"
- "upgrade_test/**"
- "*.md"
- "*.sql"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: use clang-format 13
run: pip3 install clang-format==13.0.1
- name: Check clang code style
run: git ls-files *.{c,h} | xargs clang-format -i --style=file && git diff --exit-code

17 changes: 12 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
*.o
*.so
# Build directory
build*/

regression.out
regression.diffs
/results/
# The tests results
results/

# For IDE/Editors
.vscode
.idea
tags
cscope*
.ccls-cache/
compile_commands.json
22 changes: 22 additions & 0 deletions .gitmessage/commit.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Title: Summary, imperative, start upper case, don't end with a period
# No more than 50 chars. #### 50 chars is here: #

# Remember blank line between title and body.

# Body: Explain *what* and *why* (not *how*). Include task ID (tracker issue).
# Wrap at 72 chars. ################################## which is here: #

# At the end: Include Co-authored-by for all contributors.
# Include at least one empty line before it. Format:
# Co-authored-by: name <user@users.noreply.github.com>
#
# How to Write a Git Commit Message:
# https://chris.beams.io/posts/git-commit/
#
# 1.Separate subject from body with a blank line
# 2. Limit the subject line to 50 characters
# 3. Capitalize the subject line
# 4. Do not end the subject line with a period
# 5. Use the imperative mood in the subject line
# 6. Wrap the body at 72 characters
# 7. Use the body to explain what and why vs. how
173 changes: 173 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
cmake_minimum_required(VERSION 3.18)
# file(ARCHIVE_EXTRACT foo) need 3.18

project(diskquota)

if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Debug' as none was specified.")
set(CMAKE_BUILD_TYPE "Debug" CACHE
STRING "Choose the type of build." FORCE)
endif()

# generate 'compile_commands.json'
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Retrieve repository information
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Git.cmake)
GitHash_Get(DISKQUOTA_GIT_HASH)

include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Gpdb.cmake)


# set include directories for all sub-projects
include_directories(${PG_INCLUDE_DIR_SERVER})
include_directories(${PG_INCLUDE_DIR}) # for libpq
# Overwrite the default build type flags set by cmake.
# We don't want the '-O3 -DNDEBUG' from cmake. Instead, those will be set by the CFLAGS from pg_config.
# And, the good news is, GPDB release always have '-g'.
set(CMAKE_C_FLAGS_RELEASE "" CACHE
STRING "Flags for RELEASE build" FORCE)
set(CMAKE_C_FLAGS_DEBUG "-DDISKQUOTA_DEBUG"
CACHE STRING "Flags for DEBUG build" FORCE)
# set link flags for all sub-projects
set(CMAKE_MODULE_LINKER_FLAGS "${PG_LD_FLAGS}")
if (APPLE)
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -bundle_loader ${PG_BIN_DIR}/postgres")
endif()
# set c and ld flags for all projects
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PG_C_FLAGS}")

# generate version
if(NOT DEFINED DISKQUOTA_VERSION)
file(STRINGS VERSION DISKQUOTA_VERSION)
endif()

string(REGEX REPLACE "^([0-9]+).[0-9]+.[0-9]+$" "\\1" DISKQUOTA_MAJOR_VERSION
${DISKQUOTA_VERSION})
string(REGEX REPLACE "^[0-9]+.([0-9]+).[0-9]+$" "\\1" DISKQUOTA_MINOR_VERSION
${DISKQUOTA_VERSION})
string(REGEX REPLACE "^[0-9]+.[0-9]+.([0-9]+)$" "\\1" DISKQUOTA_PATCH_VERSION
${DISKQUOTA_VERSION})

if("${DISKQUOTA_MAJOR_VERSION}.${DISKQUOTA_MINOR_VERSION}" STREQUAL "1.0")
# in special, version 1.0.x do not has suffix
set(DISKQUOTA_BINARY_NAME "diskquota")
else()
set(DISKQUOTA_BINARY_NAME
"diskquota-${DISKQUOTA_MAJOR_VERSION}.${DISKQUOTA_MINOR_VERSION}")
endif()

add_compile_definitions(
DISKQUOTA_VERSION="${DISKQUOTA_VERSION}"
DISKQUOTA_MAJOR_VERSION=${DISKQUOTA_MAJOR_VERSION}
DISKQUOTA_MINOR_VERSION=${DISKQUOTA_MINOR_VERSION}
DISKQUOTA_PATCH_VERSION=${DISKQUOTA_PATCH_VERSION}
DISKQUOTA_BINARY_NAME="${DISKQUOTA_BINARY_NAME}")

list(
APPEND
diskquota_SRC
diskquota.c
diskquota_utility.c
enforcement.c
gp_activetable.c
quotamodel.c
relation_cache.c)

list(
APPEND
diskquota_DDL
diskquota.control
diskquota--1.0.sql
diskquota--1.0--2.0.sql
diskquota--1.0.3--2.0.sql
diskquota--2.0.sql
diskquota--2.0--1.0.sql)

add_library(diskquota MODULE ${diskquota_SRC})

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX
"${PG_HOME}"
CACHE PATH "default install prefix" FORCE)
endif()

set_target_properties(
diskquota
PROPERTIES OUTPUT_NAME ${DISKQUOTA_BINARY_NAME}
PREFIX ""
C_STANDARD 99
LINKER_LANGUAGE "CXX")

# packing part, move to a separate file if this part is too large
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Distro.cmake)

if(DEFINED DISKQUOTA_LAST_RELEASE_PATH)
message(STATUS "Copy pervious installer from ${DISKQUOTA_LAST_RELEASE_PATH}")
file(ARCHIVE_EXTRACT INPUT ${DISKQUOTA_LAST_RELEASE_PATH} PATTERNS "*.so")
file(GLOB DISKQUOTA_PREVIOUS_LIBRARY
"${CMAKE_BINARY_DIR}/lib/postgresql/*.so")
install(PROGRAMS ${DISKQUOTA_PREVIOUS_LIBRARY} DESTINATION "lib/postgresql/")

get_filename_component(
DISKQUOTA_LAST_RELEASE_FILENAME ${DISKQUOTA_LAST_RELEASE_PATH} NAME CACHE
"last release installer name")
string(
REGEX
REPLACE "^diskquota-([0-9]+).[0-9]+.[0-9]+-.*$" "\\1"
DISKQUOTA_LAST_MAJOR_VERSION ${DISKQUOTA_LAST_RELEASE_FILENAME})
string(
REGEX
REPLACE "^diskquota-[0-9]+.([0-9]+).[0-9]+-.*$" "\\1"
DISKQUOTA_LAST_MINOR_VERSION ${DISKQUOTA_LAST_RELEASE_FILENAME})
string(
REGEX
REPLACE "^diskquota-[0-9]+.[0-9]+.([0-9]+)-.*$" "\\1"
DISKQUOTA_LAST_PATCH_VERSION ${DISKQUOTA_LAST_RELEASE_FILENAME})

set(DISKQUOTA_LAST_VERSION
"${DISKQUOTA_LAST_MAJOR_VERSION}.${DISKQUOTA_LAST_MINOR_VERSION}.${DISKQUOTA_LAST_PATCH_VERSION}"
)
endif()

set(tgz_NAME
"diskquota-${DISKQUOTA_MAJOR_VERSION}.${DISKQUOTA_MINOR_VERSION}.${DISKQUOTA_PATCH_VERSION}-${DISTRO_NAME}_x86_64"
)
set(CPACK_GENERATOR "TGZ")
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set(CPACK_PACKAGE_FILE_NAME ${tgz_NAME})
include(CPack)
# create_artifact target is used to tar the package with version into a version-less tarball to be
# used on concourse gcs resource. It will be uploaded to a gcs version file (no diskquota version
# string in the file name), and be retrieved in the release step. Then we don't have to firgure out
# a way to add the version string back to the release file name, just untar it.
set(artifact_NAME "diskquota.tar.gz")
add_custom_target(create_artifact
COMMAND
${CMAKE_COMMAND} --build . --target package
COMMAND
${CMAKE_COMMAND} -E tar cvf ${artifact_NAME} "${tgz_NAME}.tar.gz")
# packing end

# Create build-info
# The diskquota-build-info shouldn't be copied to GPDB release by install_gpdb_component
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/BuildInfo.cmake)
set(build_info_PATH ${CMAKE_CURRENT_BINARY_DIR}/diskquota-build-info)
BuildInfo_Create(${build_info_PATH}
VARS
DISKQUOTA_GIT_HASH
DISKQUOTA_VERSION
GP_MAJOR_VERSION
GP_VERSION
CMAKE_BUILD_TYPE)
# Create build-info end

# Add installcheck targets
add_subdirectory(tests)
add_subdirectory(upgrade_test)

# NOTE: keep install part at the end of file, to overwrite previous binary
install(PROGRAMS "cmake/install_gpdb_component" DESTINATION ".")
install(FILES ${diskquota_DDL} DESTINATION "share/postgresql/extension/")
install(TARGETS diskquota DESTINATION "lib/postgresql/")
install(FILES ${build_info_PATH} DESTINATION ".")
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Copyright (c) 2004-2018 Pivotal Software, Inc.
Copyright (c) 2004-2020 Pivotal Software, Inc.
Copyright (c) 2020-Present VMware, Inc. or its affiliates

diskquota is licensed under the PostgreSQL license, the same license
as PostgreSQL. It contains parts of PostgreSQL source code. A copy of
Expand Down
30 changes: 0 additions & 30 deletions Makefile

This file was deleted.

Loading

0 comments on commit 5835af2

Please sign in to comment.