Compare commits

...
15 Commits
Author SHA1 Message Date
Michael Keck a243a1c618 CMake: Migrate VS-only and deprecated CMakeSettings to CMakePresets (#107)
CMakePresets is a CMake standard that works in many IDEs
2026-03-04 12:21:24 +01:00
Michael Keck bc02e9e72b Add CI for clang-cl (#105)
add GitHub actions to compile with LLVM on Windows (clang-cl) and provide the resulting artifact
2026-03-03 17:17:19 +01:00
Febbe 89721f2ca7 Fix clang-cl compilation (#104)
fixes #103
2026-03-03 15:22:23 +01:00
Michael Keck 2040672b69 Fix CI, include all licenses, simplify CMake (#102)
* AppVeyor: Rewrite to only use CMake commands

* Chocolatey: Update version to current release

* Readmes: Point to GitHub instead of Sourceforge

* Readme: CMake is now mandatory

Since 1176da2ada

* Expand .gitignore

* nit: line-endings

This commit is basically just a git rebase leftover. Originally updated CMake versions in the sub-projects which is already merged now.

* Readmes: VS2017 is the minimum supported version

* CPack: Actually install all license files

This change, plus the changes applied in #84 fixes #94

* CMake: $PROJECT_NAME is built-in

No need to define this manually

https://cmake.org/cmake/help/v3.10/variable/PROJECT_NAME.html

* CMake: The entire project is C only

This is an implicit performance optimization as CMake does not have to check for C++ capabilities in the setup

* CPack: Rename default dev package from master to dev-PROJECT_VERSION

* CMake: Simplify setting default CMAKE_BUILD_TYPE

* CMake: More explicit syntax to specific project language

* Readme: Simplify

* AppVeyor: Include "vs" in artifact names
2025-11-19 22:02:14 +01:00
Simon Sobisch bf7a3ad870 Merge pull request #101 from Andrej730/update-cmake
Update cmake to fix warnings
2025-11-18 21:08:26 +01:00
Andrej730 80f4917e77 cmake - set CMP0177 to OLD explicitly
Helps to avoid lots of warnings below:
```
CMake Warning (dev) at CMakeLists.txt:80 (install):
  Policy CMP0177 is not set: install() DESTINATION paths are normalized.  Run
  "cmake --help-policy CMP0177" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.
```
2025-11-18 11:36:47 +05:00
Andrej730 f4cd95d8fb cmake - bump min required version
Resolves warning:
```
CMake Deprecation Warning at common/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.
```
2025-11-18 11:32:20 +05:00
Simon Sobisch 300f48ba3e Merge pull request #91 from jonnysoe/pid_tempname
Fix runtime error upon multiple flex processes
2023-03-05 21:15:56 +01:00
jonnysoe 2bfaf44a53 Fix runtime error upon multiple flex processes 2023-03-06 03:35:20 +08:00
Alex Zhondin 9118533590 Merge pull request #85 from lexxmark/mingw64
minor adjustments for increased mingw64 compat
2022-01-20 18:51:58 -08:00
Simon Sobisch 1476a36ff5 minor adjustments for increased mingw64 compat
... but far away from complete / working
2022-01-20 18:19:56 +01:00
Simon Sobisch 517e457174 Merge pull request #83 from Croydon/ci-vs-2022
CI: Test Visual Studio 2022 64-bit builds
2022-01-20 08:33:29 +01:00
Simon Sobisch 4cdb1ea4a6 Merge pull request #84 from Croydon/licenses
CPack: Add license files to distribution
2022-01-11 20:43:06 +01:00
Croydon 2ffb97818e CPack: Add license files to distribution 2022-01-11 20:10:25 +01:00
Croydon e79176b426 CI: Test Visual Studio 2022 64-bit builds 2022-01-11 19:51:27 +01:00
23 changed files with 301 additions and 126 deletions
+11 -5
View File
@@ -1,4 +1,4 @@
image: Visual Studio 2019
image: Visual Studio 2022
configuration:
- Release
@@ -12,24 +12,30 @@ environment:
CMAKE_OPTIONS: "-A \"%platform%\" -DCMAKE_BUILD_TYPE=\"%configuration%\" -DUSE_STATIC_RUNTIME=ON"
# VS VERSION IN CMAKE STYLE
matrix:
- VSVERSION: "17 2022"
- VSVERSION: "16 2019"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
- VSVERSION: "15 2017"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
matrix:
exclude:
- VSVERSION: "17 2022"
platform: Win32
init:
- cmake --version
- msbuild /version
before_build:
- set VSVERSIONSHORT=%VSVERSION:~3,4%
- if "%APPVEYOR_REPO_TAG_NAME%"=="" ( set "APPVEYOR_REPO_TAG_NAME=dev-%VSVERSIONSHORT%-%platform%-%configuration%" )
- if "%APPVEYOR_REPO_TAG_NAME%"=="" ( set "APPVEYOR_REPO_TAG_NAME=dev-vs-%VSVERSIONSHORT%-%platform%-%configuration%" )
- mkdir build
- cd build
- cmake -G "Visual Studio %VSVERSION%" -DCPACK_PACKAGE_VERSION="%APPVEYOR_REPO_TAG_NAME%" %CMAKE_OPTIONS% ..
build:
project: "build\\winflexbison.sln"
parallel: false
build_script:
- cmake --build . --config %configuration%
after_build:
- cmake --build . --target package
+61
View File
@@ -0,0 +1,61 @@
name: Windows Build with open source compilers
on: [push, pull_request]
jobs:
Windows:
runs-on: windows-latest
strategy:
matrix:
compiler: [clang-cl]
build_type: [Release, Debug]
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: "Clang-cl: Define compiler version"
if: matrix.compiler == 'clang-cl'
run: |
$env:COMPILER_VERSION = "21"
Add-Content -Path $env:GITHUB_ENV -Value "COMPILER_VERSION=$env:COMPILER_VERSION"
- name: "Define package name"
run: |
$env:VERSION = if ($env:GITHUB_REF -and $env:GITHUB_REF -match "^refs/tags/(?<tag>.+)$") { $matches["tag"] } else { "dev" }
$env:PACKAGE_VERSION = "$env:VERSION-${{ matrix.compiler }}-$env:COMPILER_VERSION-x64-${{ matrix.build_type }}"
Add-Content -Path $env:GITHUB_ENV -Value "PACKAGE_VERSION=$env:PACKAGE_VERSION"
- name: "Clang-cl: Set up LLVM"
if: matrix.compiler == 'clang-cl'
uses: KyleMayes/install-llvm-action@98e68e10c96dffcb7bfed8b2144541a66b49aa02 # v2.0.8
with:
version: ${{ env.COMPILER_VERSION }}
- name: Install Ninja
run: choco install ninja
- name: Output environment information
run: |
cmake --version
ninja --version
${{ matrix.compiler }} --version
- name: "Configure CMake"
if: matrix.compiler == 'clang-cl'
run: |
cmake -S . -B build -G "Ninja" -DCMAKE_C_COMPILER=${{ matrix.compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCPACK_PACKAGE_VERSION="$env:PACKAGE_VERSION" -DUSE_STATIC_RUNTIME=ON
- name: Build with CMake
run: cmake --build build --config "${{ matrix.build_type }}"
- name: Create package
run: cmake --build build --target package
- name: Upload artifacts
uses: actions/upload-artifact@v7
with:
name: ${{ env.PACKAGE_VERSION }}
path: build/win_flex_bison*.zip
+26 -4
View File
@@ -1,14 +1,28 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# Winflexbison specifics
CMakeBuild*/
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# CMake folders
CMakeBuild*/
# CMake
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
@@ -25,7 +39,15 @@ bld/
[Bb]in/
[Oo]bj/
# Visual Studio 2015 cache/options directory
# Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Visual Studio cache/options directory
.vs/
*.VC.db
*.VC.opendb
@@ -216,4 +238,4 @@ GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml
.cache/
.cache/
+22 -11
View File
@@ -1,9 +1,14 @@
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project (winflexbison)
project(winflexbison VERSION 2.5.25 LANGUAGES C)
# cmake 3.31+ - enable `install` destination paths normalization.
if(POLICY CMP0177)
cmake_policy(SET CMP0177 OLD)
endif()
if(NOT MSVC)
message( FATAL_ERROR "Visual Studio Build supported only" )
message(WARNING "Only Visual Studio Build is officially supported right now")
endif()
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
@@ -20,10 +25,13 @@ add_definitions(-Drestrict=__restrict)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W3 /MD /Od /Zi /EHsc")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /W3 /GL /Od /Oi /Gy /Zi /EHsc")
# Define Release by default.
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
message(STATUS "Build type not specified: Use Release by default.")
# Define Release by default
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type")
# Only apply to MSVC frontend (not clang frontends)
if (MSVC AND NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
# Make __extension__ expand to nothing on MSVC (so GCC/Clang keep the keyword)
add_compile_definitions("__extension__=")
endif()
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
@@ -37,7 +45,6 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
# applies to WIN32/MSVC.
#------------------------------------------------------------------------
if (MSVC)
add_compile_definitions("__extension__")
add_compile_options("/source-charset:utf-8")
option( USE_STATIC_RUNTIME "Set ON to change /MD(DLL) to /MT(static)" OFF )
if (USE_STATIC_RUNTIME)
@@ -73,7 +80,11 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
install(DIRECTORY "custom_build_rules/" DESTINATION "./custom_build_rules/")
install(DIRECTORY "bison/data/" DESTINATION "./data/")
install(FILES "bison/src/COPYING" DESTINATION "./" RENAME "COPYING.bison")
install(FILES "flex/src/FlexLexer.h" DESTINATION "./")
install(FILES "flex/src/COPYING" DESTINATION "./" RENAME "COPYING.flex")
install(FILES "COPYING" DESTINATION "./")
install(FILES "COPYING.DOC" DESTINATION "./")
install(FILES "changelog.md" DESTINATION "./")
install(FILES "README.md" DESTINATION "./")
@@ -84,9 +95,9 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(ENV_VERSION "$ENV{WINFLEXBISON_VERSION}")
if(NOT ENV_VERSION)
set(CPACK_PACKAGE_VERSION "master" CACHE STRING "Complete version of the created package.")
set(CPACK_PACKAGE_VERSION "dev-${PROJECT_VERSION}" CACHE STRING "Complete version string of the created package.")
else()
set(CPACK_PACKAGE_VERSION "${ENV_VERSION}" CACHE STRING "Complete version of the created package.")
set(CPACK_PACKAGE_VERSION "${ENV_VERSION}" CACHE STRING "Complete version string of the created package.")
endif()
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
@@ -96,4 +107,4 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(CPACK_PACKAGE_FILE_NAME "win_flex_bison-${CPACK_PACKAGE_VERSION}")
include(CPack)
endif()
endif()
+69
View File
@@ -0,0 +1,69 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 23,
"patch": 0
},
"configurePresets": [
{
"name": "x64-Release",
"displayName": "x64-Release",
"generator": "Ninja",
"binaryDir": "${sourceDir}/CMakeBuild/build/${presetName}",
"installDir": "${sourceDir}/CMakeBuild/install/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
},
"environment": {
"VSCMD_ARG_TGT_ARCH": "x64",
"VSCMD_ARG_HOST_ARCH": "x64"
}
},
{
"name": "x64-RelWithDebInfo",
"displayName": "x64-RelWithDebInfo",
"generator": "Ninja",
"binaryDir": "${sourceDir}/CMakeBuild/build/${presetName}",
"installDir": "${sourceDir}/CMakeBuild/install/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
},
"environment": {
"VSCMD_ARG_TGT_ARCH": "x64",
"VSCMD_ARG_HOST_ARCH": "x64"
}
},
{
"name": "x64-Debug",
"displayName": "x64-Debug",
"generator": "Ninja",
"binaryDir": "${sourceDir}/CMakeBuild/build/${presetName}",
"installDir": "${sourceDir}/CMakeBuild/install/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
},
"environment": {
"VSCMD_ARG_TGT_ARCH": "x64",
"VSCMD_ARG_HOST_ARCH": "x64"
}
}
],
"buildPresets": [
{
"name": "x64-Release",
"configurePreset": "x64-Release",
"verbose": true
},
{
"name": "x64-RelWithDebInfo",
"configurePreset": "x64-RelWithDebInfo",
"verbose": true
},
{
"name": "x64-Debug",
"configurePreset": "x64-Debug",
"verbose": true
}
]
}
-40
View File
@@ -1,40 +0,0 @@
{
"configurations": [
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "Release",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": []
},
{
"name": "x64-RelWithDebInfo",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": []
},
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": []
}
]
}
+14 -5
View File
@@ -1,4 +1,6 @@
# WinFlexBison - Flex and Bison for Microsoft Windows
[![Build status](https://ci.appveyor.com/api/projects/status/58lcjnr0mb9uc8c8/branch/master?svg=true)](https://ci.appveyor.com/project/lexxmark/winflexbison/branch/master)
# WinFlexBison - Flex and Bison for Windows
WinFlexBison is a Windows port of [Flex (the fast lexical analyser)](https://github.com/westes/flex/) and [GNU Bison (parser generator)](https://www.gnu.org/software/bison/).
Both win_flex and win_bison are based on upstream sources but depend on system libraries only.
@@ -8,27 +10,34 @@ Both win_flex and win_bison are based on upstream sources but depend on system l
* 2.5.x versions include GNU Bison version 3.x.x
## License
Flex uses a [BSD license](flex/src/COPYING), GNU Bison is [licensed under the GNU General Public License (GPLv3+)](bison/src/COPYING).
All build scripts in WinFlexBison are distributed under GPLv3+. See [COPYING](COPYING) for details.
All documentation, especially those under custom_build_rules/doc, is distributed under the GNU Free Documentation License (FDL 1.3+).
## Build status
Bison 3.x (master) [![Build status](https://ci.appveyor.com/api/projects/status/58lcjnr0mb9uc8c8/branch/master?svg=true)](https://ci.appveyor.com/project/lexxmark/winflexbison/branch/master) and, for compatibility reasons, Bison 2.7 (bison2.7) [![Build status](https://ci.appveyor.com/api/projects/status/58lcjnr0mb9uc8c8/branch/bison2.7?svg=true)](https://ci.appveyor.com/project/lexxmark/winflexbison/branch/bison2.7)
## Downloads
https://github.com/lexxmark/winflexbison/releases provides stable versions.
To test non-released development versions see the artifacts provided by CI under "Build status".
To test non-released development versions see the artifacts provided by CI.
## Changelog
The release page includes the full Changelog but you may also see the [changelog.md](changelog.md) file.
## Build requirements
* Visual Studio 2017 or newer
* optional: CMake (when building with CMake)
* CMake
## HowTo
You may use win_flex and win_bison directly on the command line or [use them via CustomBuildRules in VisualStudio](custom_build_rules/README.md).
## Example flex/bison files
See https://github.com/meyerd/flex-bison-example
+2 -2
View File
@@ -1,4 +1,4 @@
In case compile errors like "cannot include <unistd.h>" in win_flex generated file try add --wincompat invoke option.
This new option changes <unistd.h> unix header with windows analog <io.h> and replaces isatty/fileno functions to
"safe" windows analogs _isatty/_fileno as well. If you have compile issues with it afterwards please open ticket
at http://sourceforge.net/p/winflexbison/tickets .
"safe" windows analogs _isatty/_fileno as well. If you have compile issues with it afterwards please open an issue
at https://github.com/lexxmark/winflexbison/issues .
+3 -5
View File
@@ -1,8 +1,6 @@
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
set(PROJECT_NAME win_bison)
project(${PROJECT_NAME} C)
project(win_bison LANGUAGES C)
file(GLOB SOURCE_FILES
"src/*.c"
@@ -40,4 +38,4 @@ file(GLOB liby_src
add_library(y STATIC ${liby_src})
target_include_directories(y
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src/")
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src/")
+4 -1
View File
@@ -1,3 +1,5 @@
#pragma once
#define PACKAGE_BUGREPORT "https://github.com/lexxmark/winflexbison/issues"
#define VERSION "3.8.2"
#define PACKAGE_COPYRIGHT_YEAR 2020
@@ -19,4 +21,5 @@ extern char* _stpcpy(char *yydest, const char *yysrc);
extern int strverscmp(const char* s1, const char* s2);
extern int obstack_printf(struct obstack* obs, const char* format, ...);
struct obstack;
extern int obstack_printf(struct obstack* obs, const char* format, ...);
+4 -9
View File
@@ -44,6 +44,7 @@
#include "scan-skel.h"
#include "symtab.h"
#include "tables.h"
#include "pid_tempname.h"
#include "strversion.h"
static struct obstack format_obstack;
@@ -727,7 +728,7 @@ output_skeleton (void)
{
FILE *m4_in = NULL;
FILE *m4_out = NULL;
char m4_in_file_name[/*MAX_PATH*/260];
char m4_in_file_name[/*MAX_PATH*/260];
char m4_out_file_name[/*MAX_PATH*/260];
char const *argv[11];
@@ -813,10 +814,7 @@ output_skeleton (void)
if (trace_flag & trace_muscles)
muscles_output (stderr);
{
char* p = _tempnam(NULL, "~m4_in_");
if (!p)
error (EXIT_FAILURE, get_errno (),
"_tempnam");
char* p = pid_tempname("~m4_in_");
m4_in = fopen(strcpy(m4_in_file_name, p), "wb+");
if (!m4_in)
error (EXIT_FAILURE, get_errno (),
@@ -832,10 +830,7 @@ output_skeleton (void)
/* Read and process m4's output. */
timevar_push (tv_m4);
{
char *p = _tempnam(NULL, "~m4_out_");
if (!m4_out_file_name)
error (EXIT_FAILURE, get_errno (),
"_tempnam");
char *p = pid_tempname("~m4_out_");
m4_out = fopen(strcpy(m4_out_file_name, p), "wb+");
if (!m4_out)
error (EXIT_FAILURE, get_errno (),
+2 -2
View File
@@ -1,7 +1,7 @@
# download and unpack a zip file
Install-ChocolateyZipPackage `
-PackageName "winflexbison3" `
-Url "https://github.com/lexxmark/winflexbison/releases/download/v2.5.24/win_flex_bison-2.5.24.zip" `
-Checksum "39C6086CE211D5415500ACC5ED2D8939861CA1696AEE48909C7F6DAF5122B505" `
-Url "https://github.com/lexxmark/winflexbison/releases/download/v2.5.25/win_flex_bison-2.5.25.zip" `
-Checksum "8D324B62BE33604B2C45AD1DD34AB93D722534448F55A16CA7292DE32B6AC135" `
-ChecksumType "sha256" `
-UnzipLocation "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
+1 -1
View File
@@ -3,7 +3,7 @@
<metadata>
<id>winflexbison3</id>
<title>WinFlexBison (bison 3.8.2, flex 2.6.4)</title>
<version>2.5.25.20211207</version>
<version>2.5.25.20220111</version>
<authors>Alex Zhondin (in addition to original authors of flex and bison)</authors>
<owners>lexxmark</owners>
<summary>WinFlexBison is a port Flex/Bison tools to the Windows platform</summary>
+2 -5
View File
@@ -1,8 +1,6 @@
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
set(PROJECT_NAME winflexbison_common)
project(${PROJECT_NAME} C)
project(winflexbison_common LANGUAGES C)
# Definition of Macros
add_definitions(-D_LIB)
@@ -37,4 +35,3 @@ set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 90)
target_include_directories(${PROJECT_NAME} PUBLIC "misc")
target_include_directories(${PROJECT_NAME} PUBLIC "m4")
target_include_directories(${PROJECT_NAME} PUBLIC "m4/lib")
+15 -8
View File
@@ -1,10 +1,10 @@
/* Temporary directories and temporary files with automatic cleanup.
Copyright (C) 2006, 2011-2021 Free Software Foundation, Inc.
Copyright (C) 2006, 2011-2022 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2006.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
@@ -78,6 +78,11 @@ struct temp_dir
/* More fields are present here, but not public. */
};
/* Remove all registered files and subdirectories inside DIR and DIR itself.
DIR cannot be used any more after this call.
Return 0 upon success, or -1 if there was some problem. */
extern int cleanup_temp_dir (struct temp_dir *dir);
/* Create a temporary directory.
PREFIX is used as a prefix for the name of the temporary directory. It
should be short and still give an indication about the program.
@@ -89,7 +94,8 @@ struct temp_dir
is shown and NULL is returned. */
extern struct temp_dir * create_temp_dir (const char *prefix,
const char *parentdir,
bool cleanup_verbose);
bool cleanup_verbose)
_GL_ATTRIBUTE_DEALLOC (cleanup_temp_dir, 1);
/* Register the given ABSOLUTE_FILE_NAME as being a file inside DIR, that
needs to be removed before DIR can be removed.
@@ -130,12 +136,13 @@ extern int cleanup_temp_subdir (struct temp_dir *dir,
Return 0 upon success, or -1 if there was some problem. */
extern int cleanup_temp_dir_contents (struct temp_dir *dir);
/* Remove all registered files and subdirectories inside DIR and DIR itself.
DIR cannot be used any more after this call.
Return 0 upon success, or -1 if there was some problem. */
extern int cleanup_temp_dir (struct temp_dir *dir);
// _MODE_T_ is defined by msys2 env.'s
// __mode_t_defined is defined by linux systems
// We use the MSYS2 definition of mode_t in that case.
#if !defined(_MODE_T_) && !defined(__mode_t_defined)
#define _MODE_T_
typedef int mode_t;
#endif /* _MODE_T_ */
/* ================== Opening and closing temporary files ================== */
+9 -4
View File
@@ -31,7 +31,7 @@
#define _GL_ATTRIBUTE_COLD
#define _GL_ASYNC_SAFE
#define GNULIB_XALLOC_DIE 1
#define _GL_HAVE__STATIC_ASSERT
#define _GL_HAVE__STATIC_ASSERT 1
#define _Static_assert(a, b)
#define __PGI
@@ -39,16 +39,21 @@
#define _GL_CMP(a, b) (a) == (b)
#define __getopt_argv_const
#if !defined (__MSYS__) && !defined (__MINGW32__) /* defined in sys/cdefs.h */
#define _Noreturn
#endif
#ifndef _GL_INLINE
#define _GL_INLINE inline
#endif
/* should be set by including "filename.h"
#ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
#define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1
#endif */
#if !defined (__MSYS__) && !defined (__MINGW32__) /* defined in sys/stat.h */
#define S_ISDIR(mode) (mode & _S_IFDIR)
#endif
#define S_ISDIR(mode) (mode & _S_IFDIR)
extern char* _stpcpy(char *yydest, const char *yysrc);
extern char* _stpcpy(char *yydest, const char *yysrc);
+39
View File
@@ -0,0 +1,39 @@
#include "pid_tempname.h"
#include <stdio.h>
#include <process.h>
char temp_prefix[40];
// This adds the unique process id to the built in _tempnam to prevent race condition
// This race condition is more prevalent in Ninja as it parallelizes build and instantiates multiple win_flex/win_bison
// flex_temp_out_main fails frequently as its used for a longer time (compared to temp_file_names),
// hence more possibility to overlap
const char *pid_tempname (const char *prefix)
{
// Here is the race condition:
//
// flex A
// | flex B
// ↓ |
// _tempnam returns ~file_X ↓
// | _tempnam returns ~file_X
// ↓ |
// freopen ~file_X w+ ↓
// | freopen ~file_X w+
// ↓ |
// ... ↓
// | ...
// ↓ |
// _unlink ~file_X ... <- Fails to print
// ↓
// _unlink ~file_X <- Fails to delete
//
// It is also possible that ~file_X was deleted before the lagging win_flex is done, which can cause other errors,
// hence changing to non-fatal error upon missing ~file_X on _unlink will not work all the time
// This problem can be prevented with an even more unique temporary file name by adding the current process ID
// Synchronization is not necessary either as there is no reason for the independent processes to wait...
// The reason why this is an issue is because Windows filesystem is reflected immediately,
// unlike inode in Linux that only properly deletes files when their link count is down to zero
sprintf(temp_prefix, "%s%d_", prefix, _getpid());
return _tempnam(NULL, temp_prefix);
}
+4
View File
@@ -0,0 +1,4 @@
// The longer pid_tempname was used to distinguish from GNU's tempname header
///@brief Generates a unique pid temporary file
const char *pid_tempname (const char *prefix);
+2 -2
View File
@@ -1,6 +1,6 @@
How to setup custom build rules for Visual Studio 2010 and up.
---------------
# How to setup custom build rules for Visual Studio 2017 and up
First of all you should have the necessary files.
Custom Build rules are separated into a file triplet of `.xml`, `.targets` and `.props`.
+3 -5
View File
@@ -1,8 +1,6 @@
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
set(PROJECT_NAME win_flex)
project(${PROJECT_NAME} C)
project(win_flex LANGUAGES C)
file(GLOB SOURCE_FILES
"src/*.c"
@@ -30,4 +28,4 @@ add_library(fl STATIC
"${CMAKE_CURRENT_SOURCE_DIR}/src/libyywrap.c")
target_include_directories(fl
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src/")
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src/")
+3 -4
View File
@@ -22,6 +22,7 @@
/* PURPOSE. */
#include "flexdef.h"
#include "pid_tempname.h"
static const char * check_4_gnu_m4 =
"m4_dnl ifdef(`__gnu__', ,"
"`errprint(Flex requires GNU M4. Set the PATH or set the M4 environment variable to its path name.)"
@@ -75,9 +76,7 @@ FILE* mkstempFILE (char *pref, const char *mode)
if (!pref || !*pref)
return NULL;
name = _tempnam(flex_tmp_dir, pref);
if (!name)
return NULL;
name = pid_tempname(pref);
fd = fopen(name, mode);
if (fd)
@@ -255,7 +254,7 @@ bool filter_apply_chain (struct filter * chain, FILE* in_file, FILE* out_file)
}
return result;
#if 0
#if 0
int pid, pipes[2];
-1
View File
@@ -1136,7 +1136,6 @@ extern int filter_tee_header(struct filter *chain);
extern int filter_fix_linedirs(struct filter *chain);
extern int filter_m4_p(struct filter *chain);
extern const char* flex_tmp_dir;
extern FILE* mkstempFILE(char *pref, const char *mode);
extern void unlinktemp();
+5 -12
View File
@@ -36,6 +36,7 @@
//#include "version.h"
#include "options.h"
#include "tables.h"
#include "pid_tempname.h"
#include "parse.h"
#include <io.h>
#include <fcntl.h>
@@ -411,12 +412,14 @@ void check_options (void)
*/
/* collect all output to temp file to use it as input for filter chain */
prev_stdout = _dup(1); // prev_stdout now refers to "stdout"
prev_stdout = _dup(1); // prev_stdout now refers to "stdout"
flex_temp_out_main = _strdup(pid_tempname("~flex_out_main_"));
freopen(flex_temp_out_main, "w+", stdout);
if (stdout == NULL)
lerr(_("could not create %s"), flex_temp_out_main);
yyout = stdout;
@@ -1039,8 +1042,6 @@ void flexend (int exit_status)
/* flexinit - initialize flex */
const char* flex_tmp_dir;
void flexinit (int argc, char **argv)
{
int i, sawcmpflag, rv, optind;
@@ -1048,14 +1049,6 @@ void flexinit (int argc, char **argv)
scanopt_t sopt;
char *ext_path = 0;
flex_tmp_dir = getenv ("FLEX_TMP_DIR");
{
char *p = _tempnam(flex_tmp_dir, "~flex_out_main_");
if (!p)
flexfatal(_("_tempnam(main)"));
flex_temp_out_main = _strdup(p);
}
printstats = syntaxerror = trace = spprdflt = false;
lex_compat = posix_compat = C_plus_plus = backing_up_report =
ddebug = fulltbl = false;