From b6871833c475ec4851ffb49dbc2bafbd0b6c6cdf Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Wed, 9 Mar 2016 23:45:22 -0500 Subject: [PATCH] cmake: Generate gears.shape SVG and example code --- CMakeLists.txt | 4 +++ awesomeConfig.cmake | 6 +++++ docs/generate_examples.cmake | 47 ++++++++++++++++++++++++++++++++++++ tests/shape/test-shape.lua | 5 ---- 4 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 docs/generate_examples.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b8e0d999..85f9236df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ if(NOT EXISTS ${SOURCE_DIR}/awesomeConfig.cmake) message(FATAL_ERROR "Please provide awesomeConfig.cmake") endif() +# Define many variables + include(awesomeConfig.cmake) include_directories( @@ -252,8 +254,10 @@ endif() # {{{ Lua API Documentation if(GENERATE_DOC) + if(NOT BUILD_DIR STREQUAL SOURCE_DIR) file(MAKE_DIRECTORY ${BUILD_DIR}/lib) + file(MAKE_DIRECTORY ${BUILD_DIR}/doc) endif() file(GLOB_RECURSE AWE_LUA_FILES ${BUILD_DIR}/lib/*.lua) diff --git a/awesomeConfig.cmake b/awesomeConfig.cmake index 060785a8e..33d09ff0c 100644 --- a/awesomeConfig.cmake +++ b/awesomeConfig.cmake @@ -295,6 +295,12 @@ set(AWESOME_ICON_PATH ${AWESOME_DATA_PATH}/icons) set(AWESOME_THEMES_PATH ${AWESOME_DATA_PATH}/themes) # }}} + +if(GENERATE_DOC) + # Generate some images and examples + include(docs/generate_examples.cmake) +endif() + # {{{ Configure files file(GLOB awesome_c_configure_files RELATIVE ${SOURCE_DIR} ${SOURCE_DIR}/*.c diff --git a/docs/generate_examples.cmake b/docs/generate_examples.cmake new file mode 100644 index 000000000..61ec092c3 --- /dev/null +++ b/docs/generate_examples.cmake @@ -0,0 +1,47 @@ + +# Get and update the LUA_PATH so the scripts can be executed without Awesome +execute_process(COMMAND lua -e print\(package.path\) OUTPUT_VARIABLE LUA_PATH_) +set(ENV{LUA_PATH} "${SOURCE_DIR}/lib/?;${SOURCE_DIR}/lib/?.lua;${LUA_PATH_}") + +file(MAKE_DIRECTORY "${BUILD_DIR}/doc/images") + +# +# Shape API +# +foreach (SHAPE_NAME "circle" "arrow" "rounded_rect" "hexagon" "infobubble" + "powerline" "isosceles_triangle" "cross" "octogon" "parallelogram" + "losange" "partially_rounded_rect" "radial_progress" "rounded_bar" + "rectangle" "rectangular_tag") + set(SHAPE_FILE "${SOURCE_DIR}/tests/shape/${SHAPE_NAME}.lua") + set(SHAPE_SVG "${BUILD_DIR}/doc/images/shape_${SHAPE_NAME}.svg") + + # Generate some SVG for the documentation and load the examples for the doc + execute_process( + COMMAND lua ${SOURCE_DIR}/tests/shape/test-shape.lua ${SHAPE_FILE} ${SHAPE_SVG} + OUTPUT_VARIABLE SHAPE_OUTPUT + ERROR_VARIABLE SHAPE_ERROR + ) + + if (NOT SHAPE_ERROR STREQUAL "") + message(${SHAPE_ERROR}) + message(FATAL_ERROR ${SHAPE_NAME} " SVG generation failed, bye") + endif() + + # Set the SVG paths for the doc + set(SHAPE_${SHAPE_NAME}_SVG "../images/shape_${SHAPE_NAME}.svg") + + # Use the .lua as code example + file(READ ${SHAPE_FILE} SHAPE_EXAMPLE) + STRING(REGEX REPLACE "\n" ";" SHAPE_EXAMPLE "${SHAPE_EXAMPLE}") + SET(SHAPE_COMMENTED + "![Shape example](../images/shape_${SHAPE_NAME}.svg)\n--\n-- @usage" + ) + foreach (EXAMPLE_FILE ${SHAPE_EXAMPLE}) + if(NOT EXAMPLE_FILE MATCHES "^.+--DOC_HIDE$") + SET(SHAPE_COMMENTED ${SHAPE_COMMENTED}\n--${EXAMPLE_FILE}) + endif() + endforeach() + + set(SHAPE_${SHAPE_NAME}_EXAMPLE ${SHAPE_COMMENTED}) + +endforeach() diff --git a/tests/shape/test-shape.lua b/tests/shape/test-shape.lua index e8d4283f6..6a5484de9 100644 --- a/tests/shape/test-shape.lua +++ b/tests/shape/test-shape.lua @@ -5,11 +5,6 @@ local cairo = require( "lgi" ).cairo local shape = require( "gears.shape" ) local filepath, svgpath = ... --- This is normal when running test, it will run twice -if (not filepath) or (not svgpath) or key then - os.exit(0) -end - local function get_surface(p) local img = cairo.SvgSurface.create(p, 288, 76) return cairo.Context(img)